3 # This is written in a peculiar style, since we're trying to avoid
4 # most of the constructs we'll be testing for. (This comment is
5 # probably obsolete on the avoidance side, though still currrent
6 # on the peculiarity side.)
10 # Let tests know they're running in the perl core. Useful for modules
11 # which live dual lives on CPAN.
14 # remove empty elements due to insertion of empty symbols via "''p1'" syntax
15 @ARGV = grep($_,@ARGV) if $^O eq 'VMS';
17 # Cheesy version of Getopt::Std. Maybe we should replace it with that.
20 foreach my $idx (0..$#ARGV) {
21 push( @argv, $ARGV[$idx] ), next unless $ARGV[$idx] =~ /^-(\S+)$/;
22 $core = 1 if $1 eq 'core';
23 $verbose = 1 if $1 eq 'v';
24 $torture = 1 if $1 eq 'torture';
25 $with_utf8 = 1 if $1 eq 'utf8';
26 $with_utf16 = 1 if $1 eq 'utf16';
27 $bytecompile = 1 if $1 eq 'bytecompile';
28 $compile = 1 if $1 eq 'compile';
29 $taintwarn = 1 if $1 eq 'taintwarn';
30 $ENV{PERL_CORE_MINITEST} = 1 if $1 eq 'minitest';
31 if ($1 =~ /^deparse(,.+)?$/) {
39 chdir 't' if -f 't/TEST';
41 die "You need to run \"make test\" first to set things up.\n"
42 unless -e 'perl' or -e 'perl.exe' or -e 'perl.pm';
44 if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
45 unless (-x 'perl.third') {
46 unless (-x '../perl.third') {
47 die "You need to run \"make perl.third first.\n";
50 print "Symlinking ../perl.third as perl.third...\n";
51 die "Failed to symlink: $!\n"
52 unless symlink("../perl.third", "perl.third");
53 die "Symlinked but no executable perl.third: $!\n"
54 unless -x 'perl.third';
59 # check leakage for embedders
60 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
62 $ENV{EMXSHELL} = 'sh'; # For OS/2
64 # Roll your own File::Find!
67 my $curdir = File::Spec->curdir;
68 my $updir = File::Spec->updir;
72 opendir DIR, $dir or die "Trouble opening $dir: $!";
73 foreach my $f (sort { $a cmp $b } readdir DIR) {
74 next if $f eq $curdir or $f eq $updir or
75 $f =~ /^(?:CVS|RCS|SCCS|\.svn)$/;
77 my $fullpath = File::Spec->catfile($dir, $f);
79 _find_tests($fullpath) if -d $fullpath;
80 $fullpath = VMS::Filespec::unixify($fullpath) if $^O eq 'VMS';
81 push @ARGV, $fullpath if $f =~ /\.t$/;
89 foreach (split(/\s+/,$args)) {
90 # In VMS protect with doublequotes because otherwise
91 # DCL will lowercase -- unless already doublequoted.
92 $_ = q(").$_.q(") if ($^O eq 'VMS') && !/^\"/ && length($_) > 0;
93 $argstring .= ' ' . $_;
99 return map {$_, 1} split /\s+/, $_[0];
103 foreach my $dir (qw(base comp cmd run io op uni)) {
106 _find_tests("lib") unless $core;
107 # Config.pm may be broken for make minitest. And this is only a refinement
108 # for skipping tests on non-default builds, so it is allowed to fail.
109 # What we want to to is make a list of extensions which we did not build.
110 my $configsh = File::Spec->catfile($updir, "config.sh");
113 my (%extensions, %known_extensions);
114 open FH, $configsh or die "Can't open $configsh: $!";
116 if (/^extensions=['"](.*)['"]$/) {
117 # Deliberate string interpolation to avoid triggering possible
119 %extensions = _populate_hash ("$1");
121 elsif (/^known_extensions=['"](.*)['"]$/) {
122 %known_extensions = _populate_hash ($1);
126 if (%known_extensions) {
127 foreach (keys %known_extensions) {
128 $skip{$_}++ unless $extensions{$_};
131 warn "No known_extensions line found in $configsh";
134 warn "No extensions line found in $configsh";
137 my $mani = File::Spec->catfile($updir, "MANIFEST");
138 if (open(MANI, $mani)) {
139 while (<MANI>) { # similar code in t/harness
140 if (m!^(ext/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
143 if (!$core || $t =~ m!^lib/[a-z]!)
145 if (defined $extension) {
146 $extension =~ s!/t$!!;
147 # XXX Do I want to warn that I'm skipping these?
148 next if $skip{$extension};
150 $path = File::Spec->catfile($updir, $t);
158 warn "$0: cannot open $mani: $!\n";
163 _find_tests('japh') if $torture;
167 # Tests known to cause infinite loops for the perlcc tests.
168 # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
172 _testprogs('deparse', '', @ARGV);
175 _testprogs('compile', '', @ARGV);
177 elsif( $bytecompile ) {
178 _testprogs('bytecompile', '', @ARGV);
180 elsif ($with_utf16) {
183 print STDERR "# ENDIAN $e BOM $b\n";
186 my $u = $a . "." . ($e ? "l" : "b") . "e" . ($b ? "b" : "");
187 my $f = $e ? "v" : "n";
191 if (open(U, ">$u")) {
192 print U pack("$f", 0xFEFF) if $b;
194 print U pack("$f*", unpack("C*", $_));
201 _testprogs('perl', '', @UARGV);
207 _testprogs('compile', '', @ARGV) if -e "../testcompile";
208 _testprogs('perl', '', @ARGV);
216 print <<'EOT' if ($type eq 'compile');
217 ------------------------------------------------------------------------------
219 ------------------------------------------------------------------------------
222 print <<'EOT' if ($type eq 'deparse');
223 ------------------------------------------------------------------------------
225 ------------------------------------------------------------------------------
228 print <<EOT if ($type eq 'bytecompile');
229 ------------------------------------------------------------------------------
230 TESTING BYTECODE COMPILER
231 ------------------------------------------------------------------------------
234 $ENV{PERLCC_TIMEOUT} = 120
235 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
243 foreach my $t (@tests) {
244 unless (exists $name{$t}) {
245 my $tname = File::Spec->catfile('t',$t);
246 $tname = VMS::Filespec::unixify($tname) if $^O eq 'VMS';
251 foreach (@name{@tests}) {
254 $maxlen = $len if $len > $maxlen;
256 # + 3 : we want three dots between the test name and the "ok"
257 $dotdotdot = $maxlen + 3 ;
259 my $valgrind_log = 'current.valgrind';
260 while ($test = shift @tests) {
262 if ( $infinite{$test} && $type eq 'compile' ) {
263 print STDERR "$test creates infinite loop! Skipping.\n";
269 if ($type eq 'deparse') {
270 if ($test eq "comp/redef.t") {
271 # Redefinition happens at compile time
274 elsif ($test =~ m{lib/Switch/t/}) {
275 # B::Deparse doesn't support source filtering
279 $te = $name{$test} . '.' x ($dotdotdot - length($name{$test}));
281 if ($^O ne 'VMS') { # defer printing on VMS due to piping bug
286 $test = $OVER{$test} if exists $OVER{$test};
288 open(SCRIPT,"<$test") or die "Can't run $test.\n";
290 close(SCRIPT) unless ($type eq 'deparse');
294 if (/#!.*\bperl.*\s-\w*([tT])/) {
299 # not all tests are expected to pass with this option
307 my $test_executable; # for 'compile' tests
309 if ($type eq 'deparse') {
310 # Look for #line directives which change the filename
312 $file_opts .= ",-f$3$4"
313 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
318 my $utf8 = $with_utf8 ? '-I../lib -Mutf8' : '';
319 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
320 if ($type eq 'deparse') {
322 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,-sv1.,".
323 "-l$deparse_opts$file_opts ".
325 "&& ./perl $testswitch $switch -I../lib $test.dp |";
326 open(RESULTS, $deparse)
327 or print "can't deparse '$deparse': $!.\n";
329 elsif ($type eq 'bytecompile') {
331 if( $^O eq 'MSWin32') {
339 my $perl = $ENV{PERL} || "$pwd/perl";
340 my $bswitch = "-MO=Bytecode,-H,-TI,-s$pwd/$test,";
341 $bswitch .= "-TF$test.plc,"
342 if $test =~ m(chdir|pod/|CGI/t/carp|lib/DB);
344 if $test =~ m(deparse|terse|ext/Storable/t/code);
346 if $test =~ m(op/getpid);
348 "$perl $testswitch $switch -I../lib $bswitch".
349 "-o$test.plc $test 2>$null &&".
350 "$perl $testswitch $switch -I../lib $utf8 $test.plc |";
351 open(RESULTS,$bytecompile)
352 or print "can't byte-compile '$bytecompile': $!.\n";
354 elsif ($type eq 'perl') {
355 my $perl = $ENV{PERL} || './perl';
356 my $redir = $^O eq 'VMS' ? '2>&1' : '';
357 if ($ENV{PERL_VALGRIND}) {
358 $perl = "valgrind --suppressions=perl.supp --leak-check=yes "
359 . "--leak-resolution=high --show-reachable=yes "
360 . "--num-callers=50 --logfile-fd=3 $perl";
361 $redir = "3>$valgrind_log";
363 my $run = "$perl" . _quote_args("$testswitch $switch $utf8") . " $test $redir|";
364 open(RESULTS,$run) or print "can't run '$run': $!.\n";
368 my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
369 # -O9 for good measure, -fcog is broken ATM
370 "$switch -Wb=-O9,-fno-cog -L .. " .
371 "-I \".. ../lib/CORE\" $args $utf8 $test -o ";
373 if( $^O eq 'MSWin32' ) {
374 $test_executable = "$test.exe";
375 # hopefully unused name...
376 open HACK, "> xweghyz.pl";
380 open HACK, '.\\perl $pl2c $test_executable |';
381 # cl.exe prints the name of the .c file on stdout (\%^\$^#)
382 while(<HACK>) {m/^\\w+\\.[cC]\$/ && next;print}
383 open HACK, '$test_executable |';
384 while(<HACK>) {print}
387 $compile = 'xweghyz.pl |';
390 $test_executable = "$test.plc";
391 $compile = "./perl $pl2c $test_executable && $test_executable |";
393 unlink $test_executable if -f $test_executable;
394 open(RESULTS, $compile)
395 or print "can't compile '$compile': $!.\n";
403 next if /^\s*$/; # skip blank lines
408 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
410 %todo = map { $_ => 1 } split / /, $3 if $3;
420 if (/^(not )?ok (\d+)[^\#]*(\s*\#.*)?/) {
421 unless ($seen_leader) {
429 my($not, $num, $extra, $istodo) = ($1, $2, $3, 0);
430 # SKIP is essentially the same as TODO for t/TEST
431 # this still conforms to TAP:
432 # http://search.cpan.org/dist/Test-Harness/lib/Test/Harness/TAP.pod
433 $extra and $istodo = $extra =~ /#\s*(?:TODO|SKIP)\b/;
434 $istodo = 1 if $todo{$num};
436 if( $not && !$istodo ) {
446 elsif (/^Bail out!\s*(.*)/i) { # magic words
447 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
456 if ($ENV{PERL_VALGRIND}) {
458 if (-e $valgrind_log) {
459 if (open(V, $valgrind_log)) {
463 warn "$0: Failed to open '$valgrind_log': $!\n";
469 for my $i (0..$#valgrind) {
470 local $_ = $valgrind[$i];
471 if (/^==\d+== ERROR SUMMARY: (\d+) errors? /) {
472 $errors += $1; # there may be multiple error summaries
473 } elsif (/^==\d+== LEAK SUMMARY:/) {
474 for my $off (1 .. 4) {
475 if ($valgrind[$i+$off] =~
476 /(?:lost|reachable):\s+\d+ bytes in (\d+) blocks/) {
482 if ($errors or $leaks) {
483 if (rename $valgrind_log, "$test.valgrind") {
486 warn "$0: Failed to create '$test.valgrind': $!\n";
490 warn "No valgrind output?\n";
492 if (-e $valgrind_log) {
494 or warn "$0: Failed to unlink '$valgrind_log': $!\n";
497 if ($type eq 'deparse') {
500 if ($ENV{PERL_3LOG}) {
504 $tpp =~ s:\.t$:.3log:;
505 rename("perl.3log", $tpp) ||
506 die "rename: perl3.log to $tpp: $!\n";
509 # test if the compiler compiled something
510 if( $type eq 'compile' && !-e "$test_executable" ) {
512 print "Test did not compile\n";
514 if ($ok && $next == $max ) {
520 print "${te}skipping test on this platform\n";
527 print "${te}FAILED at test $next\tpossibly due to extra output\n";
530 print "${te}FAILED at test $next\n";
535 die "Failed a basic test--cannot continue.\n";
542 print "All tests successful.\n";
543 # XXX add mention of 'perlbug -ok' ?
546 die "FAILED--no tests were run for some reason.\n";
550 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
552 warn "Failed 1 test script out of $files, $pct% okay.\n";
555 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
558 ### Since not all tests were successful, you may want to run some of
559 ### them individually and examine any diagnostic messages they produce.
560 ### See the INSTALL document's section on "make test".
562 warn <<'SHRDLU_2' if $good / $total > 0.8;
563 ### You have a good chance to get more information by running
565 ### in the 't' directory since most (>=80%) of the tests succeeded.
567 if (eval {require Config; import Config; 1}) {
568 if ($Config{usedl} && (my $p = $Config{ldlibpthname})) {
570 ### You may have to set your dynamic library search path,
571 ### $p, to point to the build directory:
573 if (exists $ENV{$p} && $ENV{$p} ne '') {
575 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
576 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
577 ### export $p=`pwd`:\$$p; cd t; ./perl harness
581 ### setenv $p `pwd`; cd t; ./perl harness
582 ### $p=`pwd`; export $p; cd t; ./perl harness
583 ### export $p=`pwd`; cd t; ./perl harness
587 ### for csh-style shells, like tcsh; or for traditional/modern
588 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
593 ($user,$sys,$cuser,$csys) = times;
594 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
595 $user,$sys,$cuser,$csys,$files,$totmax);
596 if ($ENV{PERL_VALGRIND}) {
597 my $s = $valgrind == 1 ? '' : 's';
598 print "$valgrind valgrind report$s created.\n", ;