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 $with_utf= 1 if $1 eq 'utf8';
23 $byte_compile = 1 if $1 eq 'bytecompile';
24 $compile = 1 if $1 eq 'compile';
25 if ($1 =~ /^deparse(,.+)?$/) {
33 chdir 't' if -f 't/TEST';
35 die "You need to run \"make test\" first to set things up.\n"
36 unless -e 'perl' or -e 'perl.exe' or -e 'perl.pm';
38 if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
39 unless (-x 'perl.third') {
40 unless (-x '../perl.third') {
41 die "You need to run \"make perl.third first.\n";
44 print "Symlinking ../perl.third as perl.third...\n";
45 die "Failed to symlink: $!\n"
46 unless symlink("../perl.third", "perl.third");
47 die "Symlinked but no executable perl.third: $!\n"
48 unless -x 'perl.third';
53 # check leakage for embedders
54 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
56 $ENV{EMXSHELL} = 'sh'; # For OS/2
58 # Roll your own File::Find!
61 my $curdir = File::Spec->curdir;
62 my $updir = File::Spec->updir;
66 opendir DIR, $dir || die "Trouble opening $dir: $!";
67 foreach my $f (sort { $a cmp $b } readdir DIR) {
68 next if $f eq $curdir or $f eq $updir;
70 my $fullpath = File::Spec->catfile($dir, $f);
72 _find_tests($fullpath) if -d $fullpath;
73 $fullpath = VMS::Filespec::unixify($fullpath) if $^O eq 'VMS';
74 push @ARGV, $fullpath if $f =~ /\.t$/;
82 foreach (split(/\s+/,$args)) {
83 # In VMS protect with doublequotes because otherwise
84 # DCL will lowercase -- unless already doublequoted.
85 $_ = q(").$_.q(") if ($^O eq 'VMS') && !/^\"/ && length($_) > 0;
86 $argstring .= ' ' . $_;
92 foreach my $dir (qw(base comp cmd run io op uni)) {
95 _find_tests("lib") unless $core;
96 my $mani = File::Spec->catfile($updir, "MANIFEST");
97 if (open(MANI, $mani)) {
98 while (<MANI>) { # similar code in t/harness
99 if (m!^(ext/\S+/?([^/]+\.t|test\.pl)|lib/\S+?(\.t|test\.pl))\s!) {
101 if (!$core || $t =~ m!^lib/[a-z]!)
103 $path = File::Spec->catfile($updir, $t);
111 warn "$0: cannot open $mani: $!\n";
113 _find_tests('pod') unless $core;
114 _find_tests('x2p') unless $core;
115 _find_tests('japh') unless $core;
118 # Tests known to cause infinite loops for the perlcc tests.
119 # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
123 _testprogs('deparse', '', @ARGV);
125 elsif( $compile || $byte_compile ) {
126 _testprogs('compile', '', @ARGV) if $compile;
127 _testprogs('compile', '-B', @ARGV) if $byte_compile;
130 _testprogs('compile', '', @ARGV) if -e "../testcompile";
131 _testprogs('perl', '', @ARGV);
139 print <<'EOT' if ($type eq 'compile');
140 ------------------------------------------------------------------------------
142 ------------------------------------------------------------------------------
145 print <<'EOT' if ($type eq 'deparse');
146 ------------------------------------------------------------------------------
148 ------------------------------------------------------------------------------
151 $ENV{PERLCC_TIMEOUT} = 120
152 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
160 foreach my $t (@tests) {
161 unless (exists $name{$t}) {
162 my $tname = File::Spec->catfile('t',$t);
163 $tname = VMS::Filespec::unixify($tname) if $^O eq 'VMS';
168 foreach (@name{@tests}) {
171 $maxlen = $len if $len > $maxlen;
173 # + 3 : we want three dots between the test name and the "ok"
174 $dotdotdot = $maxlen + 3 ;
175 while ($test = shift @tests) {
177 if ( $infinite{$test} && $type eq 'compile' ) {
178 print STDERR "$test creates infinite loop! Skipping.\n";
184 if ($type eq 'deparse') {
185 if ($test eq "comp/redef.t") {
186 # Redefinition happens at compile time
189 elsif ($test eq "lib/switch.t") {
190 # B::Deparse doesn't support source filtering
194 $te = $name{$test} . '.' x ($dotdotdot - length($name{$test}));
196 if ($^O ne 'VMS') { # defer printing on VMS due to piping bug
201 $test = $OVER{$test} if exists $OVER{$test};
203 open(SCRIPT,"<$test") or die "Can't run $test.\n";
205 close(SCRIPT) unless ($type eq 'deparse');
206 if (/#!.*\bperl.*-\w*([tT])/) {
213 my $test_executable; # for 'compile' tests
215 if ($type eq 'deparse') {
216 # Look for #line directives which change the filename
218 $file_opts .= ",-f$3$4"
219 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
224 my $utf = $with_utf ? '-I../lib -Mutf8' : '';
225 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
226 if ($type eq 'deparse') {
228 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,".
229 "-l$deparse_opts$file_opts ".
231 "&& ./perl $testswitch $switch -I../lib $test.dp |";
232 open(RESULTS, $deparse)
233 or print "can't deparse '$deparse': $!.\n";
235 elsif ($type eq 'perl') {
236 my $perl = $ENV{PERL} || './perl';
237 my $redir = ($^O eq 'VMS' ? '2>&1' : '');
238 my $run = "$perl" . _quote_args("$testswitch $switch $utf") . " $test $redir|";
239 open(RESULTS,$run) or print "can't run '$run': $!.\n";
243 my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
244 # -O9 for good measure, -fcog is broken ATM
245 "$switch -Wb=-O9,-fno-cog -L .. " .
246 "-I \".. ../lib/CORE\" $args $utf $test -o ";
248 if( $^O eq 'MSWin32' ) {
249 $test_executable = "$test.exe";
250 # hopefully unused name...
251 open HACK, "> xweghyz.pl";
255 open HACK, '.\\perl $pl2c $test_executable |';
256 # cl.exe prints the name of the .c file on stdout (\%^\$^#)
257 while(<HACK>) {m/^\\w+\\.[cC]\$/ && next;print}
258 open HACK, '$test_executable |';
259 while(<HACK>) {print}
262 $compile = 'xweghyz.pl |';
265 $test_executable = "$test.plc";
266 $compile = "./perl $pl2c $test_executable && $test_executable |";
268 unlink $test_executable if -f $test_executable;
269 open(RESULTS, $compile)
270 or print "can't compile '$compile': $!.\n";
276 next if /^\s*$/; # skip blank lines
281 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
283 %todo = map { $_ => 1 } split / /, $3 if $3;
290 if (/^(not )?ok (\d+)[^#]*(\s*#.*)?/ &&
293 my($not, $num, $extra) = ($1, $2, $3);
294 my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
295 $istodo = 1 if $todo{$num};
297 if( $not && !$istodo ) {
306 elsif (/^Bail out!\s*(.*)/i) { # magic words
307 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
316 if ($type eq 'deparse') {
319 if ($ENV{PERL_3LOG}) {
324 rename("perl.3log", "perl.3log.$tpp") ||
325 die "rename: perl3.log to perl.3log.$tpp: $!\n";
328 # test if the compiler compiled something
329 if( $type eq 'compile' && !-e "$test_executable" ) {
331 print "Test did not compile\n";
333 if ($ok && $next == $max ) {
339 print "${te}skipping test on this platform\n";
345 print "${te}FAILED at test $next\n";
349 die "Failed a basic test--cannot continue.\n";
356 print "All tests successful.\n";
357 # XXX add mention of 'perlbug -ok' ?
360 die "FAILED--no tests were run for some reason.\n";
364 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
366 warn "Failed 1 test script out of $files, $pct% okay.\n";
369 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
372 ### Since not all tests were successful, you may want to run some of
373 ### them individually and examine any diagnostic messages they produce.
374 ### See the INSTALL document's section on "make test".
376 warn <<'SHRDLU_2' if $good / $total > 0.8;
377 ### You have a good chance to get more information by running
379 ### in the 't' directory since most (>=80%) of the tests succeeded.
381 if (eval {require Config; import Config; 1}) {
382 if ($Config{usedl} && (my $p = $Config{ldlibpthname})) {
384 ### You may have to set your dynamic library search path,
385 ### $p, to point to the build directory:
387 if (exists $ENV{$p} && $ENV{$p} ne '') {
389 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
390 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
391 ### export $p=`pwd`:\$$p; cd t; ./perl harness
395 ### setenv $p `pwd`; cd t; ./perl harness
396 ### $p=`pwd`; export $p; cd t; ./perl harness
397 ### export $p=`pwd`; cd t; ./perl harness
401 ### for csh-style shells, like tcsh; or for traditional/modern
402 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
407 ($user,$sys,$cuser,$csys) = times;
408 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
409 $user,$sys,$cuser,$csys,$files,$totmax);