This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
SYN SYN
[perl5.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                     elsif (/^Bail out!\s*(.*)/i) { # magic words
132                         die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
133                     }
134                     else {
135                         $ok = 0;
136                     }
137                 }
138             }
139         }
140         close RESULTS;
141         $next = $next - 1;
142         if ($ok && $next == $max) {
143             if ($max) {
144                 print "ok\n";
145                 $good = $good + 1;
146             }
147             else {
148                 print "skipping test on this platform\n";
149                 $files -= 1;
150             }
151         }
152         else {
153             $next += 1;
154             print "FAILED at test $next\n";
155             $bad = $bad + 1;
156             $_ = $test;
157             if (/^base/) {
158                 die "Failed a basic test--cannot continue.\n";
159             }
160         }
161     }
162
163     if ($bad == 0) {
164         if ($ok) {
165             print "All tests successful.\n";
166             # XXX add mention of 'perlbug -ok' ?
167         }
168         else {
169             die "FAILED--no tests were run for some reason.\n";
170         }
171     }
172     else {
173         $pct = sprintf("%.2f", $good / $total * 100);
174         if ($bad == 1) {
175             warn "Failed 1 test script out of $total, $pct% okay.\n";
176         }
177         else {
178             warn "Failed $bad test scripts out of $total, $pct% okay.\n";
179         }
180         warn <<'SHRDLU';
181    ### Since not all tests were successful, you may want to run some
182    ### of them individually and examine any diagnostic messages they
183    ### produce.  See the INSTALL document's section on "make test".
184    ### If you are testing the compiler, then ignore this message 
185    ### and run 
186    ###      ./perl harness
187    ### in the directory ./t.
188 SHRDLU
189         warn <<'SHRDLU' if $good / $total > 0.8;
190    ###
191    ### Since most tests were successful, you have a good chance to
192    ### get information with better granularity by running
193    ###     ./perl harness 
194    ### in directory ./t.
195 SHRDLU
196     }
197     ($user,$sys,$cuser,$csys) = times;
198     print sprintf("u=%g  s=%g  cu=%g  cs=%g  scripts=%d  tests=%d\n",
199         $user,$sys,$cuser,$csys,$files,$totmax);
200 }
201 exit ($bad != 0);