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 delete $ENV{PERL5LIB};
13 my $torture; # torture testing?
15 use TAP::Harness 3.13;
18 $::do_nothing = $::do_nothing = 1;
22 $Verbose++ while @ARGV && $ARGV[0] eq '-v' && shift;
24 if ($ARGV[0] && $ARGV[0] eq '-torture') {
29 # Let tests know they're running in the perl core. Useful for modules
30 # which live dual lives on CPAN.
49 foreach (keys %datahandle) {
55 # [.VMS]TEST.COM calls harness with empty arguments, so clean-up @ARGV
56 @ARGV = grep $_ && length( $_ ) => @ARGV;
60 # This can probably be done more tersely with a map, but I doubt that it
66 if ($ref eq 'ARRAY') {
67 push @results, _extract_tests @$_;
68 } elsif ($ref eq 'HASH') {
69 push @results, _extract_tests values %$_;
71 die "Unknown reference type $ref";
74 push @results, glob $_;
80 if ($ARGV[0] && $ARGV[0]=~/^-re/) {
86 (undef,$re)=split/=/,shift;
90 my $jobs = $ENV{TEST_JOBS};
91 my ($rules, $state, $color);
92 if ($ENV{HARNESS_OPTIONS}) {
93 for my $opt ( split /:/, $ENV{HARNESS_OPTIONS} ) {
94 if ( $opt =~ /^j(\d*)$/ ) {
97 elsif ( $opt eq 'c' ) {
101 die "Unknown HARNESS_OPTIONS item: $opt\n";
107 # If you want these run in speed order, just use prove
108 if ($^O eq 'MSWin32') {
109 @tests = map(glob($_),@ARGV);
115 # Ideally we'd get somewhere close to Tux's Oslo rules
118 # { seq => '../ext/DB_File/t/*' },
119 # { seq => '../ext/IO_Compress_Zlib/t/*' },
120 # { seq => '../lib/CPANPLUS/*' },
121 # { seq => '../lib/ExtUtils/t/*' },
126 # but for now, run all directories in sequence. In particular, it would be
127 # nice to get the tests in t/op/*.t able to run in parallel.
130 my @seq = <base/*.t>;
132 my @next = qw(comp run cmd io op uni mro lib porting);
133 push @next, 'japh' if $torture;
134 push @next, 'win32' if $^O eq 'MSWin32';
135 push @next, 'benchmark' if $ENV{PERL_BENCHMARK};
136 # Hopefully TAP::Parser::Scheduler will support this syntax soon.
137 # my $next = { par => '{' . join (',', @next) . '}/*.t' };
138 my $next = { par => [
139 map { "$_/*.t" } @next
141 @tests = _extract_tests ($next);
143 # This is a bit of a game, because we only want to sort these tests in
144 # speed order. base/*.t wants to run first, and ext,lib etc last and in
147 require App::Prove::State;
148 $state = App::Prove::State->new({ store => 'test_state' });
149 $state->apply_switch('slow', 'save');
150 # For some reason get_tests returns *all* the tests previously run,
151 # (in the right order), not simply the selection in @tests
152 # (in the right order). Not sure if this is a bug or a feature.
153 # Whatever, *we* are only interested in the ones that are in @tests
156 @tests = grep {exists $seen{$_} } $state->get_tests(0, @tests);
158 @tests = (@seq, @tests);
163 push @last, sort { lc $a cmp lc $b }
164 _tests_from_manifest($Config{extensions}, $Config{known_extensions});
165 push @last, <pod/*.t>;
166 push @last, <x2p/*.t>;
170 # Where known, collate the elapsed times by test name
171 foreach ($state->results->tests()) {
172 $times{$_->name} = $_->elapsed();
180 if ($^O eq 'MSWin32') {
181 s,\\,/,g; # canonicalize path
183 m!(.*[/])! or die "'$_'";
184 push @{$dir{$1}}, $_;
185 $total_time{$1} += $times{$_} || 0;
190 # Generate T::H schedule rules that run the contents of each directory
192 push @seq, { par => [ map { { seq => "$_*" } } sort {
193 # Directories, ordered by total time descending then name ascending
194 $total_time{$b} <=> $total_time{$a} || $a cmp $b
197 $rules = { seq => \@seq };
200 if ($^O eq 'MSWin32') {
203 @tests=grep /$re/, @tests
206 my $h = TAP::Harness->new({
210 verbosity => $Verbose,
217 $state->observe_test(@_);
221 after_runtests => sub {
229 my ( $args, $test ) = @_;
230 push @{ $args->{switches} }, '-I../lib';
233 $h->runtests(@tests);