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