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