[ PATCH 5.004_64 ] Integrated regression tests for compiler
[p5sagit/p5-mst-13.2.git] / t / TEST
1 #!./perl
2
3 # Last change: Fri Jan 10 09:57:03 WET 1997
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 && $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 == -1) {
23     @ARGV = split(/[ \n]/,
24       `echo base/*.t comp/*.t cmd/*.t io/*.t; echo op/*.t pragma/*.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 %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 ); 
42
43 _testprogs('perl', @ARGV);
44 _testprogs('compile', @ARGV) if (-e "../testcompile"); 
45
46 sub _testprogs
47 {
48         $type = shift @_;
49         @tests = @_;
50
51
52         print "
53 --------------------------------------------------------------------------------
54 TESTING COMPILER
55 --------------------------------------------------------------------------------
56 " if ($type eq 'compile');
57
58         $bad = 0;
59         $good = 0;
60         $total = @tests;
61         $files  = 0;
62         $totmax = 0;
63 while ($test = shift @tests) {
64
65     if ( $infinite{$test} && $type eq 'compile' ) {
66                 print STDERR "$test creates infinite loop! Skipping.\n"; 
67         next;
68         }
69     if ($test =~ /^$/) {
70         next;
71     }
72     $te = $test;
73     chop($te);
74     print "$te" . '.' x (18 - length($te));
75     if ($sharpbang) {
76         -x $test || (print "isn't executable.\n");
77
78         if ($type eq 'perl')
79                 { open(RESULTS, "./$test |") || (print "can't run.\n"); }
80         else
81         { 
82                 open(RESULTS, "./perl -I../lib ../utils/perlcc ./$test -run -verbose dcf -log ../compilelog |") 
83                                                                                         || (print "can't compile.\n");
84         }
85     } else {
86         open(SCRIPT,"$test") || die "Can't run $test.\n";
87         $_ = <SCRIPT>;
88         close(SCRIPT);
89         if (/#!..perl(.*)/) {
90             $switch = $1;
91             if ($^O eq 'VMS') {
92                 # Must protect uppercase switches with "" on command line
93                 $switch =~ s/-([A-Z]\S*)/"-$1"/g;
94             }
95         } else {
96             $switch = '';
97         }
98
99         if ($type eq 'perl')
100         {
101                 open(RESULTS,"./perl$switch $test |") || (print "can't run.\n");
102         }
103         else
104         {
105                 open(RESULTS, "./perl -I../lib ../utils/perlcc ./$test -run -verbose dcf -log ../compilelog |") 
106                                                                                         || (print "can't compile.\n");
107         }
108     }
109     $ok = 0;
110     $next = 0;
111     while (<RESULTS>) {
112         if ($verbose) {
113             print $_;
114         }
115         unless (/^#/) {
116             if (/^1\.\.([0-9]+)/) {
117                 $max = $1;
118                 $totmax += $max;
119                 $files += 1;
120                 $next = 1;
121                 $ok = 1;
122             } else {
123                 $next = $1, $ok = 0, last if /^not ok ([0-9]*)/;
124                 if (/^ok (\d+)(\s*#.*)?$/ && $1 == $next) {
125                     $next = $next + 1;
126                 } else {
127                     $ok = 0;
128                 }
129             }
130         }
131     }
132     $next = $next - 1;
133     if ($ok && $next == $max) {
134         if ($max) {
135             print "ok\n";
136             $good = $good + 1;
137         } else {
138             print "skipping test on this platform\n";
139             $files -= 1;
140         }
141     } else {
142         $next += 1;
143         print "FAILED at test $next\n";
144         $bad = $bad + 1;
145         $_ = $test;
146         if (/^base/) {
147             die "Failed a basic test--cannot continue.\n";
148         }
149     }
150 }
151
152 if ($bad == 0) {
153     if ($ok) {
154         print "All tests successful.\n";
155         # XXX add mention of 'perlbug -ok' ?
156     } else {
157         die "FAILED--no tests were run for some reason.\n";
158     }
159 } else {
160     $pct = sprintf("%.2f", $good / $total * 100);
161     if ($bad == 1) {
162         warn "Failed 1 test script out of $total, $pct% okay.\n";
163     } else {
164         warn "Failed $bad test scripts out of $total, $pct% okay.\n";
165     }
166        warn <<'SHRDLU';
167    ### Since not all tests were successful, you may want to run some
168    ### of them individually and examine any diagnostic messages they
169    ### produce.  See the INSTALL document's section on "make test".
170    ### If you are testing the compiler, then ignore this message 
171    ### and run 
172    ###      ./perl harness
173    ### in the directory ./t.
174 SHRDLU
175        warn <<'SHRDLU' if $good / $total > 0.8;
176    ###
177    ### Since most tests were successful, you have a good chance to
178    ### get information with better granularity by running
179    ###     ./perl harness 
180    ### in directory ./t.
181 SHRDLU
182 }
183 ($user,$sys,$cuser,$csys) = times;
184 print sprintf("u=%g  s=%g  cu=%g  cs=%g  scripts=%d  tests=%d\n",
185     $user,$sys,$cuser,$csys,$files,$totmax);
186 }
187 exit ($bad != 0);