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 # Cheesy version of Getopt::Std. Maybe we should replace it with that.
15 foreach my $idx (0..$#ARGV) {
16 push( @argv, $ARGV[$idx] ), next unless $ARGV[$idx] =~ /^-(\S+)$/;
17 $core = 1 if $1 eq 'core';
18 $verbose = 1 if $1 eq 'v';
19 $with_utf= 1 if $1 eq 'utf8';
20 $byte_compile = 1 if $1 eq 'bytecompile';
21 $compile = 1 if $1 eq 'compile';
22 if ($1 =~ /^deparse(,.+)?$/) {
30 chdir 't' if -f 't/TEST';
32 die "You need to run \"make test\" first to set things up.\n"
33 unless -e 'perl' or -e 'perl.exe' or -e 'perl.pm';
35 if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
36 unless (-x 'perl.third') {
37 unless (-x '../perl.third') {
38 die "You need to run \"make perl.third first.\n";
41 print "Symlinking ../perl.third as perl.third...\n";
42 die "Failed to symlink: $!\n"
43 unless symlink("../perl.third", "perl.third");
44 die "Symlinked but no executable perl.third: $!\n"
45 unless -x 'perl.third';
50 # check leakage for embedders
51 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
53 $ENV{EMXSHELL} = 'sh'; # For OS/2
55 # Roll your own File::Find!
58 my $curdir = File::Spec->curdir;
59 my $updir = File::Spec->updir;
63 opendir DIR, $dir || die "Trouble opening $dir: $!";
64 foreach my $f (sort { $a cmp $b } readdir DIR) {
65 next if $f eq $curdir or $f eq $updir;
67 my $fullpath = File::Spec->catdir($dir, $f);
69 _find_tests($fullpath) if -d $fullpath;
70 push @ARGV, $fullpath if $f =~ /\.t$/;
75 foreach my $dir (qw(base comp cmd run io op uni)) {
78 _find_tests("lib") unless $core;
79 my $mani = File::Spec->catdir($updir, "MANIFEST");
80 if (open(MANI, $mani)) {
81 while (<MANI>) { # similar code in t/harness
82 if (m!^(ext/\S+/?([^/]+\.t|test\.pl)|lib/\S+?(\.t|test\.pl))\s!) {
84 if (!$core || $t =~ m!^lib/[a-z]!)
86 $path = File::Spec->catdir($updir, $t);
93 warn "$0: cannot open $mani: $!\n";
95 _find_tests('pod') unless $core;
96 _find_tests('x2p') unless $core;
97 _find_tests('japh') unless $core;
100 # Tests known to cause infinite loops for the perlcc tests.
101 # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
105 _testprogs('deparse', '', @ARGV);
107 elsif( $compile || $byte_compile ) {
108 _testprogs('compile', '', @ARGV) if $compile;
109 _testprogs('compile', '-B', @ARGV) if $byte_compile;
112 _testprogs('compile', '', @ARGV) if -e "../testcompile";
113 _testprogs('perl', '', @ARGV);
121 print <<'EOT' if ($type eq 'compile');
122 ------------------------------------------------------------------------------
124 ------------------------------------------------------------------------------
127 print <<'EOT' if ($type eq 'deparse');
128 ------------------------------------------------------------------------------
130 ------------------------------------------------------------------------------
133 $ENV{PERLCC_TIMEOUT} = 120
134 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
143 $name{$_} = File::Spec->catdir('t',$_) unless exists $name{$_};
146 foreach (@name{@tests}) {
149 $maxlen = $len if $len > $maxlen;
151 # + 3 : we want three dots between the test name and the "ok"
152 $dotdotdot = $maxlen + 3 ;
153 while ($test = shift @tests) {
155 if ( $infinite{$test} && $type eq 'compile' ) {
156 print STDERR "$test creates infinite loop! Skipping.\n";
162 if ($type eq 'deparse') {
163 if ($test eq "comp/redef.t") {
164 # Redefinition happens at compile time
167 elsif ($test eq "lib/switch.t") {
168 # B::Deparse doesn't support source filtering
173 print "$te" . '.' x ($dotdotdot - length($te));
175 $test = $OVER{$test} if exists $OVER{$test};
177 open(SCRIPT,"<$test") or die "Can't run $test.\n";
179 close(SCRIPT) unless ($type eq 'deparse');
180 if (/#!.*\bperl.*-\w*([tT])/) {
187 my $test_executable; # for 'compile' tests
189 if ($type eq 'deparse') {
190 # Look for #line directives which change the filename
192 $file_opts .= ",-f$3$4"
193 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
198 my $utf = $with_utf ? '-I../lib -Mutf8' : '';
199 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
200 if ($type eq 'deparse') {
202 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,".
203 "-l$deparse_opts$file_opts ".
205 "&& ./perl $testswitch $switch -I../lib $test.dp |";
206 open(RESULTS, $deparse)
207 or print "can't deparse '$deparse': $!.\n";
209 elsif ($type eq 'perl') {
210 my $perl = $ENV{PERL} || './perl';
211 my $run = "$perl $testswitch $switch $utf $test |";
212 open(RESULTS,$run) or print "can't run '$run': $!.\n";
216 my $pl2c = "$testswitch -I../lib ../utils/perlcc --testsuite " .
217 # -O9 for good measure, -fcog is broken ATM
218 "$switch -Wb=-O9,-fno-cog -L .. " .
219 "-I \".. ../lib/CORE\" $args $utf $test -o ";
221 if( $^O eq 'MSWin32' ) {
222 $test_executable = "$test.exe";
223 # hopefully unused name...
224 open HACK, "> xweghyz.pl";
228 open HACK, '.\\perl $pl2c $test_executable |';
229 # cl.exe prints the name of the .c file on stdout (\%^\$^#)
230 while(<HACK>) {m/^\w+\.[cC]\$/ && next;print}
231 open HACK, '$test_executable |';
232 while(<HACK>) {print}
235 $compile = 'xweghyz.pl |';
238 $test_executable = "$test.plc";
239 $compile = "./perl $pl2c $test_executable && $test_executable |";
241 unlink $test_executable if -f $test_executable;
242 open(RESULTS, $compile)
243 or print "can't compile '$compile': $!.\n";
253 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
255 %todo = map { $_ => 1 } split / /, $3 if $3;
262 if (/^(not )?ok (\d+)[^#]*(\s*#.*)?/ &&
265 my($not, $num, $extra) = ($1, $2, $3);
266 my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
267 $istodo = 1 if $todo{$num};
269 if( $not && !$istodo ) {
278 elsif (/^Bail out!\s*(.*)/i) { # magic words
279 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
288 if ($type eq 'deparse') {
291 if ($ENV{PERL_3LOG}) {
296 rename("perl.3log", "perl.3log.$tpp") ||
297 die "rename: perl3.log to perl.3log.$tpp: $!\n";
300 # test if the compiler compiled something
301 if( $type eq 'compile' && !-e "$test_executable" ) {
303 print "Test did not compile\n";
305 if ($ok && $next == $max ) {
311 print "skipping test on this platform\n";
317 print "FAILED at test $next\n";
321 die "Failed a basic test--cannot continue.\n";
328 print "All tests successful.\n";
329 # XXX add mention of 'perlbug -ok' ?
332 die "FAILED--no tests were run for some reason.\n";
336 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
338 warn "Failed 1 test script out of $files, $pct% okay.\n";
341 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
344 ### Since not all tests were successful, you may want to run some of
345 ### them individually and examine any diagnostic messages they produce.
346 ### See the INSTALL document's section on "make test".
348 warn <<'SHRDLU_2' if $good / $total > 0.8;
349 ### You have a good chance to get more information by running
351 ### in the 't' directory since most (>=80%) of the tests succeeded.
353 if (eval {require Config; import Config; 1}) {
354 if ($Config{usedl} && (my $p = $Config{ldlibpthname})) {
356 ### You may have to set your dynamic library search path,
357 ### $p, to point to the build directory:
359 if (exists $ENV{$p} && $ENV{$p} ne '') {
361 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
362 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
363 ### export $p=`pwd`:\$$p; cd t; ./perl harness
367 ### setenv $p `pwd`; cd t; ./perl harness
368 ### $p=`pwd`; export $p; cd t; ./perl harness
369 ### export $p=`pwd`; cd t; ./perl harness
373 ### for csh-style shells, like tcsh; or for traditional/modern
374 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
379 ($user,$sys,$cuser,$csys) = times;
380 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
381 $user,$sys,$cuser,$csys,$files,$totmax);