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