Diagnostic cleanup
[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" 
18   unless -e 'perl' or -e 'perl.exe';
19
20 $ENV{EMXSHELL} = 'sh';        # For OS/2
21
22 if ($ARGV[0] eq '') {
23     @ARGV = split(/[ \n]/,
24       `echo base/*.t comp/*.t cmd/*.t io/*.t; echo op/*.t lib/*.t`);
25 }
26
27 open(CONFIG,"../config.sh");
28 while (<CONFIG>) {
29     if (/sharpbang='(.*)'/) {
30         $sharpbang = ($1 eq '#!');
31         last;
32     }
33 }
34 $sharpbang = 0 if $ENV{OS2_SHELL};              # OS/2
35 $bad = 0;
36 $good = 0;
37 $total = @ARGV;
38 while ($test = shift) {
39     if ($test =~ /^$/) {
40         next;
41     }
42     $te = $test;
43     chop($te);
44     print "$te" . '.' x (18 - length($te));
45     if ($sharpbang) {
46         open(results,"./$test |") || (print "can't run.\n");
47     } else {
48         open(script,"$test") || die "Can't run $test.\n";
49         $_ = <script>;
50         close(script);
51         if (/#!..perl(.*)/) {
52             $switch = $1;
53             if ($^O eq 'VMS') {
54                 # Must protect uppercase switches with "" on command line
55                 $switch =~ s/-([A-Z]\S*)/"-$1"/g;
56             }
57         } else {
58             $switch = '';
59         }
60         open(results,"./perl$switch $test |") || (print "can't run.\n");
61     }
62     $ok = 0;
63     $next = 0;
64     while (<results>) {
65         if ($verbose) {
66             print $_;
67         }
68         unless (/^#/) {
69             if (/^1\.\.([0-9]+)/) {
70                 $max = $1;
71                 $totmax += $max;
72                 $files += 1;
73                 $next = 1;
74                 $ok = 1;
75             } else {
76                 $next = $1, $ok = 0, last if /^not ok ([0-9]*)/;
77                 if (/^ok (.*)/ && $1 == $next) {
78                     $next = $next + 1;
79                 } else {
80                     $ok = 0;
81                 }
82             }
83         }
84     }
85     $next = $next - 1;
86     if ($ok && $next == $max) {
87         if ($max) {
88             print "ok\n";
89             $good = $good + 1;
90         } else {
91             print "skipping test on this platform\n";
92             $files -= 1;
93         }
94     } else {
95         $next += 1;
96         print "FAILED on test $next\n";
97         $bad = $bad + 1;
98         $_ = $test;
99         if (/^base/) {
100             die "Failed a basic test--cannot continue.\n";
101         }
102     }
103 }
104
105 if ($bad == 0) {
106     if ($ok) {
107         print "All tests successful.\n";
108     } else {
109         die "FAILED--no tests were run for some reason.\n";
110     }
111 } else {
112     $pct = sprintf("%.2f", $good / $total * 100);
113     if ($bad == 1) {
114         warn "Failed 1 test, $pct% okay.\n";
115     } else {
116         die "Failed $bad/$total tests, $pct% okay.\n";
117     }
118 }
119 ($user,$sys,$cuser,$csys) = times;
120 print sprintf("u=%g  s=%g  cu=%g  cs=%g  files=%d  tests=%d\n",
121     $user,$sys,$cuser,$csys,$files,$totmax);