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