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