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