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