3 # This is written in a peculiar style, since we're trying to avoid
4 # most of the constructs we'll be testing for.
8 # Let tests know they're running in the perl core. Useful for modules
9 # which live dual lives on CPAN.
12 # remove empty elements due to insertion of empty symbols via "''p1'" syntax
13 @ARGV = grep($_,@ARGV) if $^O eq 'VMS';
15 # Cheesy version of Getopt::Std. Maybe we should replace it with that.
18 foreach my $idx (0..$#ARGV) {
19 push( @argv, $ARGV[$idx] ), next unless $ARGV[$idx] =~ /^-(\S+)$/;
20 $core = 1 if $1 eq 'core';
21 $verbose = 1 if $1 eq 'v';
22 $torture = 1 if $1 eq 'torture';
23 $with_utf= 1 if $1 eq 'utf8';
24 $bytecompile = 1 if $1 eq 'bytecompile';
25 $compile = 1 if $1 eq 'compile';
26 $taintwarn = 1 if $1 eq 'taintwarn';
27 if ($1 =~ /^deparse(,.+)?$/) {
35 chdir 't' if -f 't/TEST';
37 die "You need to run \"make test\" first to set things up.\n"
38 unless -e 'perl' or -e 'perl.exe' or -e 'perl.pm';
40 if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
41 unless (-x 'perl.third') {
42 unless (-x '../perl.third') {
43 die "You need to run \"make perl.third first.\n";
46 print "Symlinking ../perl.third as perl.third...\n";
47 die "Failed to symlink: $!\n"
48 unless symlink("../perl.third", "perl.third");
49 die "Symlinked but no executable perl.third: $!\n"
50 unless -x 'perl.third';
55 # check leakage for embedders
56 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
58 $ENV{EMXSHELL} = 'sh'; # For OS/2
60 # Roll your own File::Find!
63 my $curdir = File::Spec->curdir;
64 my $updir = File::Spec->updir;
68 opendir DIR, $dir or die "Trouble opening $dir: $!";
69 foreach my $f (sort { $a cmp $b } readdir DIR) {
70 next if $f eq $curdir or $f eq $updir;
72 my $fullpath = File::Spec->catfile($dir, $f);
74 _find_tests($fullpath) if -d $fullpath;
75 $fullpath = VMS::Filespec::unixify($fullpath) if $^O eq 'VMS';
76 push @ARGV, $fullpath if $f =~ /\.t$/;
84 foreach (split(/\s+/,$args)) {
85 # In VMS protect with doublequotes because otherwise
86 # DCL will lowercase -- unless already doublequoted.
87 $_ = q(").$_.q(") if ($^O eq 'VMS') && !/^\"/ && length($_) > 0;
88 $argstring .= ' ' . $_;
94 foreach my $dir (qw(base comp cmd run io op uni)) {
97 _find_tests("lib") unless $core;
98 my $mani = File::Spec->catfile($updir, "MANIFEST");
99 if (open(MANI, $mani)) {
100 while (<MANI>) { # similar code in t/harness
101 if (m!^(ext/\S+/?(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
103 if (!$core || $t =~ m!^lib/[a-z]!)
105 $path = File::Spec->catfile($updir, $t);
113 warn "$0: cannot open $mani: $!\n";
118 _find_tests('japh') if $torture;
122 # Tests known to cause infinite loops for the perlcc tests.
123 # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
127 _testprogs('deparse', '', @ARGV);
130 _testprogs('compile', '', @ARGV);
132 elsif( $bytecompile ) {
133 _testprogs('bytecompile', '', @ARGV);
136 _testprogs('compile', '', @ARGV) if -e "../testcompile";
137 _testprogs('perl', '', @ARGV);
145 print <<'EOT' if ($type eq 'compile');
146 ------------------------------------------------------------------------------
148 ------------------------------------------------------------------------------
151 print <<'EOT' if ($type eq 'deparse');
152 ------------------------------------------------------------------------------
154 ------------------------------------------------------------------------------
157 print <<EOT if ($type eq 'bytecompile');
158 ------------------------------------------------------------------------------
159 TESTING BYTECODE COMPILER
160 ------------------------------------------------------------------------------
163 $ENV{PERLCC_TIMEOUT} = 120
164 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
172 foreach my $t (@tests) {
173 unless (exists $name{$t}) {
174 my $tname = File::Spec->catfile('t',$t);
175 $tname = VMS::Filespec::unixify($tname) if $^O eq 'VMS';
180 foreach (@name{@tests}) {
183 $maxlen = $len if $len > $maxlen;
185 # + 3 : we want three dots between the test name and the "ok"
186 $dotdotdot = $maxlen + 3 ;
188 my $valgrind_log = 'current.valgrind';
189 while ($test = shift @tests) {
191 if ( $infinite{$test} && $type eq 'compile' ) {
192 print STDERR "$test creates infinite loop! Skipping.\n";
198 if ($type eq 'deparse') {
199 if ($test eq "comp/redef.t") {
200 # Redefinition happens at compile time
203 elsif ($test =~ m{lib/Switch/t/}) {
204 # B::Deparse doesn't support source filtering
208 $te = $name{$test} . '.' x ($dotdotdot - length($name{$test}));
210 if ($^O ne 'VMS') { # defer printing on VMS due to piping bug
215 $test = $OVER{$test} if exists $OVER{$test};
217 open(SCRIPT,"<$test") or die "Can't run $test.\n";
219 close(SCRIPT) unless ($type eq 'deparse');
220 if (/#!.*\bperl.*\s-\w*([tT])/) {
225 # not all tests are expected to pass with this option
233 my $test_executable; # for 'compile' tests
235 if ($type eq 'deparse') {
236 # Look for #line directives which change the filename
238 $file_opts .= ",-f$3$4"
239 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
244 my $utf = $with_utf ? '-I../lib -Mutf8' : '';
245 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
246 if ($type eq 'deparse') {
248 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,-sv1.,".
249 "-l$deparse_opts$file_opts ".
251 "&& ./perl $testswitch $switch -I../lib $test.dp |";
252 open(RESULTS, $deparse)
253 or print "can't deparse '$deparse': $!.\n";
255 elsif ($type eq 'bytecompile') {
257 if( $^O eq 'MSWin32') {
265 my $perl = $ENV{PERL} || "$pwd/perl";
266 my $bswitch = "-MO=Bytecode,-H,-TI,-s$pwd/$test,";
267 $bswitch .= "-TF$test.plc,"
268 if $test =~ m(chdir|pod/|CGI/t/carp|lib/DB);
270 if $test =~ m(deparse|terse|ext/Storable/t/code);
272 if $test =~ m(op/getpid);
274 "$perl $testswitch $switch -I../lib $bswitch".
275 "-o$test.plc $test 2>$null &&".
276 "$perl $testswitch $switch -I../lib $utf $test.plc |";
277 open(RESULTS,$bytecompile)
278 or print "can't byte-compile '$bytecompile': $!.\n";
280 elsif ($type eq 'perl') {
281 my $perl = $ENV{PERL} || './perl';
282 my $redir = $^O eq 'VMS' ? '2>&1' : '';
283 if ($ENV{PERL_VALGRIND}) {
284 $perl = "valgrind --suppressions=perl.supp --leak-check=yes "
285 . "--leak-resolution=high --show-reachable=yes "
286 . "--num-callers=50 --logfile-fd=3 $perl";
287 $redir = "3>$valgrind_log";
289 my $run = "$perl" . _quote_args("$testswitch $switch $utf") . " $test $redir|";
290 open(RESULTS,$run) or print "can't run '$run': $!.\n";
294 my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
295 # -O9 for good measure, -fcog is broken ATM
296 "$switch -Wb=-O9,-fno-cog -L .. " .
297 "-I \".. ../lib/CORE\" $args $utf $test -o ";
299 if( $^O eq 'MSWin32' ) {
300 $test_executable = "$test.exe";
301 # hopefully unused name...
302 open HACK, "> xweghyz.pl";
306 open HACK, '.\\perl $pl2c $test_executable |';
307 # cl.exe prints the name of the .c file on stdout (\%^\$^#)
308 while(<HACK>) {m/^\\w+\\.[cC]\$/ && next;print}
309 open HACK, '$test_executable |';
310 while(<HACK>) {print}
313 $compile = 'xweghyz.pl |';
316 $test_executable = "$test.plc";
317 $compile = "./perl $pl2c $test_executable && $test_executable |";
319 unlink $test_executable if -f $test_executable;
320 open(RESULTS, $compile)
321 or print "can't compile '$compile': $!.\n";
329 next if /^\s*$/; # skip blank lines
334 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
336 %todo = map { $_ => 1 } split / /, $3 if $3;
346 if (/^(not )?ok (\d+)[^\#]*(\s*\#.*)?/) {
347 unless ($seen_leader) {
355 my($not, $num, $extra) = ($1, $2, $3);
356 my($istodo) = $extra =~ /#\s*TODO/ if $extra;
357 $istodo = 1 if $todo{$num};
359 if( $not && !$istodo ) {
369 elsif (/^Bail out!\s*(.*)/i) { # magic words
370 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
379 if ($ENV{PERL_VALGRIND}) {
381 if (-e $valgrind_log) {
382 if (open(V, $valgrind_log)) {
386 warn "$0: Failed to open '$valgrind_log': $!\n";
392 for my $i (0..$#valgrind) {
393 local $_ = $valgrind[$i];
394 if (/^==\d+== ERROR SUMMARY: (\d+) errors? /) {
395 $errors += $1; # there may be multiple error summaries
396 } elsif (/^==\d+== LEAK SUMMARY:/) {
397 for my $off (1 .. 4) {
398 if ($valgrind[$i+$off] =~
399 /(?:lost|reachable):\s+\d+ bytes in (\d+) blocks/) {
405 if ($errors or $leaks) {
406 if (rename $valgrind_log, "$test.valgrind") {
409 warn "$0: Failed to create '$test.valgrind': $!\n";
413 warn "No valgrind output?\n";
415 if (-e $valgrind_log) {
417 or warn "$0: Failed to unlink '$valgrind_log': $!\n";
420 if ($type eq 'deparse') {
423 if ($ENV{PERL_3LOG}) {
427 $tpp =~ s:\.t$:.3log:;
428 rename("perl.3log", $tpp) ||
429 die "rename: perl3.log to $tpp: $!\n";
432 # test if the compiler compiled something
433 if( $type eq 'compile' && !-e "$test_executable" ) {
435 print "Test did not compile\n";
437 if ($ok && $next == $max ) {
443 print "${te}skipping test on this platform\n";
449 print "${te}FAILED at test $next\n";
453 die "Failed a basic test--cannot continue.\n";
460 print "All tests successful.\n";
461 # XXX add mention of 'perlbug -ok' ?
464 die "FAILED--no tests were run for some reason.\n";
468 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
470 warn "Failed 1 test script out of $files, $pct% okay.\n";
473 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
476 ### Since not all tests were successful, you may want to run some of
477 ### them individually and examine any diagnostic messages they produce.
478 ### See the INSTALL document's section on "make test".
480 warn <<'SHRDLU_2' if $good / $total > 0.8;
481 ### You have a good chance to get more information by running
483 ### in the 't' directory since most (>=80%) of the tests succeeded.
485 if (eval {require Config; import Config; 1}) {
486 if ($Config{usedl} && (my $p = $Config{ldlibpthname})) {
488 ### You may have to set your dynamic library search path,
489 ### $p, to point to the build directory:
491 if (exists $ENV{$p} && $ENV{$p} ne '') {
493 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
494 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
495 ### export $p=`pwd`:\$$p; cd t; ./perl harness
499 ### setenv $p `pwd`; cd t; ./perl harness
500 ### $p=`pwd`; export $p; cd t; ./perl harness
501 ### export $p=`pwd`; cd t; ./perl harness
505 ### for csh-style shells, like tcsh; or for traditional/modern
506 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
511 ($user,$sys,$cuser,$csys) = times;
512 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
513 $user,$sys,$cuser,$csys,$files,$totmax);
514 if ($ENV{PERL_VALGRIND}) {
515 my $s = $valgrind == 1 ? '' : 's';
516 print "$valgrind valgrind report$s created.\n", ;