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