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 # for testing TEST only
11 #BEGIN { require '../lib/strict.pm'; strict->import() };
12 #BEGIN { require '../lib/warnings.pm'; warnings->import() };
14 # Let tests know they're running in the perl core. Useful for modules
15 # which live dual lives on CPAN.
18 # remove empty elements due to insertion of empty symbols via "''p1'" syntax
19 @ARGV = grep($_,@ARGV) if $^O eq 'VMS';
21 # Cheesy version of Getopt::Std. Maybe we should replace it with that.
24 foreach my $idx (0..$#ARGV) {
25 push( @argv, $ARGV[$idx] ), next unless $ARGV[$idx] =~ /^-(\S+)$/;
26 $::core = 1 if $1 eq 'core';
27 $::verbose = 1 if $1 eq 'v';
28 $::torture = 1 if $1 eq 'torture';
29 $::with_utf8 = 1 if $1 eq 'utf8';
30 $::with_utf16 = 1 if $1 eq 'utf16';
31 $::bytecompile = 1 if $1 eq 'bytecompile';
32 $::compile = 1 if $1 eq 'compile';
33 $::taintwarn = 1 if $1 eq 'taintwarn';
34 $ENV{PERL_CORE_MINITEST} = 1 if $1 eq 'minitest';
35 if ($1 =~ /^deparse(,.+)?$/) {
43 chdir 't' if -f 't/TEST';
45 die "You need to run \"make test\" first to set things up.\n"
46 unless -e 'perl' or -e 'perl.exe' or -e 'perl.pm';
48 if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
49 unless (-x 'perl.third') {
50 unless (-x '../perl.third') {
51 die "You need to run \"make perl.third first.\n";
54 print "Symlinking ../perl.third as perl.third...\n";
55 die "Failed to symlink: $!\n"
56 unless symlink("../perl.third", "perl.third");
57 die "Symlinked but no executable perl.third: $!\n"
58 unless -x 'perl.third';
63 # check leakage for embedders
64 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
66 $ENV{EMXSHELL} = 'sh'; # For OS/2
68 # Roll your own File::Find!
71 my $curdir = File::Spec->curdir;
72 my $updir = File::Spec->updir;
76 opendir DIR, $dir or die "Trouble opening $dir: $!";
77 foreach my $f (sort { $a cmp $b } readdir DIR) {
78 next if $f eq $curdir or $f eq $updir or
79 $f =~ /^(?:CVS|RCS|SCCS|\.svn)$/;
81 my $fullpath = File::Spec->catfile($dir, $f);
83 _find_tests($fullpath) if -d $fullpath;
84 $fullpath = VMS::Filespec::unixify($fullpath) if $^O eq 'VMS';
85 push @ARGV, $fullpath if $f =~ /\.t$/;
93 foreach (split(/\s+/,$args)) {
94 # In VMS protect with doublequotes because otherwise
95 # DCL will lowercase -- unless already doublequoted.
96 $_ = q(").$_.q(") if ($^O eq 'VMS') && !/^\"/ && length($_) > 0;
97 $argstring .= ' ' . $_;
103 return map {$_, 1} split /\s+/, $_[0];
107 foreach my $dir (qw(base comp cmd run io op uni)) {
110 _find_tests("lib") unless $::core;
111 # Config.pm may be broken for make minitest. And this is only a refinement
112 # for skipping tests on non-default builds, so it is allowed to fail.
113 # What we want to to is make a list of extensions which we did not build.
114 my $configsh = File::Spec->catfile($updir, "config.sh");
117 my (%extensions, %known_extensions);
118 open FH, $configsh or die "Can't open $configsh: $!";
120 if (/^extensions=['"](.*)['"]$/) {
121 # Deliberate string interpolation to avoid triggering possible
123 %extensions = _populate_hash ("$1");
125 elsif (/^known_extensions=['"](.*)['"]$/) {
126 %known_extensions = _populate_hash ($1);
130 if (%known_extensions) {
131 foreach (keys %known_extensions) {
132 $skip{$_}++ unless $extensions{$_};
135 warn "No known_extensions line found in $configsh";
138 warn "No extensions line found in $configsh";
141 my $mani = File::Spec->catfile($updir, "MANIFEST");
142 if (open(MANI, $mani)) {
143 while (<MANI>) { # similar code in t/harness
144 if (m!^(ext/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
147 if (!$::core || $t =~ m!^lib/[a-z]!)
149 if (defined $extension) {
150 $extension =~ s!/t$!!;
151 # XXX Do I want to warn that I'm skipping these?
152 next if $skip{$extension};
154 my $path = File::Spec->catfile($updir, $t);
156 $::path_to_name{$path} = $t;
162 warn "$0: cannot open $mani: $!\n";
167 _find_tests('japh') if $::torture;
171 # Tests known to cause infinite loops for the perlcc tests.
172 # %::infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
176 _testprogs('deparse', '', @ARGV);
178 elsif( $::compile ) {
179 _testprogs('compile', '', @ARGV);
181 elsif( $::bytecompile ) {
182 _testprogs('bytecompile', '', @ARGV);
184 elsif ($::with_utf16) {
187 print STDERR "# ENDIAN $e BOM $b\n";
190 my $u = $a . "." . ($e ? "l" : "b") . "e" . ($b ? "b" : "");
191 my $f = $e ? "v" : "n";
195 if (open(U, ">$u")) {
196 print U pack("$f", 0xFEFF) if $b;
198 print U pack("$f*", unpack("C*", $_));
205 _testprogs('perl', '', @UARGV);
211 _testprogs('compile', '', @ARGV) if -e "../testcompile";
212 _testprogs('perl', '', @ARGV);
216 my ($type, $args, @tests) = @_;
218 print <<'EOT' if ($type eq 'compile');
219 ------------------------------------------------------------------------------
221 ------------------------------------------------------------------------------
224 print <<'EOT' if ($type eq 'deparse');
225 ------------------------------------------------------------------------------
227 ------------------------------------------------------------------------------
230 print <<EOT if ($type eq 'bytecompile');
231 ------------------------------------------------------------------------------
232 TESTING BYTECODE COMPILER
233 ------------------------------------------------------------------------------
236 $ENV{PERLCC_TIMEOUT} = 120
237 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
241 foreach my $t (@tests) {
242 unless (exists $::path_to_name{$t}) {
243 my $tname = File::Spec->catfile('t',$t);
244 $tname = VMS::Filespec::unixify($tname) if $^O eq 'VMS';
245 $::path_to_name{$t} = $tname;
249 foreach (@::path_to_name{@tests}) {
252 $maxlen = $len if $len > $maxlen;
254 # + 3 : we want three dots between the test name and the "ok"
255 my $dotdotdot = $maxlen + 3 ;
257 my $valgrind_log = 'current.valgrind';
258 my $total_files = @tests;
260 my $tested_files = 0;
265 while ($test = shift @tests) {
267 if ( $::infinite{$test} && $type eq 'compile' ) {
268 print STDERR "$test creates infinite loop! Skipping.\n";
274 if ($type eq 'deparse') {
275 if ($test eq "comp/redef.t") {
276 # Redefinition happens at compile time
279 elsif ($test =~ m{lib/Switch/t/}) {
280 # B::Deparse doesn't support source filtering
284 my $te = $::path_to_name{$test} . '.'
285 x ($dotdotdot - length($::path_to_name{$test}));
287 if ($^O ne 'VMS') { # defer printing on VMS due to piping bug
292 # XXX DAPM %OVER not defined anywhere
293 # $test = $OVER{$test} if exists $OVER{$test};
295 open(SCRIPT,"<$test") or die "Can't run $test.\n";
297 close(SCRIPT) unless ($type eq 'deparse');
302 if (/#!.*\bperl.*\s-\w*([tT])/) {
307 # not all tests are expected to pass with this option
315 my $test_executable; # for 'compile' tests
317 if ($type eq 'deparse') {
318 # Look for #line directives which change the filename
320 $file_opts .= ",-f$3$4"
321 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
326 my $utf8 = $::with_utf8 ? '-I../lib -Mutf8' : '';
327 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
328 if ($type eq 'deparse') {
330 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,-sv1.,".
331 "-l$::deparse_opts$file_opts ".
333 "&& ./perl $testswitch $switch -I../lib $test.dp |";
334 open(RESULTS, $deparse_cmd)
335 or print "can't deparse '$deparse_cmd': $!.\n";
337 elsif ($type eq 'bytecompile') {
339 if( $^O eq 'MSWin32') {
347 my $perl = $ENV{PERL} || "$pwd/perl";
348 my $bswitch = "-MO=Bytecode,-H,-TI,-s$pwd/$test,";
349 $bswitch .= "-TF$test.plc,"
350 if $test =~ m(chdir|pod/|CGI/t/carp|lib/DB);
352 if $test =~ m(deparse|terse|ext/Storable/t/code);
354 if $test =~ m(op/getpid);
355 my $bytecompile_cmd =
356 "$perl $testswitch $switch -I../lib $bswitch".
357 "-o$test.plc $test 2>$null &&".
358 "$perl $testswitch $switch -I../lib $utf8 $test.plc |";
359 open(RESULTS,$bytecompile_cmd)
360 or print "can't byte-compile '$bytecompile_cmd': $!.\n";
362 elsif ($type eq 'perl') {
363 my $perl = $ENV{PERL} || './perl';
364 my $redir = $^O eq 'VMS' ? '2>&1' : '';
365 if ($ENV{PERL_VALGRIND}) {
366 $perl = "valgrind --suppressions=perl.supp --leak-check=yes "
367 . "--leak-resolution=high --show-reachable=yes "
368 . "--num-callers=50 --logfile-fd=3 $perl";
369 $redir = "3>$valgrind_log";
371 my $run = "$perl" . _quote_args("$testswitch $switch $utf8")
373 open(RESULTS,$run) or print "can't run '$run': $!.\n";
377 my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
378 # -O9 for good measure, -fcog is broken ATM
379 "$switch -Wb=-O9,-fno-cog -L .. " .
380 "-I \".. ../lib/CORE\" $args $utf8 $test -o ";
382 if( $^O eq 'MSWin32' ) {
383 $test_executable = "$test.exe";
384 # hopefully unused name...
385 open HACK, "> xweghyz.pl";
389 open HACK, '.\\perl $pl2c $test_executable |';
390 # cl.exe prints the name of the .c file on stdout (\%^\$^#)
391 while(<HACK>) {m/^\\w+\\.[cC]\$/ && next;print}
392 open HACK, '$test_executable |';
393 while(<HACK>) {print}
396 $compile_cmd = 'xweghyz.pl |';
399 $test_executable = "$test.plc";
401 = "./perl $pl2c $test_executable && $test_executable |";
403 unlink $test_executable if -f $test_executable;
404 open(RESULTS, $compile_cmd)
405 or print "can't compile '$compile_cmd': $!.\n";
414 next if /^\s*$/; # skip blank lines
420 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
422 %todo = map { $_ => 1 } split / /, $3 if $3;
432 if (/^(not )?ok (\d+)[^\#]*(\s*\#.*)?/) {
433 unless ($seen_leader) {
441 my($not, $num, $extra, $istodo) = ($1, $2, $3, 0);
442 # SKIP is essentially the same as TODO for t/TEST
443 # this still conforms to TAP:
444 # http://search.cpan.org/dist/Test-Harness/lib/Test/Harness/TAP.pod
445 $extra and $istodo = $extra =~ /#\s*(?:TODO|SKIP)\b/;
446 $istodo = 1 if $todo{$num};
448 if( $not && !$istodo ) {
458 elsif (/^Bail out!\s*(.*)/i) { # magic words
459 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
468 if ($ENV{PERL_VALGRIND}) {
470 if (-e $valgrind_log) {
471 if (open(V, $valgrind_log)) {
475 warn "$0: Failed to open '$valgrind_log': $!\n";
481 for my $i (0..$#valgrind) {
482 local $_ = $valgrind[$i];
483 if (/^==\d+== ERROR SUMMARY: (\d+) errors? /) {
484 $errors += $1; # there may be multiple error summaries
485 } elsif (/^==\d+== LEAK SUMMARY:/) {
486 for my $off (1 .. 4) {
487 if ($valgrind[$i+$off] =~
488 /(?:lost|reachable):\s+\d+ bytes in (\d+) blocks/) {
494 if ($errors or $leaks) {
495 if (rename $valgrind_log, "$test.valgrind") {
498 warn "$0: Failed to create '$test.valgrind': $!\n";
502 warn "No valgrind output?\n";
504 if (-e $valgrind_log) {
506 or warn "$0: Failed to unlink '$valgrind_log': $!\n";
509 if ($type eq 'deparse') {
512 if ($ENV{PERL_3LOG}) {
516 $tpp =~ s:\.t$:.3log:;
517 rename("perl.3log", $tpp) ||
518 die "rename: perl3.log to $tpp: $!\n";
521 # test if the compiler compiled something
522 if( $type eq 'compile' && !-e "$test_executable" ) {
524 print "Test did not compile\n";
526 if ($ok && $next == $max ) {
532 print "${te}skipping test on this platform\n";
539 print "${te}FAILED at test $next\tpossibly due to extra output\n";
542 print "${te}FAILED at test $next\n";
547 die "Failed a basic test--cannot continue.\n";
552 if ($::bad_files == 0) {
554 print "All tests successful.\n";
555 # XXX add mention of 'perlbug -ok' ?
558 die "FAILED--no tests were run for some reason.\n";
562 my $pct = $tested_files ? sprintf("%.2f", ($tested_files - $::bad_files) / $tested_files * 100) : "0.00";
563 if ($::bad_files == 1) {
564 warn "Failed 1 test script out of $tested_files, $pct% okay.\n";
567 warn "Failed $::bad_files test scripts out of $tested_files, $pct% okay.\n";
570 ### Since not all tests were successful, you may want to run some of
571 ### them individually and examine any diagnostic messages they produce.
572 ### See the INSTALL document's section on "make test".
574 warn <<'SHRDLU_2' if $good_files / $total_files > 0.8;
575 ### You have a good chance to get more information by running
577 ### in the 't' directory since most (>=80%) of the tests succeeded.
579 if (eval {require Config; import Config; 1}) {
580 if ($::Config{usedl} && (my $p = $::Config{ldlibpthname})) {
582 ### You may have to set your dynamic library search path,
583 ### $p, to point to the build directory:
585 if (exists $ENV{$p} && $ENV{$p} ne '') {
587 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
588 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
589 ### export $p=`pwd`:\$$p; cd t; ./perl harness
593 ### setenv $p `pwd`; cd t; ./perl harness
594 ### $p=`pwd`; export $p; cd t; ./perl harness
595 ### export $p=`pwd`; cd t; ./perl harness
599 ### for csh-style shells, like tcsh; or for traditional/modern
600 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
605 my ($user,$sys,$cuser,$csys) = times;
606 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
607 $user,$sys,$cuser,$csys,$tested_files,$totmax);
608 if ($ENV{PERL_VALGRIND}) {
609 my $s = $valgrind == 1 ? '' : 's';
610 print "$valgrind valgrind report$s created.\n", ;
613 exit ($::bad_files != 0);