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