9885b754188c618ffc84d350681d862763612cfd
[p5sagit/p5-mst-13.2.git] / t / TEST
1 #!./perl
2
3 # $Header: TEST,v 4.0 91/03/20 01:40:22 lwall Locked $
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 if ($ARGV[0] eq '') {
18     @ARGV = split(/[ \n]/,
19       `echo base/*.t comp/*.t cmd/*.t io/*.t; echo op/*.t lib/*.t`);
20 }
21
22 open(CONFIG,"../config.sh");
23 while (<CONFIG>) {
24     if (/sharpbang='(.*)'/) {
25         $sharpbang = ($1 eq '#!');
26         last;
27     }
28 }
29 $bad = 0;
30 while ($test = shift) {
31     if ($test =~ /^$/) {
32         next;
33     }
34     $te = $test;
35     chop($te);
36     print "$te" . '.' x (15 - length($te));
37     if ($sharpbang) {
38         open(results,"./$test|") || (print "can't run.\n");
39     } else {
40         open(script,"$test") || die "Can't run $test.\n";
41         $_ = <script>;
42         close(script);
43         if (/#!..perl(.*)/) {
44             $switch = $1;
45         } else {
46             $switch = '';
47         }
48         open(results,"./perl$switch $test|") || (print "can't run.\n");
49     }
50     $ok = 0;
51     $next = 0;
52     while (<results>) {
53         if ($verbose) {
54             print $_;
55         }
56         unless (/^#/) {
57             if (/^1\.\.([0-9]+)/) {
58                 $max = $1;
59                 $next = 1;
60                 $ok = 1;
61             } else {
62                 $next = $1, $ok = 0, last if /^not ok ([0-9]*)/;
63                 if (/^ok (.*)/ && $1 == $next) {
64                     $next = $next + 1;
65                 } else {
66                     $ok = 0;
67                 }
68             }
69         }
70     }
71     $next = $next - 1;
72     if ($ok && $next == $max) {
73         print "ok\n";
74     } else {
75         $next += 1;
76         print "FAILED on test $next\n";
77         $bad = $bad + 1;
78         $_ = $test;
79         if (/^base/) {
80             die "Failed a basic test--cannot continue.\n";
81         }
82     }
83 }
84
85 if ($bad == 0) {
86     if ($ok) {
87         print "All tests successful.\n";
88     } else {
89         die "FAILED--no tests were run for some reason.\n";
90     }
91 } else {
92     if ($bad == 1) {
93         die "Failed 1 test.\n";
94     } else {
95         die "Failed $bad tests.\n";
96     }
97 }
98 ($user,$sys,$cuser,$csys) = times;
99 print sprintf("u=%g  s=%g  cu=%g  cs=%g\n",$user,$sys,$cuser,$csys);