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 if ($1 =~ /^deparse(,.+)?$/) {
23 splice(@ARGV, $idx, 1);
27 chdir 't' if -f 't/TEST';
29 die "You need to run \"make test\" first to set things up.\n"
30 unless -e 'perl' or -e 'perl.exe';
32 if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
33 unless (-x 'perl.third') {
34 unless (-x '../perl.third') {
35 die "You need to run \"make perl.third first.\n";
38 print "Symlinking ../perl.third as perl.third...\n";
39 die "Failed to symlink: $!\n"
40 unless symlink("../perl.third", "perl.third");
41 die "Symlinked but no executable perl.third: $!\n"
42 unless -x 'perl.third';
47 # check leakage for embedders
48 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
50 $ENV{EMXSHELL} = 'sh'; # For OS/2
52 # Roll your own File::Find!
55 my $curdir = File::Spec->curdir;
56 my $updir = File::Spec->updir;
60 opendir DIR, $dir || die "Trouble opening $dir: $!";
61 foreach my $f (sort { $a cmp $b } readdir DIR) {
62 next if $f eq $curdir or $f eq $updir;
64 my $fullpath = File::Spec->catdir($dir, $f);
66 _find_tests($fullpath) if -d $fullpath;
67 push @ARGV, $fullpath if $f =~ /\.t$/;
72 foreach my $dir (qw(base comp cmd run io op)) {
75 _find_tests("lib") unless $core;
76 my $mani = File::Spec->catdir($updir, "MANIFEST");
77 if (open(MANI, $mani)) {
78 while (<MANI>) { # similar code in t/harness
79 if (m!^(ext/\S+/([^/]+\.t|test\.pl)|lib/\S+?(\.t|test\.pl))\s!) {
81 if (!$core || $t =~ m!^lib/[a-z]!)
83 $path = File::Spec->catdir($updir, $t);
90 warn "$0: cannot open $mani: $!\n";
95 # Tests known to cause infinite loops for the perlcc tests.
96 # %infinite = ( 'comp/require.t', 1, 'op/bop.t', 1, 'lib/hostname.t', 1 );
100 _testprogs('deparse', @ARGV);
102 _testprogs('perl', @ARGV);
103 _testprogs('compile', @ARGV) if (-e "../testcompile");
110 print <<'EOT' if ($type eq 'compile');
111 ------------------------------------------------------------------------------
113 ------------------------------------------------------------------------------
116 print <<'EOT' if ($type eq 'deparse');
117 ------------------------------------------------------------------------------
119 ------------------------------------------------------------------------------
122 $ENV{PERLCC_TIMEOUT} = 120
123 if ($type eq 'compile' && !$ENV{PERLCC_TIMEOUT});
132 $name{$_} = File::Spec->catdir('t',$_) unless exists $name{$_};
135 foreach (@name{@tests}) {
138 $maxlen = $len if $len > $maxlen;
140 # + 3 : we want three dots between the test name and the "ok"
141 $dotdotdot = $maxlen + 3 ;
142 while ($test = shift @tests) {
144 if ( $infinite{$test} && $type eq 'compile' ) {
145 print STDERR "$test creates infinite loop! Skipping.\n";
151 if ($type eq 'deparse') {
152 if ($test eq "comp/redef.t") {
153 # Redefinition happens at compile time
156 elsif ($test eq "lib/switch.t") {
157 # B::Deparse doesn't support source filtering
162 print "$te" . '.' x ($dotdotdot - length($te));
164 $test = $OVER{$test} if exists $OVER{$test};
166 open(SCRIPT,"<$test") or die "Can't run $test.\n";
168 close(SCRIPT) unless ($type eq 'deparse');
169 if (/#!.*perl(.*)$/) {
172 # Must protect uppercase switches with "" on command line
173 $switch =~ s/-([A-Z]\S*)/"-$1"/g;
181 if ($type eq 'deparse') {
182 # Look for #line directives which change the filename
184 $file_opts .= ",-f$3$4"
185 if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
190 my $utf = $with_utf ? '-I../lib -Mutf8' : '';
191 my $testswitch = '-I. -MTestInit'; # -T will strict . from @INC
192 if ($type eq 'deparse') {
194 "./perl $testswitch $switch -I../lib -MO=-qq,Deparse,".
195 "-l$deparse_opts$file_opts ".
197 "&& ./perl $testswitch $switch -I../lib $test.dp |";
198 open(RESULTS, $deparse)
199 or print "can't deparse '$deparse': $!.\n";
201 elsif ($type eq 'perl') {
202 my $perl = $ENV{PERL} || './perl';
203 my $run = "$perl $testswitch $switch $utf $test |";
204 open(RESULTS,$run) or print "can't run '$run': $!.\n";
208 "./perl $testswitch -I../lib ../utils/perlcc -o ".
209 "$test.plc $utf $test ".
211 open(RESULTS, $compile)
212 or print "can't compile '$compile': $!.\n";
223 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
225 %todo = map { $_ => 1 } split / /, $3 if $3;
232 if (/^(not )?ok (\d+)[^#]*(\s*#.*)?/ &&
235 my($not, $num, $extra) = ($1, $2, $3);
236 my($istodo) = $extra =~ /^\s*#\s*TODO/ if $extra;
237 $istodo = 1 if $todo{$num};
239 if( $not && !$istodo ) {
248 elsif (/^Bail out!\s*(.*)/i) { # magic words
249 die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
258 if ($type eq 'deparse') {
261 if ($ENV{PERL_3LOG}) {
266 rename("perl.3log", "perl.3log.$tpp") ||
267 die "rename: perl3.log to perl.3log.$tpp: $!\n";
270 if ($ok && $next == $max) {
276 print "skipping test on this platform\n";
282 print "FAILED at test $next\n";
286 die "Failed a basic test--cannot continue.\n";
293 print "All tests successful.\n";
294 # XXX add mention of 'perlbug -ok' ?
297 die "FAILED--no tests were run for some reason.\n";
301 $pct = $files ? sprintf("%.2f", ($files - $bad) / $files * 100) : "0.00";
303 warn "Failed 1 test script out of $files, $pct% okay.\n";
306 warn "Failed $bad test scripts out of $files, $pct% okay.\n";
309 ### Since not all tests were successful, you may want to run some of
310 ### them individually and examine any diagnostic messages they produce.
311 ### See the INSTALL document's section on "make test".
313 warn <<'SHRDLU' if $good / $total > 0.8;
314 ### You have a good chance to get more information by running
316 ### in the 't' directory since most (>=80%) of the tests succeeded.
319 if ($Config{ldlibpthname}) {
321 ### You may have to set your dynamic library search path,
322 ### $Config{ldlibpthname}, to point to the build directory
323 ### before running the harness-- depending on your shell style:
324 ### setenv $Config{ldlibpthname} `pwd`:$Config{ldlibpthname}; cd t; ./perl harness
325 ### $Config{ldlibpthname}=`pwd`:$Config{ldlibpthname}; export $Config{ldlibpthname}; cd t; ./perl harness
326 ### export $Config{ldlibpthname}=`pwd`:$Config{ldlibpthname}; cd t; ./perl harness
327 ### for csh-style shells, like tcsh; or for traditional/modern
328 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
332 ($user,$sys,$cuser,$csys) = times;
333 print sprintf("u=%g s=%g cu=%g cs=%g scripts=%d tests=%d\n",
334 $user,$sys,$cuser,$csys,$files,$totmax);