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 $ENV{PERL_CORE_MINITEST} = 1 if $1 eq 'minitest';
28 if ($1 =~ /^deparse(,.+)?$/) {
36 chdir 't' if -f 't/TEST';
38 die "You need to run \"make test\" first to set things up.\n"
39 unless -e 'perl' or -e 'perl.exe' or -e 'perl.pm';
41 if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
42 unless (-x 'perl.third') {
43 unless (-x '../perl.third') {
44 die "You need to run \"make perl.third first.\n";
47 print "Symlinking ../perl.third as perl.third...\n";
48 die "Failed to symlink: $!\n"
49 unless symlink("../perl.third", "perl.third");
50 die "Symlinked but no executable perl.third: $!\n"
51 unless -x 'perl.third';
56 # check leakage for embedders
57 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
59 $ENV{EMXSHELL} = 'sh'; # For OS/2
61 # Roll your own File::Find!
64 my $curdir = File::Spec->curdir;
65 my $updir = File::Spec->updir;
69 opendir DIR, $dir or die "Trouble opening $dir: $!";
70 foreach my $f (sort { $a cmp $b } readdir DIR) {
71 next if $f eq $curdir or $f eq $updir or
72 $f =~ /^(?:CVS|RCS|SCCS|\.svn)$/;
74 my $fullpath = File::Spec->catfile($dir, $f);
76 _find_tests($fullpath) if -d $fullpath;
77 $fullpath = VMS::Filespec::unixify($fullpath) if $^O eq 'VMS';
78 push @ARGV, $fullpath if $f =~ /\.t$/;
86 foreach (split(/\s+/,$args)) {
87 # In VMS protect with doublequotes because otherwise
88 # DCL will lowercase -- unless already doublequoted.
89 $_ = q(").$_.q(") if ($^O eq 'VMS') && !/^\"/ && length($_) > 0;
90 $argstring .= ' ' . $_;
96 foreach my $dir (qw(base comp cmd run io op uni)) {
99 _find_tests("lib") unless $core;
100 my $mani = File::Spec->catfile($updir, "MANIFEST");
101 if (open(MANI, $mani)) {
102 while (<MANI>) { # similar code in t/harness
103 if (m!^(ext/\S+/?(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
105 if (!$core || $t =~ m!^lib/[a-z]!)
107 $path = File::Spec->catfile($updir, $t);
115 warn "$0: cannot open $mani: $!\n";
120 _find_tests('japh') if $torture;
124 # Tests known to cause infinite loops for the perlcc tests.
125 # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
129 _testprogs('deparse', '', @ARGV);
132 _testprogs('compile', '', @ARGV);
134 elsif( $bytecompile ) {
135 _testprogs('bytecompile', '', @ARGV);
138 _testprogs('compile', '', @ARGV) if -e "../testcompile";
139 _testprogs('perl', '', @ARGV);
147 print <<'EOT' if ($type eq 'compile');
148 ------------------------------------------------------------------------------
150 ------------------------------------------------------------------------------
153 print <<'EOT' if ($type eq 'deparse');
154 ------------------------------------------------------------------------------
156 ------------------------------------------------------------------------------
159 print <<EOT if ($type eq 'bytecompile');
160 ------------------------------------------------------------------------------
161 TESTING BYTECODE COMPILER
162 ------------------------------------------------------------------------------
165 $ENV{PERLCC_TIMEOUT} = 120
166 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
174 foreach my $t (@tests) {
175 unless (exists $name{$t}) {
176 my $tname = File::Spec->catfile('t',$t);
177 $tname = VMS::Filespec::unixify($tname) if $^O eq 'VMS';
182 foreach (@name{@tests}) {
185 $maxlen = $len if $len > $maxlen;
187 # + 3 : we want three dots between the test name and the "ok"
188 $dotdotdot = $maxlen + 3 ;
190 my $valgrind_log = 'current.valgrind';
191 while ($test = shift @tests) {
193 if ( $infinite{$test} && $type eq 'compile' ) {
194 print STDERR "$test creates infinite loop! Skipping.\n";
200 if ($type eq 'deparse') {
201 if ($test eq "comp/redef.t") {
202 # Redefinition happens at compile time
205 elsif ($test =~ m{lib/Switch/t/}) {
206 # B::Deparse doesn't support source filtering
210 $te = $name{$test} . '.' x ($dotdotdot - length($name{$test}));
212 if ($^O ne 'VMS') { # defer printing on VMS due to piping bug
217 $test = $OVER{$test} if exists $OVER{$test};
219 open(SCRIPT,"<$test") or die "Can't run $test.\n";
221 close(SCRIPT) unless ($type eq 'deparse');
222 if (/#!.*\bperl.*\s-\w*([tT])/) {
227 # not all tests are expected to pass with this option
235 my $test_executable; # for 'compile' tests
237 if ($type eq 'deparse') {
238 # Look for #line directives which change the filename
240 $file_opts .= ",-f$3$4"
241 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
246 my $utf = $with_utf ? '-I../lib -Mutf8' : '';
247 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
248 if ($type eq 'deparse') {
250 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,-sv1.,".
251 "-l$deparse_opts$file_opts ".
253 "&& ./perl $testswitch $switch -I../lib $test.dp |";
254 open(RESULTS, $deparse)
255 or print "can't deparse '$deparse': $!.\n";
257 elsif ($type eq 'bytecompile') {
259 if( $^O eq 'MSWin32') {
267 my $perl = $ENV{PERL} || "$pwd/perl";
268 my $bswitch = "-MO=Bytecode,-H,-TI,-s$pwd/$test,";
269 $bswitch .= "-TF$test.plc,"
270 if $test =~ m(chdir|pod/|CGI/t/carp|lib/DB);
272 if $test =~ m(deparse|terse|ext/Storable/t/code);
274 if $test =~ m(op/getpid);
276 "$perl $testswitch $switch -I../lib $bswitch".
277 "-o$test.plc $test 2>$null &&".
278 "$perl $testswitch $switch -I../lib $utf $test.plc |";
279 open(RESULTS,$bytecompile)
280 or print "can't byte-compile '$bytecompile': $!.\n";
282 elsif ($type eq 'perl') {
283 my $perl = $ENV{PERL} || './perl';
284 my $redir = $^O eq 'VMS' ? '2>&1' : '';
285 if ($ENV{PERL_VALGRIND}) {
286 $perl = "valgrind --suppressions=perl.supp --leak-check=yes "
287 . "--leak-resolution=high --show-reachable=yes "
288 . "--num-callers=50 --logfile-fd=3 $perl";
289 $redir = "3>$valgrind_log";
291 my $run = "$perl" . _quote_args("$testswitch $switch $utf") . " $test $redir|";
292 open(RESULTS,$run) or print "can't run '$run': $!.\n";
296 my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
297 # -O9 for good measure, -fcog is broken ATM
298 "$switch -Wb=-O9,-fno-cog -L .. " .
299 "-I \".. ../lib/CORE\" $args $utf $test -o ";
301 if( $^O eq 'MSWin32' ) {
302 $test_executable = "$test.exe";
303 # hopefully unused name...
304 open HACK, "> xweghyz.pl";
308 open HACK, '.\\perl $pl2c $test_executable |';
309 # cl.exe prints the name of the .c file on stdout (\%^\$^#)
310 while(<HACK>) {m/^\\w+\\.[cC]\$/ && next;print}
311 open HACK, '$test_executable |';
312 while(<HACK>) {print}
315 $compile = 'xweghyz.pl |';
318 $test_executable = "$test.plc";
319 $compile = "./perl $pl2c $test_executable && $test_executable |";
321 unlink $test_executable if -f $test_executable;
322 open(RESULTS, $compile)
323 or print "can't compile '$compile': $!.\n";
331 next if /^\s*$/; # skip blank lines
336 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
338 %todo = map { $_ => 1 } split / /, $3 if $3;
348 if (/^(not )?ok (\d+)[^\#]*(\s*\#.*)?/) {
349 unless ($seen_leader) {
357 my($not, $num, $extra) = ($1, $2, $3);
358 my($istodo) = $extra =~ /#\s*TODO/ if $extra;
359 $istodo = 1 if $todo{$num};
361 if( $not && !$istodo ) {
371 elsif (/^Bail out!\s*(.*)/i) { # magic words
372 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
381 if ($ENV{PERL_VALGRIND}) {
383 if (-e $valgrind_log) {
384 if (open(V, $valgrind_log)) {
388 warn "$0: Failed to open '$valgrind_log': $!\n";
394 for my $i (0..$#valgrind) {
395 local $_ = $valgrind[$i];
396 if (/^==\d+== ERROR SUMMARY: (\d+) errors? /) {
397 $errors += $1; # there may be multiple error summaries
398 } elsif (/^==\d+== LEAK SUMMARY:/) {
399 for my $off (1 .. 4) {
400 if ($valgrind[$i+$off] =~
401 /(?:lost|reachable):\s+\d+ bytes in (\d+) blocks/) {
407 if ($errors or $leaks) {
408 if (rename $valgrind_log, "$test.valgrind") {
411 warn "$0: Failed to create '$test.valgrind': $!\n";
415 warn "No valgrind output?\n";
417 if (-e $valgrind_log) {
419 or warn "$0: Failed to unlink '$valgrind_log': $!\n";
422 if ($type eq 'deparse') {
425 if ($ENV{PERL_3LOG}) {
429 $tpp =~ s:\.t$:.3log:;
430 rename("perl.3log", $tpp) ||
431 die "rename: perl3.log to $tpp: $!\n";
434 # test if the compiler compiled something
435 if( $type eq 'compile' && !-e "$test_executable" ) {
437 print "Test did not compile\n";
439 if ($ok && $next == $max ) {
445 print "${te}skipping test on this platform\n";
452 print "${te}FAILED at test $next\tpossibly due to extra output\n";
455 print "${te}FAILED at test $next\n";
460 die "Failed a basic test--cannot continue.\n";
467 print "All tests successful.\n";
468 # XXX add mention of 'perlbug -ok' ?
471 die "FAILED--no tests were run for some reason.\n";
475 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
477 warn "Failed 1 test script out of $files, $pct% okay.\n";
480 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
483 ### Since not all tests were successful, you may want to run some of
484 ### them individually and examine any diagnostic messages they produce.
485 ### See the INSTALL document's section on "make test".
487 warn <<'SHRDLU_2' if $good / $total > 0.8;
488 ### You have a good chance to get more information by running
490 ### in the 't' directory since most (>=80%) of the tests succeeded.
492 if (eval {require Config; import Config; 1}) {
493 if ($Config{usedl} && (my $p = $Config{ldlibpthname})) {
495 ### You may have to set your dynamic library search path,
496 ### $p, to point to the build directory:
498 if (exists $ENV{$p} && $ENV{$p} ne '') {
500 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
501 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
502 ### export $p=`pwd`:\$$p; cd t; ./perl harness
506 ### setenv $p `pwd`; cd t; ./perl harness
507 ### $p=`pwd`; export $p; cd t; ./perl harness
508 ### export $p=`pwd`; cd t; ./perl harness
512 ### for csh-style shells, like tcsh; or for traditional/modern
513 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
518 ($user,$sys,$cuser,$csys) = times;
519 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
520 $user,$sys,$cuser,$csys,$files,$totmax);
521 if ($ENV{PERL_VALGRIND}) {
522 my $s = $valgrind == 1 ? '' : 's';
523 print "$valgrind valgrind report$s created.\n", ;