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;
21 $Verbose++ while @ARGV && $ARGV[0] eq '-v' && shift;
23 if ($ARGV[0] && $ARGV[0] eq '-torture') {
28 # Let tests know they're running in the perl core. Useful for modules
29 # which live dual lives on CPAN.
48 foreach (keys %datahandle) {
54 # [.VMS]TEST.COM calls harness with empty arguments, so clean-up @ARGV
55 @ARGV = grep $_ && length( $_ ) => @ARGV;
59 # This can probably be done more tersely with a map, but I doubt that it
65 if ($ref eq 'ARRAY') {
66 push @results, _extract_tests @$_;
67 } elsif ($ref eq 'HASH') {
68 push @results, _extract_tests values %$_;
70 die "Unknown reference type $ref";
73 push @results, glob $_;
79 if ($ARGV[0] && $ARGV[0]=~/^-re/) {
85 (undef,$re)=split/=/,shift;
89 my $jobs = $ENV{TEST_JOBS};
90 my ($rules, $state, $color);
91 if ($ENV{HARNESS_OPTIONS}) {
92 for my $opt ( split /:/, $ENV{HARNESS_OPTIONS} ) {
93 if ( $opt =~ /^j(\d*)$/ ) {
96 elsif ( $opt eq 'c' ) {
100 die "Unknown HARNESS_OPTIONS item: $opt\n";
106 # If you want these run in speed order, just use prove
107 if ($^O eq 'MSWin32') {
108 @tests = map(glob($_),@ARGV);
113 # This is a hack to force config_heavy.pl to be loaded, before the
114 # prep work for running a test changes directory.
115 1 if $Config{d_fork};
117 # Ideally we'd get somewhere close to Tux's Oslo rules
120 # { seq => '../ext/DB_File/t/*' },
121 # { seq => '../ext/IO_Compress_Zlib/t/*' },
122 # { seq => '../lib/CPANPLUS/*' },
123 # { seq => '../lib/ExtUtils/t/*' },
128 # but for now, run all directories in sequence. In particular, it would be
129 # nice to get the tests in t/op/*.t able to run in parallel.
132 my @seq = <base/*.t>;
134 my @next = qw(comp run cmd io re op uni mro lib porting);
135 push @next, 'japh' if $torture;
136 push @next, 'win32' if $^O eq 'MSWin32';
137 push @next, 'benchmark' if $ENV{PERL_BENCHMARK};
138 push @next, 'bigmem' if $ENV{PERL_TEST_MEMORY};
139 # Hopefully TAP::Parser::Scheduler will support this syntax soon.
140 # my $next = { par => '{' . join (',', @next) . '}/*.t' };
141 my $next = { par => [
142 map { "$_/*.t" } @next
144 @tests = _extract_tests ($next);
146 # This is a bit of a game, because we only want to sort these tests in
147 # speed order. base/*.t wants to run first, and ext,lib etc last and in
150 require App::Prove::State;
151 $state = App::Prove::State->new({ store => 'test_state' });
152 $state->apply_switch('slow', 'save');
153 # For some reason get_tests returns *all* the tests previously run,
154 # (in the right order), not simply the selection in @tests
155 # (in the right order). Not sure if this is a bug or a feature.
156 # Whatever, *we* are only interested in the ones that are in @tests
159 @tests = grep {exists $seen{$_} } $state->get_tests(0, @tests);
161 @tests = (@seq, @tests);
165 push @last, sort { lc $a cmp lc $b }
166 _tests_from_manifest($Config{extensions}, $Config{known_extensions});
167 push @last, <x2p/*.t>;
171 # Where known, collate the elapsed times by test name
172 foreach ($state->results->tests()) {
173 $times{$_->name} = $_->elapsed();
181 if ($^O eq 'MSWin32') {
182 s,\\,/,g; # canonicalize path
184 # Treat every file matching lib/*.t as a "directory"
185 m!\A(\.\./lib/[^/]+\.t\z|.*[/])! or die "'$_'";
186 push @{$dir{$1}}, $_;
187 $total_time{$1} += $times{$_} || 0;
192 # Generate T::H schedule rules that run the contents of each directory
194 push @seq, { par => [ map { s!/$!/*!; { seq => $_ } } sort {
195 # Directories, ordered by total time descending then name ascending
196 $total_time{$b} <=> $total_time{$a} || $a cmp $b
199 $rules = { seq => \@seq };
202 if ($^O eq 'MSWin32') {
205 @tests=grep /$re/, @tests
212 # Load TAP::Parser now as otherwise it could be required in the short time span
213 # in which the harness process chdirs into ext/Dist
216 my $h = TAP::Harness->new({
220 verbosity => $Verbose,
222 my ($harness, $test) = @_;
224 my $options = $options{$test};
225 if (!defined $options) {
226 $options = $options{$test} = _scan_test($test, $type);
229 return [ split ' ', _cmd($options, $type) ];
236 $state->observe_test(@_);
240 after_runtests => sub {
248 my ($args, $job) = @_;
249 my $test = $job->[0];
250 _before_fork($options{$test});
251 push @{ $args->{switches} }, "-I../../lib";
257 my ($parser, $job) = @_;
258 my $test = $job->[0];
259 my $options = delete $options{$test};
260 _after_fork($options);
264 my $agg = $h->runtests(@tests);
265 exit $agg->has_errors ? 1 : 0;