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 if ($1 =~ /^deparse(,.+)?$/) {
34 chdir 't' if -f 't/TEST';
36 die "You need to run \"make test\" first to set things up.\n"
37 unless -e 'perl' or -e 'perl.exe' or -e 'perl.pm';
39 if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
40 unless (-x 'perl.third') {
41 unless (-x '../perl.third') {
42 die "You need to run \"make perl.third first.\n";
45 print "Symlinking ../perl.third as perl.third...\n";
46 die "Failed to symlink: $!\n"
47 unless symlink("../perl.third", "perl.third");
48 die "Symlinked but no executable perl.third: $!\n"
49 unless -x 'perl.third';
54 # check leakage for embedders
55 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
57 $ENV{EMXSHELL} = 'sh'; # For OS/2
59 # Roll your own File::Find!
62 my $curdir = File::Spec->curdir;
63 my $updir = File::Spec->updir;
67 opendir DIR, $dir or die "Trouble opening $dir: $!";
68 foreach my $f (sort { $a cmp $b } readdir DIR) {
69 next if $f eq $curdir or $f eq $updir;
71 my $fullpath = File::Spec->catfile($dir, $f);
73 _find_tests($fullpath) if -d $fullpath;
74 $fullpath = VMS::Filespec::unixify($fullpath) if $^O eq 'VMS';
75 push @ARGV, $fullpath if $f =~ /\.t$/;
83 foreach (split(/\s+/,$args)) {
84 # In VMS protect with doublequotes because otherwise
85 # DCL will lowercase -- unless already doublequoted.
86 $_ = q(").$_.q(") if ($^O eq 'VMS') && !/^\"/ && length($_) > 0;
87 $argstring .= ' ' . $_;
93 foreach my $dir (qw(base comp cmd run io op uni)) {
96 _find_tests("lib") unless $core;
97 my $mani = File::Spec->catfile($updir, "MANIFEST");
98 if (open(MANI, $mani)) {
99 while (<MANI>) { # similar code in t/harness
100 if (m!^(ext/\S+/?(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
102 if (!$core || $t =~ m!^lib/[a-z]!)
104 $path = File::Spec->catfile($updir, $t);
112 warn "$0: cannot open $mani: $!\n";
117 _find_tests('japh') if $torture;
121 # Tests known to cause infinite loops for the perlcc tests.
122 # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
126 _testprogs('deparse', '', @ARGV);
129 _testprogs('compile', '', @ARGV);
131 elsif( $bytecompile ) {
132 _testprogs('bytecompile', '', @ARGV);
135 _testprogs('compile', '', @ARGV) if -e "../testcompile";
136 _testprogs('perl', '', @ARGV);
144 print <<'EOT' if ($type eq 'compile');
145 ------------------------------------------------------------------------------
147 ------------------------------------------------------------------------------
150 print <<'EOT' if ($type eq 'deparse');
151 ------------------------------------------------------------------------------
153 ------------------------------------------------------------------------------
156 print <<EOT if ($type eq 'bytecompile');
157 ------------------------------------------------------------------------------
158 TESTING BYTECODE COMPILER
159 ------------------------------------------------------------------------------
162 $ENV{PERLCC_TIMEOUT} = 120
163 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
171 foreach my $t (@tests) {
172 unless (exists $name{$t}) {
173 my $tname = File::Spec->catfile('t',$t);
174 $tname = VMS::Filespec::unixify($tname) if $^O eq 'VMS';
179 foreach (@name{@tests}) {
182 $maxlen = $len if $len > $maxlen;
184 # + 3 : we want three dots between the test name and the "ok"
185 $dotdotdot = $maxlen + 3 ;
187 my $valgrind_log = 'current.valgrind';
188 while ($test = shift @tests) {
190 if ( $infinite{$test} && $type eq 'compile' ) {
191 print STDERR "$test creates infinite loop! Skipping.\n";
197 if ($type eq 'deparse') {
198 if ($test eq "comp/redef.t") {
199 # Redefinition happens at compile time
202 elsif ($test =~ m{lib/Switch/t/}) {
203 # B::Deparse doesn't support source filtering
207 $te = $name{$test} . '.' x ($dotdotdot - length($name{$test}));
209 if ($^O ne 'VMS') { # defer printing on VMS due to piping bug
214 $test = $OVER{$test} if exists $OVER{$test};
216 open(SCRIPT,"<$test") or die "Can't run $test.\n";
218 close(SCRIPT) unless ($type eq 'deparse');
219 if (/#!.*\bperl.*\s-\w*([tT])/) {
226 my $test_executable; # for 'compile' tests
228 if ($type eq 'deparse') {
229 # Look for #line directives which change the filename
231 $file_opts .= ",-f$3$4"
232 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
237 my $utf = $with_utf ? '-I../lib -Mutf8' : '';
238 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
239 if ($type eq 'deparse') {
241 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,-sv1.,".
242 "-l$deparse_opts$file_opts ".
244 "&& ./perl $testswitch $switch -I../lib $test.dp |";
245 open(RESULTS, $deparse)
246 or print "can't deparse '$deparse': $!.\n";
248 elsif ($type eq 'bytecompile') {
250 if( $^O eq 'MSWin32') {
258 my $perl = $ENV{PERL} || "$pwd/perl";
259 my $bswitch = "-MO=Bytecode,-H,-TI,-s$pwd/$test,";
260 $bswitch .= "-TF$test.plc,"
261 if $test =~ m(chdir|pod/|CGI/t/carp|lib/DB);
263 if $test =~ m(deparse|terse|ext/Storable/t/code);
265 if $test =~ m(op/getpid);
267 "$perl $testswitch $switch -I../lib $bswitch".
268 "-o$test.plc $test 2>$null &&".
269 "$perl $testswitch $switch -I../lib $utf $test.plc |";
270 open(RESULTS,$bytecompile)
271 or print "can't byte-compile '$bytecompile': $!.\n";
273 elsif ($type eq 'perl') {
274 my $perl = $ENV{PERL} || './perl';
275 my $redir = $^O eq 'VMS' ? '2>&1' : '';
276 if ($ENV{PERL_VALGRIND}) {
277 $perl = "valgrind --suppressions=perl.supp --leak-check=yes "
278 . "--leak-resolution=high --show-reachable=yes "
279 . "--num-callers=50 --logfile-fd=3 $perl";
280 $redir = "3>$valgrind_log";
282 my $run = "$perl" . _quote_args("$testswitch $switch $utf") . " $test $redir|";
283 open(RESULTS,$run) or print "can't run '$run': $!.\n";
287 my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
288 # -O9 for good measure, -fcog is broken ATM
289 "$switch -Wb=-O9,-fno-cog -L .. " .
290 "-I \".. ../lib/CORE\" $args $utf $test -o ";
292 if( $^O eq 'MSWin32' ) {
293 $test_executable = "$test.exe";
294 # hopefully unused name...
295 open HACK, "> xweghyz.pl";
299 open HACK, '.\\perl $pl2c $test_executable |';
300 # cl.exe prints the name of the .c file on stdout (\%^\$^#)
301 while(<HACK>) {m/^\\w+\\.[cC]\$/ && next;print}
302 open HACK, '$test_executable |';
303 while(<HACK>) {print}
306 $compile = 'xweghyz.pl |';
309 $test_executable = "$test.plc";
310 $compile = "./perl $pl2c $test_executable && $test_executable |";
312 unlink $test_executable if -f $test_executable;
313 open(RESULTS, $compile)
314 or print "can't compile '$compile': $!.\n";
322 next if /^\s*$/; # skip blank lines
327 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
329 %todo = map { $_ => 1 } split / /, $3 if $3;
339 if (/^(not )?ok (\d+)[^\#]*(\s*\#.*)?/) {
340 unless ($seen_leader) {
348 my($not, $num, $extra) = ($1, $2, $3);
349 my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
350 $istodo = 1 if $todo{$num};
352 if( $not && !$istodo ) {
362 elsif (/^Bail out!\s*(.*)/i) { # magic words
363 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
372 if ($ENV{PERL_VALGRIND}) {
374 if (-e $valgrind_log) {
375 if (open(V, $valgrind_log)) {
379 warn "$0: Failed to open '$valgrind_log': $!\n";
385 for my $i (0..$#valgrind) {
386 local $_ = $valgrind[$i];
387 if (/^==\d+== ERROR SUMMARY: (\d+) errors? /) {
388 $errors += $1; # there may be multiple error summaries
389 } elsif (/^==\d+== LEAK SUMMARY:/) {
390 for my $off (1 .. 4) {
391 if ($valgrind[$i+$off] =~
392 /(?:lost|reachable):\s+\d+ bytes in (\d+) blocks/) {
398 if ($errors or $leaks) {
399 if (rename $valgrind_log, "$test.valgrind") {
402 warn "$0: Failed to create '$test.valgrind': $!\n";
406 warn "No valgrind output?\n";
408 if (-e $valgrind_log) {
410 or warn "$0: Failed to unlink '$valgrind_log': $!\n";
413 if ($type eq 'deparse') {
416 if ($ENV{PERL_3LOG}) {
420 $tpp =~ s:\.t$:.3log:;
421 rename("perl.3log", $tpp) ||
422 die "rename: perl3.log to $tpp: $!\n";
425 # test if the compiler compiled something
426 if( $type eq 'compile' && !-e "$test_executable" ) {
428 print "Test did not compile\n";
430 if ($ok && $next == $max ) {
436 print "${te}skipping test on this platform\n";
442 print "${te}FAILED at test $next\n";
446 die "Failed a basic test--cannot continue.\n";
453 print "All tests successful.\n";
454 # XXX add mention of 'perlbug -ok' ?
457 die "FAILED--no tests were run for some reason.\n";
461 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
463 warn "Failed 1 test script out of $files, $pct% okay.\n";
466 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
469 ### Since not all tests were successful, you may want to run some of
470 ### them individually and examine any diagnostic messages they produce.
471 ### See the INSTALL document's section on "make test".
473 warn <<'SHRDLU_2' if $good / $total > 0.8;
474 ### You have a good chance to get more information by running
476 ### in the 't' directory since most (>=80%) of the tests succeeded.
478 if (eval {require Config; import Config; 1}) {
479 if ($Config{usedl} && (my $p = $Config{ldlibpthname})) {
481 ### You may have to set your dynamic library search path,
482 ### $p, to point to the build directory:
484 if (exists $ENV{$p} && $ENV{$p} ne '') {
486 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
487 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
488 ### export $p=`pwd`:\$$p; cd t; ./perl harness
492 ### setenv $p `pwd`; cd t; ./perl harness
493 ### $p=`pwd`; export $p; cd t; ./perl harness
494 ### export $p=`pwd`; cd t; ./perl harness
498 ### for csh-style shells, like tcsh; or for traditional/modern
499 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
504 ($user,$sys,$cuser,$csys) = times;
505 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
506 $user,$sys,$cuser,$csys,$files,$totmax);
507 if ($ENV{PERL_VALGRIND}) {
508 my $s = $valgrind == 1 ? '' : 's';
509 print "$valgrind valgrind report$s created.\n", ;