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