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