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.
14 foreach my $idx (0..$#ARGV) {
15 next unless $ARGV[$idx] =~ /^-(\S+)$/;
16 $core = 1 if $1 eq 'core';
17 $verbose = 1 if $1 eq 'v';
18 $with_utf= 1 if $1 eq 'utf8';
19 $byte_compile = 1 if $1 eq 'bytecompile';
20 $compile = 1 if $1 eq 'compile';
21 if ($1 =~ /^deparse(,.+)?$/) {
25 splice(@ARGV, $idx, 1);
29 chdir 't' if -f 't/TEST';
31 die "You need to run \"make test\" first to set things up.\n"
32 unless -e 'perl' or -e 'perl.exe';
34 if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
35 unless (-x 'perl.third') {
36 unless (-x '../perl.third') {
37 die "You need to run \"make perl.third first.\n";
40 print "Symlinking ../perl.third as perl.third...\n";
41 die "Failed to symlink: $!\n"
42 unless symlink("../perl.third", "perl.third");
43 die "Symlinked but no executable perl.third: $!\n"
44 unless -x 'perl.third';
49 # check leakage for embedders
50 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
52 $ENV{EMXSHELL} = 'sh'; # For OS/2
54 # Roll your own File::Find!
57 my $curdir = File::Spec->curdir;
58 my $updir = File::Spec->updir;
62 opendir DIR, $dir || die "Trouble opening $dir: $!";
63 foreach my $f (sort { $a cmp $b } readdir DIR) {
64 next if $f eq $curdir or $f eq $updir;
66 my $fullpath = File::Spec->catdir($dir, $f);
68 _find_tests($fullpath) if -d $fullpath;
69 push @ARGV, $fullpath if $f =~ /\.t$/;
74 foreach my $dir (qw(base comp cmd run io op)) {
77 _find_tests("lib") unless $core;
78 my $mani = File::Spec->catdir($updir, "MANIFEST");
79 if (open(MANI, $mani)) {
80 while (<MANI>) { # similar code in t/harness
81 if (m!^(ext/\S+/([^/]+\.t|test\.pl)|lib/\S+?(\.t|test\.pl))\s!) {
83 if (!$core || $t =~ m!^lib/[a-z]!)
85 $path = File::Spec->catdir($updir, $t);
92 warn "$0: cannot open $mani: $!\n";
97 # Tests known to cause infinite loops for the perlcc tests.
98 # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
102 _testprogs('deparse', '', @ARGV);
104 elsif( $compile || $byte_compile ) {
105 _testprogs('compile', '', @ARGV) if $compile;
106 _testprogs('compile', '-B', @ARGV) if $byte_compile;
109 _testprogs('compile', '', @ARGV) if -e "../testcompile";
110 _testprogs('perl', '', @ARGV);
118 print <<'EOT' if ($type eq 'compile');
119 ------------------------------------------------------------------------------
121 ------------------------------------------------------------------------------
124 print <<'EOT' if ($type eq 'deparse');
125 ------------------------------------------------------------------------------
127 ------------------------------------------------------------------------------
130 $ENV{PERLCC_TIMEOUT} = 120
131 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
140 $name{$_} = File::Spec->catdir('t',$_) unless exists $name{$_};
143 foreach (@name{@tests}) {
146 $maxlen = $len if $len > $maxlen;
148 # + 3 : we want three dots between the test name and the "ok"
149 $dotdotdot = $maxlen + 3 ;
150 while ($test = shift @tests) {
152 if ( $infinite{$test} && $type eq 'compile' ) {
153 print STDERR "$test creates infinite loop! Skipping.\n";
159 if ($type eq 'deparse') {
160 if ($test eq "comp/redef.t") {
161 # Redefinition happens at compile time
164 elsif ($test eq "lib/switch.t") {
165 # B::Deparse doesn't support source filtering
170 print "$te" . '.' x ($dotdotdot - length($te));
172 $test = $OVER{$test} if exists $OVER{$test};
174 open(SCRIPT,"<$test") or die "Can't run $test.\n";
176 close(SCRIPT) unless ($type eq 'deparse');
177 if (/#!.*\bperl.*-\w*([tT])/) {
185 if ($type eq 'deparse') {
186 # Look for #line directives which change the filename
188 $file_opts .= ",-f$3$4"
189 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
194 my $utf = $with_utf ? '-I../lib -Mutf8' : '';
195 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
196 if ($type eq 'deparse') {
198 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,".
199 "-l$deparse_opts$file_opts ".
201 "&& ./perl $testswitch $switch -I../lib $test.dp |";
202 open(RESULTS, $deparse)
203 or print "can't deparse '$deparse': $!.\n";
205 elsif ($type eq 'perl') {
206 my $perl = $ENV{PERL} || './perl';
207 my $run = "$perl $testswitch $switch $utf $test |";
208 open(RESULTS,$run) or print "can't run '$run': $!.\n";
212 "./perl $testswitch -I../lib ../utils/perlcc -I .. $args -o ".
213 "$test.plc $utf $test ".
215 open(RESULTS, $compile)
216 or print "can't compile '$compile': $!.\n";
227 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
229 %todo = map { $_ => 1 } split / /, $3 if $3;
236 if (/^(not )?ok (\d+)[^#]*(\s*#.*)?/ &&
239 my($not, $num, $extra) = ($1, $2, $3);
240 my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
241 $istodo = 1 if $todo{$num};
243 if( $not && !$istodo ) {
252 elsif (/^Bail out!\s*(.*)/i) { # magic words
253 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
262 if ($type eq 'deparse') {
265 if ($ENV{PERL_3LOG}) {
270 rename("perl.3log", "perl.3log.$tpp") ||
271 die "rename: perl3.log to perl.3log.$tpp: $!\n";
274 if ($ok && $next == $max) {
280 print "skipping test on this platform\n";
286 print "FAILED at test $next\n";
290 die "Failed a basic test--cannot continue.\n";
297 print "All tests successful.\n";
298 # XXX add mention of 'perlbug -ok' ?
301 die "FAILED--no tests were run for some reason.\n";
305 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
307 warn "Failed 1 test script out of $files, $pct% okay.\n";
310 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
313 ### Since not all tests were successful, you may want to run some of
314 ### them individually and examine any diagnostic messages they produce.
315 ### See the INSTALL document's section on "make test".
317 warn <<'SHRDLU_2' if $good / $total > 0.8;
318 ### You have a good chance to get more information by running
320 ### in the 't' directory since most (>=80%) of the tests succeeded.
322 if (eval {require Config; import Config; 1}) {
323 if ($Config{usedl} && (my $p = $Config{ldlibpthname})) {
325 ### You may have to set your dynamic library search path,
326 ### $p, to point to the build directory:
328 if (exists $ENV{$p} && $ENV{$p} ne '') {
330 ### setenv $p `pwd`:\$$p; cd t; ./perl harness
331 ### $p=`pwd`:\$$p; export $p; cd t; ./perl harness
332 ### export $p=`pwd`:\$$p; cd t; ./perl harness
336 ### setenv $p `pwd`; cd t; ./perl harness
337 ### $p=`pwd`; export $p; cd t; ./perl harness
338 ### export $p=`pwd`; cd t; ./perl harness
342 ### for csh-style shells, like tcsh; or for traditional/modern
343 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
348 ($user,$sys,$cuser,$csys) = times;
349 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
350 $user,$sys,$cuser,$csys,$files,$totmax);