3 # We suppose that perl _mostly_ works at this moment, so may use
4 # sophisticated testing.
8 @INC = '../lib'; # pick up only this build's lib
11 my $torture; # torture testing?
13 use TAP::Harness 3.13;
17 $::do_nothing = $::do_nothing = 1;
22 $Verbose++ while @ARGV && $ARGV[0] eq '-v' && shift;
24 # For valgrind summary output
28 if ($ARGV[0] && $ARGV[0] eq '-torture') {
33 # Let tests know they're running in the perl core. Useful for modules
34 # which live dual lives on CPAN.
39 # [.VMS]TEST.COM calls harness with empty arguments, so clean-up @ARGV
40 @ARGV = grep $_ && length( $_ ) => @ARGV;
44 # This can probably be done more tersely with a map, but I doubt that it
50 if ($ref eq 'ARRAY') {
51 push @results, _extract_tests @$_;
52 } elsif ($ref eq 'HASH') {
53 push @results, _extract_tests values %$_;
55 die "Unknown reference type $ref";
58 push @results, glob $_;
64 if ($ARGV[0] && $ARGV[0]=~/^-re/) {
70 (undef,$re)=split/=/,shift;
74 my $jobs = $ENV{TEST_JOBS};
75 my ($rules, $state, $color);
76 if ($ENV{HARNESS_OPTIONS}) {
77 for my $opt ( split /:/, $ENV{HARNESS_OPTIONS} ) {
78 if ( $opt =~ /^j(\d*)$/ ) {
81 elsif ( $opt eq 'c' ) {
85 die "Unknown HARNESS_OPTIONS item: $opt\n";
91 # If you want these run in speed order, just use prove
92 if ($^O eq 'MSWin32') {
93 @tests = map(glob($_),@ARGV);
98 # This is a hack to force config_heavy.pl to be loaded, before the
99 # prep work for running a test changes directory.
100 1 if $Config{d_fork};
102 # Ideally we'd get somewhere close to Tux's Oslo rules
105 # { seq => '../ext/DB_File/t/*' },
106 # { seq => '../ext/IO_Compress_Zlib/t/*' },
107 # { seq => '../lib/ExtUtils/t/*' },
112 # but for now, run all directories in sequence.
115 my @seq = <base/*.t>;
117 my @next = qw(comp run cmd io re opbasic op uni mro lib porting perf);
118 push @next, 'japh' if $torture;
119 push @next, 'win32' if $^O eq 'MSWin32';
120 push @next, 'benchmark' if $ENV{PERL_BENCHMARK};
121 push @next, 'bigmem' if $ENV{PERL_TEST_MEMORY};
122 # Hopefully TAP::Parser::Scheduler will support this syntax soon.
123 # my $next = { par => '{' . join (',', @next) . '}/*.t' };
124 my $next = { par => [
125 map { "$_/*.t" } @next
127 @tests = _extract_tests ($next);
129 # This is a bit of a game, because we only want to sort these tests in
130 # speed order. base/*.t wants to run first, and ext,lib etc last and in
133 require App::Prove::State;
134 $state = App::Prove::State->new({ store => 'test_state' });
135 $state->apply_switch('slow', 'save');
136 # For some reason get_tests returns *all* the tests previously run,
137 # (in the right order), not simply the selection in @tests
138 # (in the right order). Not sure if this is a bug or a feature.
139 # Whatever, *we* are only interested in the ones that are in @tests
142 @tests = grep {exists $seen{$_} } $state->get_tests(0, @tests);
144 @tests = (@seq, @tests);
148 push @last, sort { lc $a cmp lc $b }
149 _tests_from_manifest($Config{extensions}, $Config{known_extensions});
152 # Where known, collate the elapsed times by test name
153 foreach ($state->results->tests()) {
154 $times{$_->name} = $_->elapsed();
162 if ($^O eq 'MSWin32') {
163 s,\\,/,g; # canonicalize path
165 # Treat every file matching lib/*.t as a "directory"
166 m!\A(\.\./lib/[^/]+\.t\z|.*[/])! or die "'$_'";
167 push @{$dir{$1}}, $_;
168 $total_time{$1} += $times{$_} || 0;
173 # Generate T::H schedule rules that run the contents of each directory
175 push @seq, { par => [ map { s!/$!/*!; { seq => $_ } } sort {
176 # Directories, ordered by total time descending then name ascending
177 $total_time{$b} <=> $total_time{$a} || $a cmp $b
180 $rules = { seq => \@seq };
183 if ($^O eq 'MSWin32') {
186 @tests=grep /$re/, @tests
189 # Allow eg ./perl t/harness t/op/lc.t
201 # Load TAP::Parser now as otherwise it could be required in the short time span
202 # in which the harness process chdirs into ext/Dist
205 my $h = TAP::Harness->new({
209 verbosity => $Verbose,
210 timer => $ENV{HARNESS_TIMER},
212 my ($harness, $test) = @_;
214 my $options = $options{$test};
215 if (!defined $options) {
216 $options = $options{$test} = _scan_test($test, $type);
219 (local $Valgrind_Log = "$test.valgrind-current") =~ s/^.*\///;
221 return [ split ' ', _cmd($options, $type) ];
225 # Print valgrind output after test completes
226 if ($ENV{PERL_VALGRIND}) {
230 my $test = $job->[0];
231 my $vfile = "$test.valgrind-current";
234 if ( (! -z $vfile) && open(my $voutput, '<', $vfile)) {
235 print "$test: Valgrind output:\n";
236 print "$test: $_" for <$voutput>;
240 (local $Valgrind_Log = "$test.valgrind-current") =~ s/^.*\///;
242 _check_valgrind(\$htoolnm, \$hgrind_ct, \$test);
250 $state->observe_test(@_);
254 after_runtests => sub {
262 my ($args, $job) = @_;
263 my $test = $job->[0];
264 _before_fork($options{$test});
265 push @{ $args->{switches} }, "-I../../lib";
271 my ($parser, $job) = @_;
272 my $test = $job->[0];
273 my $options = delete $options{$test};
274 _after_fork($options);
278 my $agg = $h->runtests(@tests);
279 _cleanup_valgrind(\$htoolnm, \$hgrind_ct);
280 exit $agg->has_errors ? 1 : 0;