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