This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Excluding tests in sub-dirs
[perl5.git] / t / TEST
1 #!./perl
2
3 # This is written in a peculiar style, since we're trying to avoid
4 # most of the constructs we'll be testing for.  (This comment is
5 # probably obsolete on the avoidance side, though still currrent
6 # on the peculiarity side.)
7
8 # t/TEST and t/harness need to share code. The logical way to do this would be
9 # to have the common code in a file both require or use. However, t/TEST needs
10 # to still work, to generate test results, even if require isn't working, so
11 # we cannot do that. t/harness has no such restriction, so it is quite
12 # acceptable to have it require t/TEST.
13
14 # In which case, we need to stop t/TEST actually running tests, as all
15 # t/harness needs are its subroutines.
16
17
18 # directories with special sets of test switches
19 my %dir_to_switch =
20     (base => '',
21      comp => '',
22      run => '',
23      '../ext/File-Glob/t' => '-I.. -MTestInit', # FIXME - tests assume t/
24      );
25
26 # "not absolute" is the the default, as it saves some fakery within TestInit
27 # which can peturb tests, and takes CPU. Working with the upstream author of
28 # any of these, to figure out how to remove them from this list, considered
29 # "a good thing".
30 my %abs = (
31            '../cpan/Archive-Extract' => 1,
32            '../cpan/Archive-Tar' => 1,
33            '../cpan/AutoLoader' => 1,
34            '../cpan/CPAN' => 1,
35            '../cpan/Class-ISA' => 1,
36            '../cpan/Devel-PPPort' => 1,
37            '../cpan/Encode' => 1,
38            '../cpan/ExtUtils-Command' => 1,
39            '../cpan/ExtUtils-Constant' => 1,
40            '../cpan/ExtUtils-MakeMaker' => 1,
41            '../cpan/ExtUtils-Manifest' => 1,
42            '../cpan/File-Fetch' => 1,
43            '../cpan/IPC-Cmd' => 1,
44            '../cpan/IPC-SysV' => 1,
45            '../cpan/Locale-Codes' => 1,
46            '../cpan/Log-Message' => 1,
47            '../cpan/Math-Complex' => 1,
48            '../cpan/Module-Build' => 1,
49            '../cpan/Module-Load' => 1,
50            '../cpan/Module-Load-Conditional' => 1,
51            '../cpan/Object-Accessor' => 1,
52            '../cpan/Package-Constants' => 1,
53            '../cpan/Parse-CPAN-Meta' => 1,
54            '../cpan/Pod-Simple' => 1,
55            '../cpan/Term-UI' => 1,
56            '../cpan/Test-Simple' => 1,
57            '../cpan/Tie-File' => 1,
58            '../cpan/podlators' => 1,
59            '../dist/Cwd' => 1,
60            '../dist/ExtUtils-Install' => 1,
61            '../dist/ExtUtils-ParseXS' => 1,
62           );
63
64 my %temp_no_core =
65     ('../cpan/B-Debug' => 1,
66      '../cpan/Compress-Raw-Bzip2' => 1,
67      '../cpan/Compress-Raw-Zlib' => 1,
68      '../cpan/Devel-PPPort' => 1,
69      '../cpan/Getopt-Long' => 1,
70      '../cpan/IO-Compress' => 1,
71      '../cpan/MIME-Base64' => 1,
72      '../cpan/parent' => 1,
73      '../cpan/Parse-CPAN-Meta' => 1,
74      '../cpan/Pod-Simple' => 1,
75      '../cpan/podlators' => 1,
76      '../cpan/Test-Simple' => 1,
77      '../cpan/Tie-RefHash' => 1,
78      '../cpan/Time-HiRes' => 1,
79      '../cpan/Unicode-Collate' => 1,
80      '../cpan/Unicode-Normalize' => 1,
81     );
82
83 # delete env vars that may influence the results
84 # but allow override via *_TEST env var if wanted
85 # (e.g. PERL5OPT_TEST=-d:NYTProf)
86 for my $envname (qw(PERL5LIB PERLLIB PERL5OPT)) {
87     my $override = $ENV{"${envname}_TEST"};
88     if (defined $override) {
89         warn "$0: $envname=$override\n";
90         $ENV{$envname} = $override;
91     }
92     else {
93         delete $ENV{$envname};
94     }
95 }
96
97 if ($::do_nothing) {
98     return 1;
99 }
100
101 # Location to put the Valgrind log.
102 our $Valgrind_Log;
103
104 $| = 1;
105
106 # for testing TEST only
107 #BEGIN { require '../lib/strict.pm'; "strict"->import() };
108 #BEGIN { require '../lib/warnings.pm'; "warnings"->import() };
109
110 # remove empty elements due to insertion of empty symbols via "''p1'" syntax
111 @ARGV = grep($_,@ARGV) if $^O eq 'VMS';
112 our $show_elapsed_time = $ENV{HARNESS_TIMER} || 0;
113
114 # Cheesy version of Getopt::Std.  We can't replace it with that, because we
115 # can't rely on require working.
116 {
117     my @argv = ();
118     foreach my $idx (0..$#ARGV) {
119         push( @argv, $ARGV[$idx] ), next unless $ARGV[$idx] =~ /^-(\S+)$/;
120         $::benchmark = 1 if $1 eq 'benchmark';
121         $::core    = 1 if $1 eq 'core';
122         $::verbose = 1 if $1 eq 'v';
123         $::torture = 1 if $1 eq 'torture';
124         $::with_utf8 = 1 if $1 eq 'utf8';
125         $::with_utf16 = 1 if $1 eq 'utf16';
126         $::taintwarn = 1 if $1 eq 'taintwarn';
127         $ENV{PERL_CORE_MINITEST} = 1 if $1 eq 'minitest';
128         if ($1 =~ /^deparse(,.+)?$/) {
129             $::deparse = 1;
130             $::deparse_opts = $1;
131         }
132     }
133     @ARGV = @argv;
134 }
135
136 chdir 't' if -f 't/TEST';
137 if (-f 'TEST' && -f 'harness' && -d '../lib') {
138     @INC = '../lib';
139 }
140
141 die "You need to run \"make test\" first to set things up.\n"
142   unless -e 'perl' or -e 'perl.exe' or -e 'perl.pm';
143
144 if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
145     unless (-x 'perl.third') {
146         unless (-x '../perl.third') {
147             die "You need to run \"make perl.third first.\n";
148         }
149         else {
150             print "Symlinking ../perl.third as perl.third...\n";
151             die "Failed to symlink: $!\n"
152                 unless symlink("../perl.third", "perl.third");
153             die "Symlinked but no executable perl.third: $!\n"
154                 unless -x 'perl.third';
155         }
156     }
157 }
158
159 # check leakage for embedders
160 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
161
162 $ENV{EMXSHELL} = 'sh';        # For OS/2
163
164 if ($show_elapsed_time) { require Time::HiRes }
165
166 my %skip = (
167             '.' => 1,
168             '..' => 1,
169             'CVS' => 1,
170             'RCS' => 1,
171             'SCCS' => 1,
172             '.svn' => 1,
173            );
174
175 # Roll your own File::Find!
176 sub _find_tests {
177     my($dir) = @_;
178     opendir DIR, $dir or die "Trouble opening $dir: $!";
179     foreach my $f (sort { $a cmp $b } readdir DIR) {
180         next if $skip{$f};
181
182         my $fullpath = "$dir/$f";
183
184         if (-d $fullpath) {
185             _find_tests($fullpath);
186         } elsif ($f =~ /\.t$/) {
187             push @ARGV, $fullpath;
188         }
189     }
190 }
191
192
193 # Scan the text of the test program to find switches and special options
194 # we might need to apply.
195 sub _scan_test {
196     my($test, $type) = @_;
197
198     open(my $script, "<", $test) or die "Can't read $test.\n";
199     my $first_line = <$script>;
200
201     $first_line =~ tr/\0//d if $::with_utf16;
202
203     my $switch = "";
204     if ($first_line =~ /#!.*\bperl.*\s-\w*([tT])/) {
205         $switch = "-$1";
206     } else {
207         if ($::taintwarn) {
208             # not all tests are expected to pass with this option
209             $switch = '-t';
210         } else {
211             $switch = '';
212         }
213     }
214
215     my $file_opts = "";
216     if ($type eq 'deparse') {
217         # Look for #line directives which change the filename
218         while (<$script>) {
219             $file_opts = $file_opts . ",-f$3$4"
220               if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
221         }
222     }
223
224     close $script;
225
226     my $perl = './perl';
227     my $lib  = '../lib';
228     my $run_dir;
229     my $return_dir;
230
231     $test =~ /^(.+)\/[^\/]+/;
232     my $dir = $1;
233     my $testswitch = $dir_to_switch{$dir};
234     if (!defined $testswitch) {
235         if ($test =~ s!^(\.\./(cpan|dist|ext)/[^/]+)/t!t!) {
236             $run_dir = $1;
237             $return_dir = '../../t';
238             $lib = '../../lib';
239             $perl = '../../t/perl';
240             $testswitch = "-I../.. -MTestInit=U2T";
241             if ($2 eq 'cpan' || $2 eq 'dist') {
242                 if($abs{$run_dir}) {
243                     $testswitch = $testswitch . ',A';
244                 }
245                 if ($temp_no_core{$run_dir}) {
246                     $testswitch = $testswitch . ',NC';
247                 }
248             }
249         } else {
250             $testswitch = '-I.. -MTestInit';  # -T will remove . from @INC
251         }
252     }
253
254     my $utf8 = ($::with_utf8 || $::with_utf16) ? "-I$lib -Mutf8" : '';
255
256     my %options = (
257         perl => $perl,
258         lib => $lib,
259         test => $test,
260         run_dir => $run_dir,
261         return_dir => $return_dir,
262         testswitch => $testswitch,
263         utf8 => $utf8,
264         file => $file_opts,
265         switch => $switch,
266     );
267
268     return \%options;
269 }
270
271 sub _cmd {
272     my($options, $type) = @_;
273
274     my $test = $options->{test};
275
276     my $cmd;
277     if ($type eq 'deparse') {
278         my $perl = "$options->{perl} $options->{testswitch}";
279         my $lib = $options->{lib};
280
281         $cmd = (
282           "$perl $options->{switch} -I$lib -MO=-qq,Deparse,-sv1.,".
283           "-l$::deparse_opts$options->{file} ".
284           "$test > $test.dp ".
285           "&& $perl $options->{switch} -I$lib $test.dp"
286         );
287     }
288     elsif ($type eq 'perl') {
289         my $perl = $options->{perl};
290         my $redir = $^O eq 'VMS' ? '2>&1' : '';
291
292         if ($ENV{PERL_VALGRIND}) {
293             my $perl_supp = $options->{return_dir} ? "$options->{return_dir}/perl.supp" : "perl.supp";
294             my $valgrind = $ENV{VALGRIND} // 'valgrind';
295             my $vg_opts = $ENV{VG_OPTS}
296               //  "--suppressions=$perl_supp --leak-check=yes "
297                 . "--leak-resolution=high --show-reachable=yes "
298                   . "--num-callers=50 --track-origins=yes";
299             $perl = "$valgrind --log-fd=3 $vg_opts $perl";
300             $redir = "3>$Valgrind_Log";
301             if ($options->{run_dir}) {
302                 $Valgrind_Log = "$options->{run_dir}/$Valgrind_Log";
303             }
304         }
305
306         my $args = "$options->{testswitch} $options->{switch} $options->{utf8}";
307         $cmd = $perl . _quote_args($args) . " $test $redir";
308     }
309
310     return $cmd;
311 }
312
313 sub _before_fork {
314     my ($options) = @_;
315
316     if ($options->{run_dir}) {
317         my $run_dir = $options->{run_dir};
318         chdir $run_dir or die "Can't chdir to '$run_dir': $!";
319     }
320
321     return;
322 }
323
324 sub _after_fork {
325     my ($options) = @_;
326
327     if ($options->{return_dir}) {
328         my $return_dir = $options->{return_dir};
329         chdir $return_dir
330            or die "Can't chdir from '$options->{run_dir}' to '$return_dir': $!";
331     }
332
333     return;
334 }
335
336 sub _run_test {
337     my ($test, $type) = @_;
338
339     my $options = _scan_test($test, $type);
340     # $test might have changed if we're in ext/Foo, so don't use it anymore
341     # from now on. Use $options->{test} instead.
342
343     _before_fork($options);
344
345     my $cmd = _cmd($options, $type);
346
347     open(my $results, "$cmd |") or print "can't run '$cmd': $!.\n";
348
349     _after_fork($options);
350
351     # Our environment may force us to use UTF-8, but we can't be sure that
352     # anything we're reading from will be generating (well formed) UTF-8
353     # This may not be the best way - possibly we should unset ${^OPEN} up
354     # top?
355     binmode $results;
356
357     return $results;
358 }
359
360 sub _quote_args {
361     my ($args) = @_;
362     my $argstring = '';
363
364     foreach (split(/\s+/,$args)) {
365        # In VMS protect with doublequotes because otherwise
366        # DCL will lowercase -- unless already doublequoted.
367        $_ = q(").$_.q(") if ($^O eq 'VMS') && !/^\"/ && length($_) > 0;
368        $argstring = $argstring . ' ' . $_;
369     }
370     return $argstring;
371 }
372
373 sub _populate_hash {
374     return unless defined $_[0];
375     return map {$_, 1} split /\s+/, $_[0];
376 }
377
378 sub _tests_from_manifest {
379     my ($extensions, $known_extensions) = @_;
380     my %skip;
381     my %extensions = _populate_hash($extensions);
382     my %known_extensions = _populate_hash($known_extensions);
383
384     foreach (keys %known_extensions) {
385         $skip{$_} = 1 unless $extensions{$_};
386     }
387
388     my @results;
389     my $mani = '../MANIFEST';
390     if (open(MANI, $mani)) {
391         while (<MANI>) {
392             if (m!^((?:cpan|dist|ext)/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
393                 my $t = $1;
394                 my $extension = $2;
395                 if (!$::core || $t =~ m!^lib/[a-z]!) {
396                     if (defined $extension) {
397                         $extension =~ s!/t(:?/\S+)*$!!;
398                         # XXX Do I want to warn that I'm skipping these?
399                         next if $skip{$extension};
400                         my $flat_extension = $extension;
401                         $flat_extension =~ s!-!/!g;
402                         next if $skip{$flat_extension}; # Foo/Bar may live in Foo-Bar
403                     }
404                     my $path = "../$t";
405                     push @results, $path;
406                     $::path_to_name{$path} = $t;
407                 }
408             }
409         }
410         close MANI;
411     } else {
412         warn "$0: cannot open $mani: $!\n";
413     }
414     return @results;
415 }
416
417 unless (@ARGV) {
418     # base first, as TEST bails out if that can't run
419     # then comp, to validate that require works
420     # then run, to validate that -M works
421     # then we know we can -MTestInit for everything else, making life simpler
422     foreach my $dir (qw(base comp run cmd io re op uni mro)) {
423         _find_tests($dir);
424     }
425     _find_tests("lib") unless $::core;
426     # Config.pm may be broken for make minitest. And this is only a refinement
427     # for skipping tests on non-default builds, so it is allowed to fail.
428     # What we want to to is make a list of extensions which we did not build.
429     my $configsh = '../config.sh';
430     my ($extensions, $known_extensions);
431     if (-f $configsh) {
432         open FH, $configsh or die "Can't open $configsh: $!";
433         while (<FH>) {
434             if (/^extensions=['"](.*)['"]$/) {
435                 $extensions = $1;
436             }
437             elsif (/^known_extensions=['"](.*)['"]$/) {
438                 $known_extensions = $1;
439             }
440         }
441         if (!defined $known_extensions) {
442             warn "No known_extensions line found in $configsh";
443         }
444         if (!defined $extensions) {
445             warn "No extensions line found in $configsh";
446         }
447     }
448     # The "complex" constructions of list return from a subroutine, and push of
449     # a list, might fail if perl is really hosed, but they aren't needed for
450     # make minitest, and the building of extensions will likely also fail if
451     # something is that badly wrong.
452     push @ARGV, _tests_from_manifest($extensions, $known_extensions);
453     unless ($::core) {
454         _find_tests('x2p');
455         _find_tests('porting');
456         _find_tests('japh') if $::torture;
457         _find_tests('t/benchmark') if $::benchmark or $ENV{PERL_BENCHMARK};
458     }
459 }
460
461 if ($::deparse) {
462     _testprogs('deparse', '',   @ARGV);
463 }
464 elsif ($::with_utf16) {
465     for my $e (0, 1) {
466         for my $b (0, 1) {
467             print STDERR "# ENDIAN $e BOM $b\n";
468             my @UARGV;
469             for my $a (@ARGV) {
470                 my $u = $a . "." . ($e ? "l" : "b") . "e" . ($b ? "b" : "");
471                 my $f = $e ? "v" : "n";
472                 push @UARGV, $u;
473                 unlink($u);
474                 if (open(A, $a)) {
475                     if (open(U, ">$u")) {
476                         print U pack("$f", 0xFEFF) if $b;
477                         while (<A>) {
478                             print U pack("$f*", unpack("C*", $_));
479                         }
480                         close(U);
481                     }
482                     close(A);
483                 }
484             }
485             _testprogs('perl', '', @UARGV);
486             unlink(@UARGV);
487         }
488     }
489 }
490 else {
491     _testprogs('perl',    '',   @ARGV);
492 }
493
494 sub _testprogs {
495     my ($type, $args, @tests) = @_;
496
497     print <<'EOT' if ($type eq 'deparse');
498 ------------------------------------------------------------------------------
499 TESTING DEPARSER
500 ------------------------------------------------------------------------------
501 EOT
502
503     $::bad_files = 0;
504
505     foreach my $t (@tests) {
506       unless (exists $::path_to_name{$t}) {
507         my $tname = "t/$t";
508         $::path_to_name{$t} = $tname;
509       }
510     }
511     my $maxlen = 0;
512     foreach (@::path_to_name{@tests}) {
513         s/\.\w+\z/./;
514         my $len = length ;
515         $maxlen = $len if $len > $maxlen;
516     }
517     # + 3 : we want three dots between the test name and the "ok"
518     my $dotdotdot = $maxlen + 3 ;
519     my $valgrind = 0;
520     my $total_files = @tests;
521     my $good_files = 0;
522     my $tested_files  = 0;
523     my $totmax = 0;
524     my %failed_tests;
525
526     while (my $test = shift @tests) {
527         my $test_start_time = $show_elapsed_time ? Time::HiRes::time() : 0;
528
529         if ($test =~ /^$/) {
530             next;
531         }
532         if ($type eq 'deparse') {
533             if ($test eq "comp/redef.t") {
534                 # Redefinition happens at compile time
535                 next;
536             }
537             elsif ($test =~ m{lib/Switch/t/}) {
538                 # B::Deparse doesn't support source filtering
539                 next;
540             }
541         }
542         my $te = $::path_to_name{$test} . '.'
543                     x ($dotdotdot - length($::path_to_name{$test}));
544
545         if ($^O ne 'VMS') {  # defer printing on VMS due to piping bug
546             print $te;
547             $te = '';
548         }
549
550         (local $Valgrind_Log = "$test.valgrind-current") =~ s/^.*\///;
551         my $results = _run_test($test, $type);
552
553         my $failure;
554         my $next = 0;
555         my $seen_leader = 0;
556         my $seen_ok = 0;
557         my $trailing_leader = 0;
558         my $max;
559         my %todo;
560         while (<$results>) {
561             next if /^\s*$/; # skip blank lines
562             if (/^1..$/ && ($^O eq 'VMS')) {
563                 # VMS pipe bug inserts blank lines.
564                 my $l2 = <RESULTS>;
565                 if ($l2 =~ /^\s*$/) {
566                     $l2 = <RESULTS>;
567                 }
568                 $_ = '1..' . $l2;
569             }
570             if ($::verbose) {
571                 print $_;
572             }
573             unless (/^\#/) {
574                 if ($trailing_leader) {
575                     # shouldn't be anything following a postfix 1..n
576                     $failure = 'FAILED--extra output after trailing 1..n';
577                     last;
578                 }
579                 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
580                     if ($seen_leader) {
581                         $failure = 'FAILED--seen duplicate leader';
582                         last;
583                     }
584                     $max = $1;
585                     %todo = map { $_ => 1 } split / /, $3 if $3;
586                     $totmax = $totmax + $max;
587                     $tested_files = $tested_files + 1;
588                     if ($seen_ok) {
589                         # 1..n appears at end of file
590                         $trailing_leader = 1;
591                         if ($next != $max) {
592                             $failure = "FAILED--expected $max tests, saw $next";
593                             last;
594                         }
595                     }
596                     else {
597                         $next = 0;
598                     }
599                     $seen_leader = 1;
600                 }
601                 else {
602                     if (/^(not )?ok(?: (\d+))?[^\#]*(\s*\#.*)?/) {
603                         unless ($seen_leader) {
604                             unless ($seen_ok) {
605                                 $next = 0;
606                             }
607                         }
608                         $seen_ok = 1;
609                         $next = $next + 1;
610                         my($not, $num, $extra, $istodo) = ($1, $2, $3, 0);
611                         $num = $next unless $num;
612
613                         if ($num == $next) {
614
615                             # SKIP is essentially the same as TODO for t/TEST
616                             # this still conforms to TAP:
617                             # http://search.cpan.org/dist/TAP/TAP.pm
618                             $extra and $istodo = $extra =~ /#\s*(?:TODO|SKIP)\b/;
619                             $istodo = 1 if $todo{$num};
620
621                             if( $not && !$istodo ) {
622                                 $failure = "FAILED at test $num";
623                                 last;
624                             }
625                         }
626                         else {
627                             $failure ="FAILED--expected test $next, saw test $num";
628                             last;
629                         }
630                     }
631                     elsif (/^Bail out!\s*(.*)/i) { # magic words
632                         die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
633                     }
634                     else {
635                         # module tests are allowed extra output,
636                         # because Test::Harness allows it
637                         next if $test =~ /^\W*(cpan|dist|ext|lib)\b/;
638                         $failure = "FAILED--unexpected output at test $next";
639                         last;
640                     }
641                 }
642             }
643         }
644         close $results;
645
646         if (not defined $failure) {
647             $failure = 'FAILED--no leader found' unless $seen_leader;
648         }
649
650         if ($ENV{PERL_VALGRIND}) {
651             my @valgrind;
652             if (-e $Valgrind_Log) {
653                 if (open(V, $Valgrind_Log)) {
654                     @valgrind = <V>;
655                     close V;
656                 } else {
657                     warn "$0: Failed to open '$Valgrind_Log': $!\n";
658                 }
659             }
660             if ($ENV{VG_OPTS} =~ /cachegrind/) {
661                 if (rename $Valgrind_Log, "$test.valgrind") {
662                     $valgrind = $valgrind + 1;
663                 } else {
664                     warn "$0: Failed to create '$test.valgrind': $!\n";
665                 }
666             }
667             elsif (@valgrind) {
668                 my $leaks = 0;
669                 my $errors = 0;
670                 for my $i (0..$#valgrind) {
671                     local $_ = $valgrind[$i];
672                     if (/^==\d+== ERROR SUMMARY: (\d+) errors? /) {
673                         $errors = $errors + $1;   # there may be multiple error summaries
674                     } elsif (/^==\d+== LEAK SUMMARY:/) {
675                         for my $off (1 .. 4) {
676                             if ($valgrind[$i+$off] =~
677                                 /(?:lost|reachable):\s+\d+ bytes in (\d+) blocks/) {
678                                 $leaks = $leaks + $1;
679                             }
680                         }
681                     }
682                 }
683                 if ($errors or $leaks) {
684                     if (rename $Valgrind_Log, "$test.valgrind") {
685                         $valgrind = $valgrind + 1;
686                     } else {
687                         warn "$0: Failed to create '$test.valgrind': $!\n";
688                     }
689                 }
690             } else {
691                 warn "No valgrind output?\n";
692             }
693             if (-e $Valgrind_Log) {
694                 unlink $Valgrind_Log
695                     or warn "$0: Failed to unlink '$Valgrind_Log': $!\n";
696             }
697         }
698         if ($type eq 'deparse') {
699             unlink "./$test.dp";
700         }
701         if ($ENV{PERL_3LOG}) {
702             my $tpp = $test;
703             $tpp =~ s:^\.\./::;
704             $tpp =~ s:/:_:g;
705             $tpp =~ s:\.t$:.3log:;
706             rename("perl.3log", $tpp) ||
707                 die "rename: perl3.log to $tpp: $!\n";
708         }
709         if (not defined $failure and $next != $max) {
710             $failure="FAILED--expected $max tests, saw $next";
711         }
712
713         if( !defined $failure  # don't mask a test failure
714             and $? )
715         {
716             $failure = "FAILED--non-zero wait status: $?";
717         }
718
719         if (defined $failure) {
720             print "${te}$failure\n";
721             $::bad_files = $::bad_files + 1;
722             if ($test =~ /^base/) {
723                 die "Failed a basic test ($test) -- cannot continue.\n";
724             }
725             $failed_tests{$test} = 1;
726         }
727         else {
728             if ($max) {
729                 my $elapsed;
730                 if ( $show_elapsed_time ) {
731                     $elapsed = sprintf( " %8.0f ms", (Time::HiRes::time() - $test_start_time) * 1000 );
732                 }
733                 else {
734                     $elapsed = "";
735                 }
736                 print "${te}ok$elapsed\n";
737                 $good_files = $good_files + 1;
738             }
739             else {
740                 print "${te}skipped\n";
741                 $tested_files = $tested_files - 1;
742             }
743         }
744     } # while tests
745
746     if ($::bad_files == 0) {
747         if ($good_files) {
748             print "All tests successful.\n";
749             # XXX add mention of 'perlbug -ok' ?
750         }
751         else {
752             die "FAILED--no tests were run for some reason.\n";
753         }
754     }
755     else {
756         my $pct = $tested_files ? sprintf("%.2f", ($tested_files - $::bad_files) / $tested_files * 100) : "0.00";
757         my $s = $::bad_files == 1 ? "" : "s";
758         warn "Failed $::bad_files test$s out of $tested_files, $pct% okay.\n";
759         for my $test ( sort keys %failed_tests ) {
760             print "\t$test\n";
761         }
762         warn <<'SHRDLU_1';
763 ### Since not all tests were successful, you may want to run some of
764 ### them individually and examine any diagnostic messages they produce.
765 ### See the INSTALL document's section on "make test".
766 SHRDLU_1
767         warn <<'SHRDLU_2' if $good_files / $total_files > 0.8;
768 ### You have a good chance to get more information by running
769 ###   ./perl harness
770 ### in the 't' directory since most (>=80%) of the tests succeeded.
771 SHRDLU_2
772         if (eval {require Config; import Config; 1}) {
773             if ($::Config{usedl} && (my $p = $::Config{ldlibpthname})) {
774                 warn <<SHRDLU_3;
775 ### You may have to set your dynamic library search path,
776 ### $p, to point to the build directory:
777 SHRDLU_3
778                 if (exists $ENV{$p} && $ENV{$p} ne '') {
779                     warn <<SHRDLU_4a;
780 ###   setenv $p `pwd`:\$$p; cd t; ./perl harness
781 ###   $p=`pwd`:\$$p; export $p; cd t; ./perl harness
782 ###   export $p=`pwd`:\$$p; cd t; ./perl harness
783 SHRDLU_4a
784                 } else {
785                     warn <<SHRDLU_4b;
786 ###   setenv $p `pwd`; cd t; ./perl harness
787 ###   $p=`pwd`; export $p; cd t; ./perl harness
788 ###   export $p=`pwd`; cd t; ./perl harness
789 SHRDLU_4b
790                 }
791                 warn <<SHRDLU_5;
792 ### for csh-style shells, like tcsh; or for traditional/modern
793 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
794 SHRDLU_5
795             }
796         }
797     }
798     my ($user,$sys,$cuser,$csys) = times;
799     print sprintf("u=%.2f  s=%.2f  cu=%.2f  cs=%.2f  scripts=%d  tests=%d\n",
800         $user,$sys,$cuser,$csys,$tested_files,$totmax);
801     if ($ENV{PERL_VALGRIND}) {
802         my $s = $valgrind == 1 ? '' : 's';
803         print "$valgrind valgrind report$s created.\n", ;
804     }
805 }
806 exit ($::bad_files != 0);
807
808 # ex: set ts=8 sts=4 sw=4 noet: