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