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 $byte_compile = 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+/?([^/]+\.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);
128 elsif( $compile || $byte_compile ) {
129 _testprogs('compile', '', @ARGV) if $compile;
130 _testprogs('compile', '-B', @ARGV) if $byte_compile;
133 _testprogs('compile', '', @ARGV) if -e "../testcompile";
134 _testprogs('perl', '', @ARGV);
142 print <<'EOT' if ($type eq 'compile');
143 ------------------------------------------------------------------------------
145 ------------------------------------------------------------------------------
148 print <<'EOT' if ($type eq 'deparse');
149 ------------------------------------------------------------------------------
151 ------------------------------------------------------------------------------
154 $ENV{PERLCC_TIMEOUT} = 120
155 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
163 foreach my $t (@tests) {
164 unless (exists $name{$t}) {
165 my $tname = File::Spec->catfile('t',$t);
166 $tname = VMS::Filespec::unixify($tname) if $^O eq 'VMS';
171 foreach (@name{@tests}) {
174 $maxlen = $len if $len > $maxlen;
176 # + 3 : we want three dots between the test name and the "ok"
177 $dotdotdot = $maxlen + 3 ;
178 while ($test = shift @tests) {
180 if ( $infinite{$test} && $type eq 'compile' ) {
181 print STDERR "$test creates infinite loop! Skipping.\n";
187 if ($type eq 'deparse') {
188 if ($test eq "comp/redef.t") {
189 # Redefinition happens at compile time
192 elsif ($test eq "lib/switch.t") {
193 # B::Deparse doesn't support source filtering
197 $te = $name{$test} . '.' x ($dotdotdot - length($name{$test}));
199 if ($^O ne 'VMS') { # defer printing on VMS due to piping bug
204 $test = $OVER{$test} if exists $OVER{$test};
206 open(SCRIPT,"<$test") or die "Can't run $test.\n";
208 close(SCRIPT) unless ($type eq 'deparse');
209 if (/#!.*\bperl.*\s-\w*([tT])/) {
216 my $test_executable; # for 'compile' tests
218 if ($type eq 'deparse') {
219 # Look for #line directives which change the filename
221 $file_opts .= ",-f$3$4"
222 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
227 my $utf = $with_utf ? '-I../lib -Mutf8' : '';
228 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
229 if ($type eq 'deparse') {
231 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,".
232 "-l$deparse_opts$file_opts ".
234 "&& ./perl $testswitch $switch -I../lib $test.dp |";
235 open(RESULTS, $deparse)
236 or print "can't deparse '$deparse': $!.\n";
238 elsif ($type eq 'perl') {
239 my $perl = $ENV{PERL} || './perl';
240 my $redir = ($^O eq 'VMS' ? '2>&1' : '');
241 my $run = "$perl" . _quote_args("$testswitch $switch $utf") . " $test $redir|";
242 open(RESULTS,$run) or print "can't run '$run': $!.\n";
246 my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
247 # -O9 for good measure, -fcog is broken ATM
248 "$switch -Wb=-O9,-fno-cog -L .. " .
249 "-I \".. ../lib/CORE\" $args $utf $test -o ";
251 if( $^O eq 'MSWin32' ) {
252 $test_executable = "$test.exe";
253 # hopefully unused name...
254 open HACK, "> xweghyz.pl";
258 open HACK, '.\\perl $pl2c $test_executable |';
259 # cl.exe prints the name of the .c file on stdout (\%^\$^#)
260 while(<HACK>) {m/^\\w+\\.[cC]\$/ && next;print}
261 open HACK, '$test_executable |';
262 while(<HACK>) {print}
265 $compile = 'xweghyz.pl |';
268 $test_executable = "$test.plc";
269 $compile = "./perl $pl2c $test_executable && $test_executable |";
271 unlink $test_executable if -f $test_executable;
272 open(RESULTS, $compile)
273 or print "can't compile '$compile': $!.\n";
279 next if /^\s*$/; # skip blank lines
284 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
286 %todo = map { $_ => 1 } split / /, $3 if $3;
293 if (/^(not )?ok (\d+)[^#]*(\s*#.*)?/ &&
296 my($not, $num, $extra) = ($1, $2, $3);
297 my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
298 $istodo = 1 if $todo{$num};
300 if( $not && !$istodo ) {
309 elsif (/^Bail out!\s*(.*)/i) { # magic words
310 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
319 if ($type eq 'deparse') {
322 if ($ENV{PERL_3LOG}) {
327 rename("perl.3log", "perl.3log.$tpp") ||
328 die "rename: perl3.log to perl.3log.$tpp: $!\n";
331 # test if the compiler compiled something
332 if( $type eq 'compile' && !-e "$test_executable" ) {
334 print "Test did not compile\n";
336 if ($ok && $next == $max ) {
342 print "${te}skipping test on this platform\n";
348 print "${te}FAILED at test $next\n";
352 die "Failed a basic test--cannot continue.\n";
359 print "All tests successful.\n";
360 # XXX add mention of 'perlbug -ok' ?
363 die "FAILED--no tests were run for some reason.\n";
367 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
369 warn "Failed 1 test script out of $files, $pct% okay.\n";
372 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
375 ### Since not all tests were successful, you may want to run some of
376 ### them individually and examine any diagnostic messages they produce.
377 ### See the INSTALL document's section on "make test".
379 warn <<'SHRDLU_2' if $good / $total > 0.8;
380 ### You have a good chance to get more information by running
382 ### in the 't' directory since most (>=80%) of the tests succeeded.
384 if (eval {require Config; import Config; 1}) {
385 if ($Config{usedl} && (my $p = $Config{ldlibpthname})) {
387 ### You may have to set your dynamic library search path,
388 ### $p, to point to the build directory:
390 if (exists $ENV{$p} && $ENV{$p} ne '') {
392 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
393 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
394 ### export $p=`pwd`:\$$p; cd t; ./perl harness
398 ### setenv $p `pwd`; cd t; ./perl harness
399 ### $p=`pwd`; export $p; cd t; ./perl harness
400 ### export $p=`pwd`; cd t; ./perl harness
404 ### for csh-style shells, like tcsh; or for traditional/modern
405 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
410 ($user,$sys,$cuser,$csys) = times;
411 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
412 $user,$sys,$cuser,$csys,$files,$totmax);