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;
73 my $fullpath = File::Spec->catfile($dir, $f);
75 _find_tests($fullpath) if -d $fullpath;
76 $fullpath = VMS::Filespec::unixify($fullpath) if $^O eq 'VMS';
77 push @ARGV, $fullpath if $f =~ /\.t$/;
85 foreach (split(/\s+/,$args)) {
86 # In VMS protect with doublequotes because otherwise
87 # DCL will lowercase -- unless already doublequoted.
88 $_ = q(").$_.q(") if ($^O eq 'VMS') && !/^\"/ && length($_) > 0;
89 $argstring .= ' ' . $_;
95 foreach my $dir (qw(base comp cmd run io op uni)) {
98 _find_tests("lib") unless $core;
99 my $mani = File::Spec->catfile($updir, "MANIFEST");
100 if (open(MANI, $mani)) {
101 while (<MANI>) { # similar code in t/harness
102 if (m!^(ext/\S+/?(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
104 if (!$core || $t =~ m!^lib/[a-z]!)
106 $path = File::Spec->catfile($updir, $t);
114 warn "$0: cannot open $mani: $!\n";
119 _find_tests('japh') if $torture;
123 # Tests known to cause infinite loops for the perlcc tests.
124 # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
128 _testprogs('deparse', '', @ARGV);
131 _testprogs('compile', '', @ARGV);
133 elsif( $bytecompile ) {
134 _testprogs('bytecompile', '', @ARGV);
137 _testprogs('compile', '', @ARGV) if -e "../testcompile";
138 _testprogs('perl', '', @ARGV);
146 print <<'EOT' if ($type eq 'compile');
147 ------------------------------------------------------------------------------
149 ------------------------------------------------------------------------------
152 print <<'EOT' if ($type eq 'deparse');
153 ------------------------------------------------------------------------------
155 ------------------------------------------------------------------------------
158 print <<EOT if ($type eq 'bytecompile');
159 ------------------------------------------------------------------------------
160 TESTING BYTECODE COMPILER
161 ------------------------------------------------------------------------------
164 $ENV{PERLCC_TIMEOUT} = 120
165 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
173 foreach my $t (@tests) {
174 unless (exists $name{$t}) {
175 my $tname = File::Spec->catfile('t',$t);
176 $tname = VMS::Filespec::unixify($tname) if $^O eq 'VMS';
181 foreach (@name{@tests}) {
184 $maxlen = $len if $len > $maxlen;
186 # + 3 : we want three dots between the test name and the "ok"
187 $dotdotdot = $maxlen + 3 ;
189 my $valgrind_log = 'current.valgrind';
190 while ($test = shift @tests) {
192 if ( $infinite{$test} && $type eq 'compile' ) {
193 print STDERR "$test creates infinite loop! Skipping.\n";
199 if ($type eq 'deparse') {
200 if ($test eq "comp/redef.t") {
201 # Redefinition happens at compile time
204 elsif ($test =~ m{lib/Switch/t/}) {
205 # B::Deparse doesn't support source filtering
209 $te = $name{$test} . '.' x ($dotdotdot - length($name{$test}));
211 if ($^O ne 'VMS') { # defer printing on VMS due to piping bug
216 $test = $OVER{$test} if exists $OVER{$test};
218 open(SCRIPT,"<$test") or die "Can't run $test.\n";
220 close(SCRIPT) unless ($type eq 'deparse');
221 if (/#!.*\bperl.*\s-\w*([tT])/) {
226 # not all tests are expected to pass with this option
234 my $test_executable; # for 'compile' tests
236 if ($type eq 'deparse') {
237 # Look for #line directives which change the filename
239 $file_opts .= ",-f$3$4"
240 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
245 my $utf = $with_utf ? '-I../lib -Mutf8' : '';
246 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
247 if ($type eq 'deparse') {
249 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,-sv1.,".
250 "-l$deparse_opts$file_opts ".
252 "&& ./perl $testswitch $switch -I../lib $test.dp |";
253 open(RESULTS, $deparse)
254 or print "can't deparse '$deparse': $!.\n";
256 elsif ($type eq 'bytecompile') {
258 if( $^O eq 'MSWin32') {
266 my $perl = $ENV{PERL} || "$pwd/perl";
267 my $bswitch = "-MO=Bytecode,-H,-TI,-s$pwd/$test,";
268 $bswitch .= "-TF$test.plc,"
269 if $test =~ m(chdir|pod/|CGI/t/carp|lib/DB);
271 if $test =~ m(deparse|terse|ext/Storable/t/code);
273 if $test =~ m(op/getpid);
275 "$perl $testswitch $switch -I../lib $bswitch".
276 "-o$test.plc $test 2>$null &&".
277 "$perl $testswitch $switch -I../lib $utf $test.plc |";
278 open(RESULTS,$bytecompile)
279 or print "can't byte-compile '$bytecompile': $!.\n";
281 elsif ($type eq 'perl') {
282 my $perl = $ENV{PERL} || './perl';
283 my $redir = $^O eq 'VMS' ? '2>&1' : '';
284 if ($ENV{PERL_VALGRIND}) {
285 $perl = "valgrind --suppressions=perl.supp --leak-check=yes "
286 . "--leak-resolution=high --show-reachable=yes "
287 . "--num-callers=50 --logfile-fd=3 $perl";
288 $redir = "3>$valgrind_log";
290 my $run = "$perl" . _quote_args("$testswitch $switch $utf") . " $test $redir|";
291 open(RESULTS,$run) or print "can't run '$run': $!.\n";
295 my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
296 # -O9 for good measure, -fcog is broken ATM
297 "$switch -Wb=-O9,-fno-cog -L .. " .
298 "-I \".. ../lib/CORE\" $args $utf $test -o ";
300 if( $^O eq 'MSWin32' ) {
301 $test_executable = "$test.exe";
302 # hopefully unused name...
303 open HACK, "> xweghyz.pl";
307 open HACK, '.\\perl $pl2c $test_executable |';
308 # cl.exe prints the name of the .c file on stdout (\%^\$^#)
309 while(<HACK>) {m/^\\w+\\.[cC]\$/ && next;print}
310 open HACK, '$test_executable |';
311 while(<HACK>) {print}
314 $compile = 'xweghyz.pl |';
317 $test_executable = "$test.plc";
318 $compile = "./perl $pl2c $test_executable && $test_executable |";
320 unlink $test_executable if -f $test_executable;
321 open(RESULTS, $compile)
322 or print "can't compile '$compile': $!.\n";
330 next if /^\s*$/; # skip blank lines
335 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
337 %todo = map { $_ => 1 } split / /, $3 if $3;
347 if (/^(not )?ok (\d+)[^\#]*(\s*\#.*)?/) {
348 unless ($seen_leader) {
356 my($not, $num, $extra) = ($1, $2, $3);
357 my($istodo) = $extra =~ /#\s*TODO/ if $extra;
358 $istodo = 1 if $todo{$num};
360 if( $not && !$istodo ) {
370 elsif (/^Bail out!\s*(.*)/i) { # magic words
371 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
380 if ($ENV{PERL_VALGRIND}) {
382 if (-e $valgrind_log) {
383 if (open(V, $valgrind_log)) {
387 warn "$0: Failed to open '$valgrind_log': $!\n";
393 for my $i (0..$#valgrind) {
394 local $_ = $valgrind[$i];
395 if (/^==\d+== ERROR SUMMARY: (\d+) errors? /) {
396 $errors += $1; # there may be multiple error summaries
397 } elsif (/^==\d+== LEAK SUMMARY:/) {
398 for my $off (1 .. 4) {
399 if ($valgrind[$i+$off] =~
400 /(?:lost|reachable):\s+\d+ bytes in (\d+) blocks/) {
406 if ($errors or $leaks) {
407 if (rename $valgrind_log, "$test.valgrind") {
410 warn "$0: Failed to create '$test.valgrind': $!\n";
414 warn "No valgrind output?\n";
416 if (-e $valgrind_log) {
418 or warn "$0: Failed to unlink '$valgrind_log': $!\n";
421 if ($type eq 'deparse') {
424 if ($ENV{PERL_3LOG}) {
428 $tpp =~ s:\.t$:.3log:;
429 rename("perl.3log", $tpp) ||
430 die "rename: perl3.log to $tpp: $!\n";
433 # test if the compiler compiled something
434 if( $type eq 'compile' && !-e "$test_executable" ) {
436 print "Test did not compile\n";
438 if ($ok && $next == $max ) {
444 print "${te}skipping test on this platform\n";
450 print "${te}FAILED at test $next\n";
454 die "Failed a basic test--cannot continue.\n";
461 print "All tests successful.\n";
462 # XXX add mention of 'perlbug -ok' ?
465 die "FAILED--no tests were run for some reason.\n";
469 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
471 warn "Failed 1 test script out of $files, $pct% okay.\n";
474 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
477 ### Since not all tests were successful, you may want to run some of
478 ### them individually and examine any diagnostic messages they produce.
479 ### See the INSTALL document's section on "make test".
481 warn <<'SHRDLU_2' if $good / $total > 0.8;
482 ### You have a good chance to get more information by running
484 ### in the 't' directory since most (>=80%) of the tests succeeded.
486 if (eval {require Config; import Config; 1}) {
487 if ($Config{usedl} && (my $p = $Config{ldlibpthname})) {
489 ### You may have to set your dynamic library search path,
490 ### $p, to point to the build directory:
492 if (exists $ENV{$p} && $ENV{$p} ne '') {
494 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
495 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
496 ### export $p=`pwd`:\$$p; cd t; ./perl harness
500 ### setenv $p `pwd`; cd t; ./perl harness
501 ### $p=`pwd`; export $p; cd t; ./perl harness
502 ### export $p=`pwd`; cd t; ./perl harness
506 ### for csh-style shells, like tcsh; or for traditional/modern
507 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
512 ($user,$sys,$cuser,$csys) = times;
513 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
514 $user,$sys,$cuser,$csys,$files,$totmax);
515 if ($ENV{PERL_VALGRIND}) {
516 my $s = $valgrind == 1 ? '' : 's';
517 print "$valgrind valgrind report$s created.\n", ;