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