A forgotten deletion.
[p5sagit/p5-mst-13.2.git] / t / TEST
1 #!./perl
2
3 # This is written in a peculiar style, since we're trying to avoid
4 # most of the constructs we'll be testing for.
5
6 $| = 1;
7
8 # Cheesy version of Getopt::Std.  Maybe we should replace it with that.
9 if ($#ARGV >= 0) {
10     foreach my $idx (0..$#ARGV) {
11         next unless $ARGV[$idx] =~ /^-(\S+)$/;
12         $core    = 1 if $1 eq 'core';
13         $verbose = 1 if $1 eq 'v';
14         $with_utf= 1 if $1 eq 'utf8';
15         if ($1 =~ /^deparse(,.+)?$/) {
16             $deparse = 1;
17             $deparse_opts = $1;
18         }
19         splice(@ARGV, $idx, 1);
20     }
21 }
22
23 chdir 't' if -f 't/TEST';
24
25 die "You need to run \"make test\" first to set things up.\n"
26   unless -e 'perl' or -e 'perl.exe';
27
28 if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
29     unless (-x 'perl.third') {
30         unless (-x '../perl.third') {
31             die "You need to run \"make perl.third first.\n";
32         }
33         else {
34             print "Symlinking ../perl.third as perl.third...\n";
35             die "Failed to symlink: $!\n"
36                 unless symlink("../perl.third", "perl.third");
37             die "Symlinked but no executable perl.third: $!\n"
38                 unless -x 'perl.third';
39         }
40     }
41 }
42
43 # check leakage for embedders
44 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
45
46 $ENV{EMXSHELL} = 'sh';        # For OS/2
47
48 # Roll your own File::Find!
49 use TestInit;
50 use File::Spec;
51 my $curdir = File::Spec->curdir;
52 my $updir  = File::Spec->updir;
53
54 sub _find_tests {
55     my($dir) = @_;
56     opendir DIR, $dir || die "Trouble opening $dir: $!";
57     foreach my $f (sort { $a cmp $b } readdir DIR) {
58         next if $f eq $curdir or $f eq $updir;
59
60         my $fullpath = File::Spec->catdir($dir, $f);
61
62         _find_tests($fullpath) if -d $fullpath;
63         push @ARGV, $fullpath if $f =~ /\.t$/;
64     }
65 }
66
67 unless (@ARGV) {
68     foreach my $dir (qw(base comp cmd run io op)) {
69         _find_tests($dir);
70     }
71     _find_tests("lib") unless $core;
72     my $mani = File::Spec->catdir($updir, "MANIFEST");
73     if (open(MANI, $mani)) {
74         while (<MANI>) { # similar code in t/harness
75             if (m!^(ext/\S+/([^/]+\.t|test\.pl)|lib/\S+?(\.t|test\.pl))\s!) {
76                 $t = $1;
77                 if (!$core || $t =~ m!^lib/[a-z]!)
78                 {
79                     $path = File::Spec->catdir($updir, $t);
80                     push @ARGV, $path;
81                     $name{$path} = $t;
82                 }
83             }
84         }
85     } else {
86         warn "$0: cannot open $mani: $!\n";
87     }
88     _find_tests('pod');
89 }
90
91 # Tests known to cause infinite loops for the perlcc tests.
92 # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
93 %infinite = ();
94
95 if ($deparse) {
96     _testprogs('deparse', @ARGV);
97 } else {
98     _testprogs('perl', @ARGV);
99     _testprogs('compile', @ARGV) if (-e "../testcompile");
100 }
101
102 sub _testprogs {
103     $type = shift @_;
104     @tests = @_;
105
106     print <<'EOT' if ($type eq 'compile');
107 ------------------------------------------------------------------------------
108 TESTING COMPILER
109 ------------------------------------------------------------------------------
110 EOT
111
112     print <<'EOT' if ($type eq 'deparse');
113 ------------------------------------------------------------------------------
114 TESTING DEPARSER
115 ------------------------------------------------------------------------------
116 EOT
117
118     $ENV{PERLCC_TIMEOUT} = 120
119           if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
120
121     $bad = 0;
122     $good = 0;
123     $total = @tests;
124     $files  = 0;
125     $totmax = 0;
126
127     foreach (@tests) {
128         $name{$_} = File::Spec->catdir('t',$_) unless exists $name{$_};
129     }
130     my $maxlen = 0;
131     foreach (@name{@tests}) {
132         s/\.\w+\z/./;
133         my $len = length ;
134         $maxlen = $len if $len > $maxlen;
135     }
136     # + 3 : we want three dots between the test name and the "ok"
137     $dotdotdot = $maxlen + 3 ;
138     while ($test = shift @tests) {
139
140         if ( $infinite{$test} && $type eq 'compile' ) {
141             print STDERR "$test creates infinite loop! Skipping.\n";
142             next;
143         }
144         if ($test =~ /^$/) {
145             next;
146         }
147         if ($type eq 'deparse') {
148             if ($test eq "comp/redef.t") {
149                 # Redefinition happens at compile time
150                 next;
151             }
152             elsif ($test eq "lib/switch.t") {
153                 # B::Deparse doesn't support source filtering
154                 next;
155             }
156         }
157         $te = $name{$test};
158         print "$te" . '.' x ($dotdotdot - length($te));
159
160         $test = $OVER{$test} if exists $OVER{$test};
161
162         open(SCRIPT,"<$test") or die "Can't run $test.\n";
163         $_ = <SCRIPT>;
164         close(SCRIPT) unless ($type eq 'deparse');
165         if (/#!.*perl(.*)$/) {
166             $switch = $1;
167             if ($^O eq 'VMS') {
168                 # Must protect uppercase switches with "" on command line
169                 $switch =~ s/-([A-Z]\S*)/"-$1"/g;
170             }
171         }
172         else {
173             $switch = '';
174         }
175
176         my $file_opts = "";
177         if ($type eq 'deparse') {
178             # Look for #line directives which change the filename
179             while (<SCRIPT>) {
180                 $file_opts .= ",-f$3$4"
181                         if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
182             }
183             close(SCRIPT);
184         }
185
186         my $utf = $with_utf ? '-I../lib -Mutf8' : '';
187         my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
188         if ($type eq 'deparse') {
189             my $deparse =
190                 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,".
191                 "-l$deparse_opts$file_opts ".
192                 "$test > $test.dp ".
193                 "&& ./perl $testswitch $switch -I../lib $test.dp |";
194             open(RESULTS, $deparse)
195                 or print "can't deparse '$deparse': $!.\n";
196         }
197         elsif ($type eq 'perl') {
198             my $perl = $ENV{PERL} || './perl';
199             my $run = "$perl $testswitch $switch $utf $test |";
200             open(RESULTS,$run) or print "can't run '$run': $!.\n";
201         }
202         else {
203             my $compile =
204                 "./perl $testswitch -I../lib ../utils/perlcc -o ".
205                 "$test.plc $utf $test ".
206                 " && $test.plc |";
207             open(RESULTS, $compile)
208                 or print "can't compile '$compile': $!.\n";
209             unlink "$test.plc";
210         }
211
212         $ok = 0;
213         $next = 0;
214         while (<RESULTS>) {
215             if ($verbose) {
216                 print $_;
217             }
218             unless (/^#/) {
219                 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
220                     $max = $1;
221                     %todo = map { $_ => 1 } split / /, $3 if $3;
222                     $totmax += $max;
223                     $files += 1;
224                     $next = 1;
225                     $ok = 1;
226                 }
227                 else {
228                     if (/^(not )?ok (\d+)[^#]*(\s*#.*)?/ &&
229                         $2 == $next)
230                     {
231                         my($not, $num, $extra) = ($1, $2, $3);
232                         my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
233                         $istodo = 1 if $todo{$num};
234
235                         if( $not && !$istodo ) {
236                             $ok = 0;
237                             $next = $num;
238                             last;
239                         }
240                         else {
241                             $next = $next + 1;
242                         }
243                     }
244                     elsif (/^Bail out!\s*(.*)/i) { # magic words
245                         die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
246                     }
247                     else {
248                         $ok = 0;
249                     }
250                 }
251             }
252         }
253         close RESULTS;
254         if ($type eq 'deparse') {
255             unlink "./$test.dp";
256         }
257         if ($ENV{PERL_3LOG}) {
258             my $tpp = $test;
259             $tpp =~ s:^../::;
260             $tpp =~ s:/:_:g;
261             $tpp =~ s:\.t$::;
262             rename("perl.3log", "perl.3log.$tpp") ||
263                 die "rename: perl3.log to perl.3log.$tpp: $!\n";
264         }
265         $next = $next - 1;
266         if ($ok && $next == $max) {
267             if ($max) {
268                 print "ok\n";
269                 $good = $good + 1;
270             }
271             else {
272                 print "skipping test on this platform\n";
273                 $files -= 1;
274             }
275         }
276         else {
277             $next += 1;
278             print "FAILED at test $next\n";
279             $bad = $bad + 1;
280             $_ = $test;
281             if (/^base/) {
282                 die "Failed a basic test--cannot continue.\n";
283             }
284         }
285     }
286
287     if ($bad == 0) {
288         if ($ok) {
289             print "All tests successful.\n";
290             # XXX add mention of 'perlbug -ok' ?
291         }
292         else {
293             die "FAILED--no tests were run for some reason.\n";
294         }
295     }
296     else {
297         $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
298         if ($bad == 1) {
299             warn "Failed 1 test script out of $files, $pct% okay.\n";
300         }
301         else {
302             warn "Failed $bad test scripts out of $files, $pct% okay.\n";
303         }
304         warn <<'SHRDLU';
305    ### Since not all tests were successful, you may want to run some
306    ### of them individually and examine any diagnostic messages they
307    ### produce.  See the INSTALL document's section on "make test".
308 SHRDLU
309         warn <<'SHRDLU' if $good / $total > 0.8;
310    ### Since most tests were successful you have a good chance
311    ### to get information better granularity by running
312    ###     ./perl harness
313    ### in the 't' directory.
314 SHRDLU
315         use Config;
316         if ($Config{ldlibpthname}) {
317             warn <<SHRDLU;
318    ### Since you seem to have a dynamic library search path,
319    ### $Config{ldlibpthname}, you probably should set that
320    ### to point to the build directory before running the harness.
321    ### Depending on your shell style:
322    ###     setenv $Config{ldlibpthname} `pwd`; cd t; ./perl harness
323    ###     $Config{ldlibpthname}=`pwd`; export $Config{ldlibpthname}; cd t; ./perl harness
324    ###     export $Config{ldlibpthname}=`pwd`; cd t; ./perl harness
325    ### for csh-style shells, like tcsh; or for traditional/modern
326    ### Bourne-style shells, like bash, ksh, and zsh, respectively.
327 SHRDLU
328         }
329     }
330     ($user,$sys,$cuser,$csys) = times;
331     print sprintf("u=%g  s=%g  cu=%g  cs=%g  scripts=%d  tests=%d\n",
332         $user,$sys,$cuser,$csys,$files,$totmax);
333 }
334 exit ($bad != 0);