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;
16 $::do_nothing = $::do_nothing = 1;
20 $Verbose++ while @ARGV && $ARGV[0] eq '-v' && shift;
22 if ($ARGV[0] && $ARGV[0] eq '-torture') {
27 # Let tests know they're running in the perl core. Useful for modules
28 # which live dual lives on CPAN.
47 foreach (keys %datahandle) {
53 # [.VMS]TEST.COM calls harness with empty arguments, so clean-up @ARGV
54 @ARGV = grep $_ && length( $_ ) => @ARGV;
58 # This can probably be done more tersely with a map, but I doubt that it
64 if ($ref eq 'ARRAY') {
65 push @results, _extract_tests @$_;
66 } elsif ($ref eq 'HASH') {
67 push @results, _extract_tests values %$_;
69 die "Unknown reference type $ref";
72 push @results, glob $_;
78 if ($ARGV[0] && $ARGV[0]=~/^-re/) {
84 (undef,$re)=split/=/,shift;
88 my $jobs = $ENV{TEST_JOBS};
89 my ($rules, $state, $color);
90 if ($ENV{HARNESS_OPTIONS}) {
91 for my $opt ( split /:/, $ENV{HARNESS_OPTIONS} ) {
92 if ( $opt =~ /^j(\d*)$/ ) {
95 elsif ( $opt eq 'c' ) {
99 die "Unknown HARNESS_OPTIONS item: $opt\n";
105 # If you want these run in speed order, just use prove
106 if ($^O eq 'MSWin32') {
107 @tests = map(glob($_),@ARGV);
113 # Ideally we'd get somewhere close to Tux's Oslo rules
116 # { seq => '../ext/DB_File/t/*' },
117 # { seq => '../ext/IO_Compress_Zlib/t/*' },
118 # { seq => '../lib/CPANPLUS/*' },
119 # { seq => '../lib/ExtUtils/t/*' },
124 # but for now, run all directories in sequence. In particular, it would be
125 # nice to get the tests in t/op/*.t able to run in parallel.
128 my @seq = <base/*.t>;
130 my @next = qw(comp run cmd io op uni mro lib porting);
131 push @next, 'japh' if $torture;
132 push @next, 'win32' if $^O eq 'MSWin32';
133 push @next, 'benchmark' if $ENV{PERL_BENCHMARK};
134 # Hopefully TAP::Parser::Scheduler will support this syntax soon.
135 # my $next = { par => '{' . join (',', @next) . '}/*.t' };
136 my $next = { par => [
137 map { "$_/*.t" } @next
139 @tests = _extract_tests ($next);
141 # This is a bit of a game, because we only want to sort these tests in
142 # speed order. base/*.t wants to run first, and ext,lib etc last and in
145 require App::Prove::State;
146 $state = App::Prove::State->new({ store => 'test_state' });
147 $state->apply_switch('slow', 'save');
148 # For some reason get_tests returns *all* the tests previously run,
149 # (in the right order), not simply the selection in @tests
150 # (in the right order). Not sure if this is a bug or a feature.
151 # Whatever, *we* are only interested in the ones that are in @tests
154 @tests = grep {exists $seen{$_} } $state->get_tests(0, @tests);
156 @tests = (@seq, @tests);
161 push @last, sort { lc $a cmp lc $b }
162 _tests_from_manifest($Config{extensions}, $Config{known_extensions});
163 push @last, <pod/*.t>;
164 push @last, <x2p/*.t>;
168 # Where known, collate the elapsed times by test name
169 foreach ($state->results->tests()) {
170 $times{$_->name} = $_->elapsed();
178 if ($^O eq 'MSWin32') {
179 s,\\,/,g; # canonicalize path
181 m!(.*[/])! or die "'$_'";
182 push @{$dir{$1}}, $_;
183 $total_time{$1} += $times{$_} || 0;
188 # Generate T::H schedule rules that run the contents of each directory
190 push @seq, { par => [ map { { seq => "$_*" } } sort {
191 # Directories, ordered by total time descending then name ascending
192 $total_time{$b} <=> $total_time{$a} || $a cmp $b
195 $rules = { seq => \@seq };
198 if ($^O eq 'MSWin32') {
201 @tests=grep /$re/, @tests
208 # Load TAP::Parser now as otherwise it could be required in the short time span
209 # in which the harness process chdirs into ext/Dist
212 my $h = TAP::Harness->new({
216 verbosity => $Verbose,
218 my ($harness, $test) = @_;
220 my $options = $options{$test};
221 if (!defined $options) {
222 $options = $options{$test} = _scan_test($test, $type);
225 return [ split ' ', _cmd($options, $type) ];
232 $state->observe_test(@_);
236 after_runtests => sub {
244 my ($args, $job) = @_;
245 my $test = $job->[0];
246 _before_fork($options{$test});
247 push @{ $args->{switches} }, "-I../../lib";
253 my ($parser, $job) = @_;
254 my $test = $job->[0];
255 my $options = delete $options{$test};
256 _after_fork($options);
260 $h->runtests(@tests);