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 ;
186 while ($test = shift @tests) {
188 if ( $infinite{$test} && $type eq 'compile' ) {
189 print STDERR "$test creates infinite loop! Skipping.\n";
195 if ($type eq 'deparse') {
196 if ($test eq "comp/redef.t") {
197 # Redefinition happens at compile time
200 elsif ($test eq "lib/switch.t") {
201 # B::Deparse doesn't support source filtering
205 $te = $name{$test} . '.' x ($dotdotdot - length($name{$test}));
207 if ($^O ne 'VMS') { # defer printing on VMS due to piping bug
212 $test = $OVER{$test} if exists $OVER{$test};
214 open(SCRIPT,"<$test") or die "Can't run $test.\n";
216 close(SCRIPT) unless ($type eq 'deparse');
217 if (/#!.*\bperl.*\s-\w*([tT])/) {
224 my $test_executable; # for 'compile' tests
226 if ($type eq 'deparse') {
227 # Look for #line directives which change the filename
229 $file_opts .= ",-f$3$4"
230 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
235 my $utf = $with_utf ? '-I../lib -Mutf8' : '';
236 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
237 if ($type eq 'deparse') {
239 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,-sv1.,".
240 "-l$deparse_opts$file_opts ".
242 "&& ./perl $testswitch $switch -I../lib $test.dp |";
243 open(RESULTS, $deparse)
244 or print "can't deparse '$deparse': $!.\n";
246 elsif ($type eq 'bytecompile') {
247 my $perl = $ENV{PERL} || './perl';
248 my $redir = ($^O eq 'VMS' ? '2>&1' : '');
249 my $bswitch = "-MO=Bytecode,-H,-s,-TD`pwd`,";
251 if $test =~ m(chdir|pod/|CGI/t/carp|lib/DB);
253 if $test =~ m(deparse|terse|ext/Storable/t/code);
255 if $] < 5.009 && $test =~ m(avhv|hashwarn);
257 if $test =~ m(op/getpid);
259 "$perl $testswitch $switch -I../lib $bswitch".
260 "-o$test.plc $test 2>/dev/null &&".
261 "$perl $testswitch $switch $utf $test.plc $redir|";
262 open(RESULTS,$bytecompile)
263 or print "can't byte-compile '$bytecompile': $!.\n";
265 elsif ($type eq 'perl') {
266 my $perl = $ENV{PERL} || './perl';
267 my $redir = ($^O eq 'VMS' ? '2>&1' : '');
268 my $run = "$perl" . _quote_args("$testswitch $switch $utf") . " $test $redir|";
269 open(RESULTS,$run) or print "can't run '$run': $!.\n";
273 my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
274 # -O9 for good measure, -fcog is broken ATM
275 "$switch -Wb=-O9,-fno-cog -L .. " .
276 "-I \".. ../lib/CORE\" $args $utf $test -o ";
278 if( $^O eq 'MSWin32' ) {
279 $test_executable = "$test.exe";
280 # hopefully unused name...
281 open HACK, "> xweghyz.pl";
285 open HACK, '.\\perl $pl2c $test_executable |';
286 # cl.exe prints the name of the .c file on stdout (\%^\$^#)
287 while(<HACK>) {m/^\\w+\\.[cC]\$/ && next;print}
288 open HACK, '$test_executable |';
289 while(<HACK>) {print}
292 $compile = 'xweghyz.pl |';
295 $test_executable = "$test.plc";
296 $compile = "./perl $pl2c $test_executable && $test_executable |";
298 unlink $test_executable if -f $test_executable;
299 open(RESULTS, $compile)
300 or print "can't compile '$compile': $!.\n";
306 next if /^\s*$/; # skip blank lines
311 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
313 %todo = map { $_ => 1 } split / /, $3 if $3;
320 if (/^(not )?ok (\d+)[^#]*(\s*#.*)?/ &&
323 my($not, $num, $extra) = ($1, $2, $3);
324 my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
325 $istodo = 1 if $todo{$num};
327 if( $not && !$istodo ) {
336 elsif (/^Bail out!\s*(.*)/i) { # magic words
337 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
346 if ($type eq 'deparse') {
349 if ($ENV{PERL_3LOG}) {
353 $tpp =~ s:\.t$:.3log:;
354 rename("perl.3log", $tpp) ||
355 die "rename: perl3.log to $tpp: $!\n";
358 # test if the compiler compiled something
359 if( $type eq 'compile' && !-e "$test_executable" ) {
361 print "Test did not compile\n";
363 if ($ok && $next == $max ) {
369 print "${te}skipping test on this platform\n";
375 print "${te}FAILED at test $next\n";
379 die "Failed a basic test--cannot continue.\n";
386 print "All tests successful.\n";
387 # XXX add mention of 'perlbug -ok' ?
390 die "FAILED--no tests were run for some reason.\n";
394 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
396 warn "Failed 1 test script out of $files, $pct% okay.\n";
399 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
402 ### Since not all tests were successful, you may want to run some of
403 ### them individually and examine any diagnostic messages they produce.
404 ### See the INSTALL document's section on "make test".
406 warn <<'SHRDLU_2' if $good / $total > 0.8;
407 ### You have a good chance to get more information by running
409 ### in the 't' directory since most (>=80%) of the tests succeeded.
411 if (eval {require Config; import Config; 1}) {
412 if ($Config{usedl} && (my $p = $Config{ldlibpthname})) {
414 ### You may have to set your dynamic library search path,
415 ### $p, to point to the build directory:
417 if (exists $ENV{$p} && $ENV{$p} ne '') {
419 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
420 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
421 ### export $p=`pwd`:\$$p; cd t; ./perl harness
425 ### setenv $p `pwd`; cd t; ./perl harness
426 ### $p=`pwd`; export $p; cd t; ./perl harness
427 ### export $p=`pwd`; cd t; ./perl harness
431 ### for csh-style shells, like tcsh; or for traditional/modern
432 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
437 ($user,$sys,$cuser,$csys) = times;
438 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
439 $user,$sys,$cuser,$csys,$files,$totmax);