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;
264 while ($test = shift @tests) {
266 if ( $::infinite{$test} && $type eq 'compile' ) {
267 print STDERR "$test creates infinite loop! Skipping.\n";
273 if ($type eq 'deparse') {
274 if ($test eq "comp/redef.t") {
275 # Redefinition happens at compile time
278 elsif ($test =~ m{lib/Switch/t/}) {
279 # B::Deparse doesn't support source filtering
283 my $te = $::path_to_name{$test} . '.'
284 x ($dotdotdot - length($::path_to_name{$test}));
286 if ($^O ne 'VMS') { # defer printing on VMS due to piping bug
291 # XXX DAPM %OVER not defined anywhere
292 # $test = $OVER{$test} if exists $OVER{$test};
294 open(SCRIPT,"<$test") or die "Can't run $test.\n";
296 close(SCRIPT) unless ($type eq 'deparse');
301 if (/#!.*\bperl.*\s-\w*([tT])/) {
306 # not all tests are expected to pass with this option
314 my $test_executable; # for 'compile' tests
316 if ($type eq 'deparse') {
317 # Look for #line directives which change the filename
319 $file_opts .= ",-f$3$4"
320 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
325 my $utf8 = $::with_utf8 ? '-I../lib -Mutf8' : '';
326 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
327 if ($type eq 'deparse') {
329 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,-sv1.,".
330 "-l$::deparse_opts$file_opts ".
332 "&& ./perl $testswitch $switch -I../lib $test.dp |";
333 open(RESULTS, $deparse_cmd)
334 or print "can't deparse '$deparse_cmd': $!.\n";
336 elsif ($type eq 'bytecompile') {
338 if( $^O eq 'MSWin32') {
346 my $perl = $ENV{PERL} || "$pwd/perl";
347 my $bswitch = "-MO=Bytecode,-H,-TI,-s$pwd/$test,";
348 $bswitch .= "-TF$test.plc,"
349 if $test =~ m(chdir|pod/|CGI/t/carp|lib/DB);
351 if $test =~ m(deparse|terse|ext/Storable/t/code);
353 if $test =~ m(op/getpid);
354 my $bytecompile_cmd =
355 "$perl $testswitch $switch -I../lib $bswitch".
356 "-o$test.plc $test 2>$null &&".
357 "$perl $testswitch $switch -I../lib $utf8 $test.plc |";
358 open(RESULTS,$bytecompile_cmd)
359 or print "can't byte-compile '$bytecompile_cmd': $!.\n";
361 elsif ($type eq 'perl') {
362 my $perl = $ENV{PERL} || './perl';
363 my $redir = $^O eq 'VMS' ? '2>&1' : '';
364 if ($ENV{PERL_VALGRIND}) {
365 $perl = "valgrind --suppressions=perl.supp --leak-check=yes "
366 . "--leak-resolution=high --show-reachable=yes "
367 . "--num-callers=50 --logfile-fd=3 $perl";
368 $redir = "3>$valgrind_log";
370 my $run = "$perl" . _quote_args("$testswitch $switch $utf8")
372 open(RESULTS,$run) or print "can't run '$run': $!.\n";
376 my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
377 # -O9 for good measure, -fcog is broken ATM
378 "$switch -Wb=-O9,-fno-cog -L .. " .
379 "-I \".. ../lib/CORE\" $args $utf8 $test -o ";
381 if( $^O eq 'MSWin32' ) {
382 $test_executable = "$test.exe";
383 # hopefully unused name...
384 open HACK, "> xweghyz.pl";
388 open HACK, '.\\perl $pl2c $test_executable |';
389 # cl.exe prints the name of the .c file on stdout (\%^\$^#)
390 while(<HACK>) {m/^\\w+\\.[cC]\$/ && next;print}
391 open HACK, '$test_executable |';
392 while(<HACK>) {print}
395 $compile_cmd = 'xweghyz.pl |';
398 $test_executable = "$test.plc";
400 = "./perl $pl2c $test_executable && $test_executable |";
402 unlink $test_executable if -f $test_executable;
403 open(RESULTS, $compile_cmd)
404 or print "can't compile '$compile_cmd': $!.\n";
411 my $trailing_leader = 0;
415 next if /^\s*$/; # skip blank lines
420 if ($trailing_leader) {
421 # shouldn't be anything following a postfix 1..n
422 $failure = 'FAILED--extra output after trailing 1..n';
425 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
427 $failure = 'FAILED--seen duplicate leader';
431 %todo = map { $_ => 1 } split / /, $3 if $3;
435 # 1..n appears at end of file
436 $trailing_leader = 1;
438 $failure = "FAILED--expected $max tests, saw $next";
448 if (/^(not )?ok (\d+)[^\#]*(\s*\#.*)?/) {
449 unless ($seen_leader) {
457 my($not, $num, $extra, $istodo) = ($1, $2, $3, 0);
458 # SKIP is essentially the same as TODO for t/TEST
459 # this still conforms to TAP:
460 # http://search.cpan.org/dist/Test-Harness/lib/Test/Harness/TAP.pod
461 $extra and $istodo = $extra =~ /#\s*(?:TODO|SKIP)\b/;
462 $istodo = 1 if $todo{$num};
464 if( $not && !$istodo ) {
465 $failure = "FAILED at test $num";
470 $failure ="FAILED--expected test $next, saw test $2";
474 elsif (/^Bail out!\s*(.*)/i) { # magic words
475 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
478 $failure = "FAILED--unexpected output at test $next";
486 if (not defined $failure) {
487 $failure = 'FAILED--no leader found' unless $seen_leader;
490 if ($ENV{PERL_VALGRIND}) {
492 if (-e $valgrind_log) {
493 if (open(V, $valgrind_log)) {
497 warn "$0: Failed to open '$valgrind_log': $!\n";
503 for my $i (0..$#valgrind) {
504 local $_ = $valgrind[$i];
505 if (/^==\d+== ERROR SUMMARY: (\d+) errors? /) {
506 $errors += $1; # there may be multiple error summaries
507 } elsif (/^==\d+== LEAK SUMMARY:/) {
508 for my $off (1 .. 4) {
509 if ($valgrind[$i+$off] =~
510 /(?:lost|reachable):\s+\d+ bytes in (\d+) blocks/) {
516 if ($errors or $leaks) {
517 if (rename $valgrind_log, "$test.valgrind") {
520 warn "$0: Failed to create '$test.valgrind': $!\n";
524 warn "No valgrind output?\n";
526 if (-e $valgrind_log) {
528 or warn "$0: Failed to unlink '$valgrind_log': $!\n";
531 if ($type eq 'deparse') {
534 if ($ENV{PERL_3LOG}) {
538 $tpp =~ s:\.t$:.3log:;
539 rename("perl.3log", $tpp) ||
540 die "rename: perl3.log to $tpp: $!\n";
542 # test if the compiler compiled something
543 if( $type eq 'compile' && !-e "$test_executable" ) {
544 $failure = "Test did not compile";
546 if (not defined $failure and $next != $max) {
547 $failure="FAILED--expected $max tests, saw $next";
550 if (defined $failure) {
551 print "${te}$failure\n";
555 die "Failed a basic test--cannot continue.\n";
564 print "${te}skipping test on this platform\n";
570 if ($::bad_files == 0) {
572 print "All tests successful.\n";
573 # XXX add mention of 'perlbug -ok' ?
576 die "FAILED--no tests were run for some reason.\n";
580 my $pct = $tested_files ? sprintf("%.2f", ($tested_files - $::bad_files) / $tested_files * 100) : "0.00";
581 if ($::bad_files == 1) {
582 warn "Failed 1 test script out of $tested_files, $pct% okay.\n";
585 warn "Failed $::bad_files test scripts out of $tested_files, $pct% okay.\n";
588 ### Since not all tests were successful, you may want to run some of
589 ### them individually and examine any diagnostic messages they produce.
590 ### See the INSTALL document's section on "make test".
592 warn <<'SHRDLU_2' if $good_files / $total_files > 0.8;
593 ### You have a good chance to get more information by running
595 ### in the 't' directory since most (>=80%) of the tests succeeded.
597 if (eval {require Config; import Config; 1}) {
598 if ($::Config{usedl} && (my $p = $::Config{ldlibpthname})) {
600 ### You may have to set your dynamic library search path,
601 ### $p, to point to the build directory:
603 if (exists $ENV{$p} && $ENV{$p} ne '') {
605 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
606 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
607 ### export $p=`pwd`:\$$p; cd t; ./perl harness
611 ### setenv $p `pwd`; cd t; ./perl harness
612 ### $p=`pwd`; export $p; cd t; ./perl harness
613 ### export $p=`pwd`; cd t; ./perl harness
617 ### for csh-style shells, like tcsh; or for traditional/modern
618 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
623 my ($user,$sys,$cuser,$csys) = times;
624 print sprintf("u=%.2f s=%.2f cu=%.2f cs=%.2f scripts=%d tests=%d\n",
625 $user,$sys,$cuser,$csys,$tested_files,$totmax);
626 if ($ENV{PERL_VALGRIND}) {
627 my $s = $valgrind == 1 ? '' : 's';
628 print "$valgrind valgrind report$s created.\n", ;
631 exit ($::bad_files != 0);