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