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 || 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 while ($test = shift @tests) {
189 if ( $infinite{$test} && $type eq 'compile' ) {
190 print STDERR "$test creates infinite loop! Skipping.\n";
196 if ($type eq 'deparse') {
197 if ($test eq "comp/redef.t") {
198 # Redefinition happens at compile time
201 elsif ($test =~ m{lib/Switch/t/}) {
202 # B::Deparse doesn't support source filtering
206 $te = $name{$test} . '.' x ($dotdotdot - length($name{$test}));
208 if ($^O ne 'VMS') { # defer printing on VMS due to piping bug
213 $test = $OVER{$test} if exists $OVER{$test};
215 open(SCRIPT,"<$test") or die "Can't run $test.\n";
217 close(SCRIPT) unless ($type eq 'deparse');
218 if (/#!.*\bperl.*\s-\w*([tT])/) {
225 my $test_executable; # for 'compile' tests
227 if ($type eq 'deparse') {
228 # Look for #line directives which change the filename
230 $file_opts .= ",-f$3$4"
231 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
236 my $utf = $with_utf ? '-I../lib -Mutf8' : '';
237 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
238 if ($type eq 'deparse') {
240 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,-sv1.,".
241 "-l$deparse_opts$file_opts ".
243 "&& ./perl $testswitch $switch -I../lib $test.dp |";
244 open(RESULTS, $deparse)
245 or print "can't deparse '$deparse': $!.\n";
247 elsif ($type eq 'bytecompile') {
248 my $perl = $ENV{PERL} || './perl';
249 my $redir = ($^O eq 'VMS' ? '2>&1' : '');
250 my $bswitch = "-MO=Bytecode,-H,-TI,-s`pwd`/$test,";
251 $bswitch .= "-TF$test.plc,"
252 if $test =~ m(chdir|pod/|CGI/t/carp|lib/DB);
254 if $test =~ m(deparse|terse|ext/Storable/t/code);
256 if $test =~ m(op/getpid);
258 "$perl $testswitch $switch -I../lib $bswitch".
259 "-o$test.plc $test 2>/dev/null &&".
260 "$perl $testswitch $switch -I../lib $utf $test.plc $redir|";
261 open(RESULTS,$bytecompile)
262 or print "can't byte-compile '$bytecompile': $!.\n";
264 elsif ($type eq 'perl') {
265 my $perl = $ENV{PERL} || './perl';
266 my $redir = ($^O eq 'VMS' || $ENV{PERL_VALGRIND} ? '2>&1' : '');
267 if ($ENV{PERL_VALGRIND}) {
268 $perl = "valgrind --num-callers=50 --leak-check=yes $perl";
270 my $run = "$perl" . _quote_args("$testswitch $switch $utf") . " $test $redir|";
271 open(RESULTS,$run) or print "can't run '$run': $!.\n";
275 my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
276 # -O9 for good measure, -fcog is broken ATM
277 "$switch -Wb=-O9,-fno-cog -L .. " .
278 "-I \".. ../lib/CORE\" $args $utf $test -o ";
280 if( $^O eq 'MSWin32' ) {
281 $test_executable = "$test.exe";
282 # hopefully unused name...
283 open HACK, "> xweghyz.pl";
287 open HACK, '.\\perl $pl2c $test_executable |';
288 # cl.exe prints the name of the .c file on stdout (\%^\$^#)
289 while(<HACK>) {m/^\\w+\\.[cC]\$/ && next;print}
290 open HACK, '$test_executable |';
291 while(<HACK>) {print}
294 $compile = 'xweghyz.pl |';
297 $test_executable = "$test.plc";
298 $compile = "./perl $pl2c $test_executable && $test_executable |";
300 unlink $test_executable if -f $test_executable;
301 open(RESULTS, $compile)
302 or print "can't compile '$compile': $!.\n";
311 next if /^\s*$/; # skip blank lines
315 if ($ENV{PERL_VALGRIND} && /^==\d+== /) {
320 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
322 %todo = map { $_ => 1 } split / /, $3 if $3;
332 if (/^(not )?ok (\d+)[^\#]*(\s*\#.*)?/) {
333 unless ($seen_leader) {
341 my($not, $num, $extra) = ($1, $2, $3);
342 my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
343 $istodo = 1 if $todo{$num};
345 if( $not && !$istodo ) {
355 elsif (/^Bail out!\s*(.*)/i) { # magic words
356 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
365 if ($ENV{PERL_VALGRIND}) {
367 my $skip_pthread_mutex_unlock;
368 for my $i (0..$#valgrind) {
369 local $_ = $valgrind[$i];
371 if (/^==(\d+)== pthread_mutex_unlock: mutex is not locked/ &&
373 $valgrind[$i+2] =~ m{\(in .+/libc.+\.so\)}) {
374 $skip_pthread_mutex_unlock++;
375 } elsif (/^==\d+== ERROR SUMMARY: (\d+) errors? /) {
379 if (defined $errors) {
380 $errors -= $skip_pthread_mutex_unlock;
382 if (open(V, ">$test.valgrind")) {
389 warn "$0: Failed to create '$test.valgrind': $!\n";
394 warn "No valgrind output?\n";
397 if ($type eq 'deparse') {
400 if ($ENV{PERL_3LOG}) {
404 $tpp =~ s:\.t$:.3log:;
405 rename("perl.3log", $tpp) ||
406 die "rename: perl3.log to $tpp: $!\n";
409 # test if the compiler compiled something
410 if( $type eq 'compile' && !-e "$test_executable" ) {
412 print "Test did not compile\n";
414 if ($ok && $next == $max ) {
420 print "${te}skipping test on this platform\n";
426 print "${te}FAILED at test $next\n";
430 die "Failed a basic test--cannot continue.\n";
437 print "All tests successful.\n";
438 # XXX add mention of 'perlbug -ok' ?
441 die "FAILED--no tests were run for some reason.\n";
445 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
447 warn "Failed 1 test script out of $files, $pct% okay.\n";
450 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
453 ### Since not all tests were successful, you may want to run some of
454 ### them individually and examine any diagnostic messages they produce.
455 ### See the INSTALL document's section on "make test".
457 warn <<'SHRDLU_2' if $good / $total > 0.8;
458 ### You have a good chance to get more information by running
460 ### in the 't' directory since most (>=80%) of the tests succeeded.
462 if (eval {require Config; import Config; 1}) {
463 if ($Config{usedl} && (my $p = $Config{ldlibpthname})) {
465 ### You may have to set your dynamic library search path,
466 ### $p, to point to the build directory:
468 if (exists $ENV{$p} && $ENV{$p} ne '') {
470 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
471 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
472 ### export $p=`pwd`:\$$p; cd t; ./perl harness
476 ### setenv $p `pwd`; cd t; ./perl harness
477 ### $p=`pwd`; export $p; cd t; ./perl harness
478 ### export $p=`pwd`; cd t; ./perl harness
482 ### for csh-style shells, like tcsh; or for traditional/modern
483 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
488 ($user,$sys,$cuser,$csys) = times;
489 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
490 $user,$sys,$cuser,$csys,$files,$totmax);
491 if ($ENV{PERL_VALGRIND}) {
492 my $s = $valgrind == 1 ? '' : 's';
493 print "$valgrind valgrind report$s created.\n", ;