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