perl 5.000
[p5sagit/p5-mst-13.2.git] / t / TEST
CommitLineData
8d063cd8 1#!./perl
2
79072805 3# $RCSfile: TEST,v $$Revision: 4.1 $$Date: 92/08/07 18:27:00 $
8d063cd8 4
5# This is written in a peculiar style, since we're trying to avoid
6# most of the constructs we'll be testing for.
7
a687059c 8$| = 1;
9
8d063cd8 10if ($ARGV[0] eq '-v') {
11 $verbose = 1;
12 shift;
13}
14
378cc40b 15chdir 't' if -f 't/TEST';
16
8d063cd8 17if ($ARGV[0] eq '') {
fe14fcc3 18 @ARGV = split(/[ \n]/,
19 `echo base/*.t comp/*.t cmd/*.t io/*.t; echo op/*.t lib/*.t`);
8d063cd8 20}
21
5303340c 22open(CONFIG,"../config.sh");
23while (<CONFIG>) {
135863df 24 if (/sharpbang='(.*)'/) {
25 $sharpbang = ($1 eq '#!');
26 last;
27 }
28}
8d063cd8 29$bad = 0;
79072805 30$good = 0;
31$total = @ARGV;
8d063cd8 32while ($test = shift) {
fe14fcc3 33 if ($test =~ /^$/) {
378cc40b 34 next;
35 }
fe14fcc3 36 $te = $test;
37 chop($te);
38 print "$te" . '.' x (15 - length($te));
135863df 39 if ($sharpbang) {
a0d0e21e 40 open(results,"./$test |") || (print "can't run.\n");
135863df 41 } else {
378cc40b 42 open(script,"$test") || die "Can't run $test.\n";
135863df 43 $_ = <script>;
44 close(script);
45 if (/#!..perl(.*)/) {
46 $switch = $1;
47 } else {
48 $switch = '';
49 }
a0d0e21e 50 open(results,"./perl$switch $test |") || (print "can't run.\n");
135863df 51 }
8d063cd8 52 $ok = 0;
378cc40b 53 $next = 0;
8d063cd8 54 while (<results>) {
55 if ($verbose) {
56 print $_;
57 }
58 unless (/^#/) {
59 if (/^1\.\.([0-9]+)/) {
60 $max = $1;
2b317908 61 $totmax += $max;
62 $files += 1;
8d063cd8 63 $next = 1;
64 $ok = 1;
65 } else {
7e1cf235 66 $next = $1, $ok = 0, last if /^not ok ([0-9]*)/;
8d063cd8 67 if (/^ok (.*)/ && $1 == $next) {
68 $next = $next + 1;
69 } else {
70 $ok = 0;
71 }
72 }
73 }
74 }
75 $next = $next - 1;
76 if ($ok && $next == $max) {
77 print "ok\n";
79072805 78 $good = $good + 1;
8d063cd8 79 } else {
80 $next += 1;
81 print "FAILED on test $next\n";
82 $bad = $bad + 1;
83 $_ = $test;
84 if (/^base/) {
378cc40b 85 die "Failed a basic test--cannot continue.\n";
8d063cd8 86 }
87 }
88}
89
90if ($bad == 0) {
91 if ($ok) {
92 print "All tests successful.\n";
93 } else {
378cc40b 94 die "FAILED--no tests were run for some reason.\n";
8d063cd8 95 }
96} else {
79072805 97 $pct = sprintf("%.2f", $good / $total * 100);
8d063cd8 98 if ($bad == 1) {
79072805 99 warn "Failed 1 test, $pct% okay.\n";
8d063cd8 100 } else {
79072805 101 die "Failed $bad/$total tests, $pct% okay.\n";
8d063cd8 102 }
103}
104($user,$sys,$cuser,$csys) = times;
2b317908 105print sprintf("u=%g s=%g cu=%g cs=%g files=%d tests=%d\n",
106 $user,$sys,$cuser,$csys,$files,$totmax);