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.
53 foreach (keys %datahandle) {
59 # [.VMS]TEST.COM calls harness with empty arguments, so clean-up @ARGV
60 @ARGV = grep $_ && length( $_ ) => @ARGV;
64 # This can probably be done more tersely with a map, but I doubt that it
70 if ($ref eq 'ARRAY') {
71 push @results, _extract_tests @$_;
72 } elsif ($ref eq 'HASH') {
73 push @results, _extract_tests values %$_;
75 die "Unknown reference type $ref";
78 push @results, glob $_;
84 if ($ARGV[0] && $ARGV[0]=~/^-re/) {
90 (undef,$re)=split/=/,shift;
94 my $jobs = $ENV{TEST_JOBS};
95 my ($rules, $state, $color);
96 if ($ENV{HARNESS_OPTIONS}) {
97 for my $opt ( split /:/, $ENV{HARNESS_OPTIONS} ) {
98 if ( $opt =~ /^j(\d*)$/ ) {
101 elsif ( $opt eq 'c' ) {
105 die "Unknown HARNESS_OPTIONS item: $opt\n";
111 # If you want these run in speed order, just use prove
112 if ($^O eq 'MSWin32') {
113 @tests = map(glob($_),@ARGV);
118 # This is a hack to force config_heavy.pl to be loaded, before the
119 # prep work for running a test changes directory.
120 1 if $Config{d_fork};
122 # Ideally we'd get somewhere close to Tux's Oslo rules
125 # { seq => '../ext/DB_File/t/*' },
126 # { seq => '../ext/IO_Compress_Zlib/t/*' },
127 # { seq => '../lib/ExtUtils/t/*' },
132 # but for now, run all directories in sequence.
135 my @seq = <base/*.t>;
137 my @next = qw(comp run cmd io re opbasic op uni mro lib porting perf);
138 push @next, 'japh' if $torture;
139 push @next, 'win32' if $^O eq 'MSWin32';
140 push @next, 'benchmark' if $ENV{PERL_BENCHMARK};
141 push @next, 'bigmem' if $ENV{PERL_TEST_MEMORY};
142 # Hopefully TAP::Parser::Scheduler will support this syntax soon.
143 # my $next = { par => '{' . join (',', @next) . '}/*.t' };
144 my $next = { par => [
145 map { "$_/*.t" } @next
147 @tests = _extract_tests ($next);
149 # This is a bit of a game, because we only want to sort these tests in
150 # speed order. base/*.t wants to run first, and ext,lib etc last and in
153 require App::Prove::State;
154 $state = App::Prove::State->new({ store => 'test_state' });
155 $state->apply_switch('slow', 'save');
156 # For some reason get_tests returns *all* the tests previously run,
157 # (in the right order), not simply the selection in @tests
158 # (in the right order). Not sure if this is a bug or a feature.
159 # Whatever, *we* are only interested in the ones that are in @tests
162 @tests = grep {exists $seen{$_} } $state->get_tests(0, @tests);
164 @tests = (@seq, @tests);
168 push @last, sort { lc $a cmp lc $b }
169 _tests_from_manifest($Config{extensions}, $Config{known_extensions});
172 # Where known, collate the elapsed times by test name
173 foreach ($state->results->tests()) {
174 $times{$_->name} = $_->elapsed();
182 if ($^O eq 'MSWin32') {
183 s,\\,/,g; # canonicalize path
185 # Treat every file matching lib/*.t as a "directory"
186 m!\A(\.\./lib/[^/]+\.t\z|.*[/])! or die "'$_'";
187 push @{$dir{$1}}, $_;
188 $total_time{$1} += $times{$_} || 0;
193 # Generate T::H schedule rules that run the contents of each directory
195 push @seq, { par => [ map { s!/$!/*!; { seq => $_ } } sort {
196 # Directories, ordered by total time descending then name ascending
197 $total_time{$b} <=> $total_time{$a} || $a cmp $b
200 $rules = { seq => \@seq };
203 if ($^O eq 'MSWin32') {
206 @tests=grep /$re/, @tests
209 # Allow eg ./perl t/harness t/op/lc.t
221 # Load TAP::Parser now as otherwise it could be required in the short time span
222 # in which the harness process chdirs into ext/Dist
225 my $h = TAP::Harness->new({
229 verbosity => $Verbose,
230 timer => $ENV{HARNESS_TIMER},
232 my ($harness, $test) = @_;
234 my $options = $options{$test};
235 if (!defined $options) {
236 $options = $options{$test} = _scan_test($test, $type);
239 (local $Valgrind_Log = "$test.valgrind-current") =~ s/^.*\///;
241 return [ split ' ', _cmd($options, $type) ];
245 # Print valgrind output after test completes
246 if ($ENV{PERL_VALGRIND}) {
250 my $test = $job->[0];
251 my $vfile = "$test.valgrind-current";
254 if ( (! -z $vfile) && open(my $voutput, '<', $vfile)) {
255 print "$test: Valgrind output:\n";
256 print "$test: $_" for <$voutput>;
260 (local $Valgrind_Log = "$test.valgrind-current") =~ s/^.*\///;
262 _check_valgrind(\$htoolnm, \$hgrind_ct, \$test);
270 $state->observe_test(@_);
274 after_runtests => sub {
282 my ($args, $job) = @_;
283 my $test = $job->[0];
284 _before_fork($options{$test});
285 push @{ $args->{switches} }, "-I../../lib";
291 my ($parser, $job) = @_;
292 my $test = $job->[0];
293 my $options = delete $options{$test};
294 _after_fork($options);
298 my $agg = $h->runtests(@tests);
299 _cleanup_valgrind(\$htoolnm, \$hgrind_ct);
300 exit $agg->has_errors ? 1 : 0;