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