BEGIN {
chdir 't' if -d 't';
@INC = '../lib'; # pick up only this build's lib
- $ENV{PERL5LIB} = '../lib'; # so children will see it too
}
+delete $ENV{PERL5LIB};
my $torture; # torture testing?
unlink "$_.t";
}
-my (@tests, $rules, $re);
+my (@tests, $re);
# [.VMS]TEST.COM calls harness with empty arguments, so clean-up @ARGV
@ARGV = grep $_ && length( $_ ) => @ARGV;
return map {$_, 1} split /\s+/, $_[0];
}
-sub _glob_and_parallelise {
- my @dirs;
- # Run the tests in each of these directories in sequence, but the
- # directories themselves can be parallelised.
- foreach (@_) {
- push @dirs, { seq => [ glob "$_/*.t" ] };
- }
- { par => \@dirs };
-}
-
# Generate T::H schedule rules that run the contents of each directory
# sequentially.
sub _seq_dir_rules {
die "Unknown reference type $ref";
}
} else {
- push @results, $_;
+ push @results, glob $_;
}
}
@results;
}
}
+my $jobs = $ENV{TEST_JOBS};
+my ($fork, $rules, $state);
+if ($ENV{HARNESS_OPTIONS}) {
+ for my $opt ( split /:/, $ENV{HARNESS_OPTIONS} ) {
+ if ( $opt =~ /^j(\d*)$/ ) {
+ $jobs ||= $1 || 9;
+ }
+ elsif ( $opt eq 'f' ) {
+ $fork = 1;
+ }
+ elsif ( $opt eq 'c' ) {
+# $args->{color} = 1;
+ }
+ else {
+ die "Unknown HARNESS_OPTIONS item: $opt\n";
+ }
+ }
+}
+
if (@ARGV) {
+ # If you want these run in speed order, just use prove
if ($^O eq 'MSWin32') {
@tests = map(glob($_),@ARGV);
}
# nice to get the tests in t/op/*.t able to run in parallel.
unless (@tests) {
- my @seq;
- push @seq, <base/*.t>;
+ my @seq = <base/*.t>;
- push @seq, _glob_and_parallelise qw(comp cmd run io);
- my @next = qw(op uni mro lib);
+ my @next = qw(comp cmd run io op uni mro lib);
push @next, 'japh' if $torture;
push @next, 'win32' if $^O eq 'MSWin32';
- push @seq, _glob_and_parallelise @next;
+ # Hopefully TAP::Parser::Scheduler will support this syntax soon.
+ # my $next = { par => '{' . join (',', @next) . '}/*.t' };
+ my $next = { par => [
+ map { "$_/*.t" } @next
+ ] };
+ @tests = _extract_tests ($next);
+
+ # This is a bit of a game, because we only want to sort these tests in
+ # speed order. base/*.t wants to run first, and ext,lib etc last and in
+ # MANIFEST order
+ if ($jobs) {
+ require App::Prove::State;
+ $state = App::Prove::State->new({ store => 'test_state' });
+ $state->apply_switch('slow', 'save');
+ # For some reason get_tests returns *all* the tests previously run,
+ # (in the right order), not simply the selection in @tests
+ # (in the right order). Not sure if this is a bug or a feature.
+ # Whatever, *we* are only interested in the ones that are in @tests
+ my %seen;
+ @seen{@tests} = ();
+ @tests = grep {exists $seen{$_} } $state->get_tests(0, @tests);
+ }
+ @tests = (@seq, @tests);
+ push @seq, $next;
my @last;
use Config;
my $mani = File::Spec->catfile(File::Spec->updir, "MANIFEST");
if (open(MANI, $mani)) {
my @manitests = ();
- my $ext_pat = $^O eq 'MSWin32' ? '(?:win32/)?ext' : 'ext';
while (<MANI>) { # similar code in t/TEST
- if (m!^($ext_pat/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
+ if (m!^(ext/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
my ($test, $extension) = ($1, $2);
if (defined $extension) {
$extension =~ s!/t$!!;
# XXX Do I want to warn that I'm skipping these?
next if $skip{$extension};
+ my $flat_extension = $extension;
+ $flat_extension =~ s!-!/!g;
+ next if $skip{$flat_extension}; # Foo/Bar may live in Foo-Bar
}
push @manitests, File::Spec->catfile($updir, $test);
}
} else {
warn "$0: cannot open $mani: $!\n";
}
- push @last, <Module_Pluggable/*.t>;
push @last, <pod/*.t>;
push @last, <x2p/*.t>;
- @tests = (_extract_tests (@seq), @last);
+ push @tests, @last;
push @seq, _seq_dir_rules @last;
$rules = { seq => \@seq };
-
}
}
if ($^O eq 'MSWin32') {
@tests=grep /$re/, @tests
if $re;
-my $jobs = $ENV{TEST_JOBS};
if ($jobs) {
eval 'use TAP::Harness 3.13; 1' or die $@;
- my $h = TAP::Harness->new({ jobs => $jobs, rules => $rules});
+
+ # Test::Harness parses $ENV{HARNESS_OPTIONS}, TAP::Harness does not
+ local $ENV{HARNESS_OPTIONS};
+ my $h = TAP::Harness->new({ jobs => $jobs, rules => $rules, ($fork ? (fork => $fork) : ())});
+ if ($state) {
+ $h->callback(
+ after_test => sub {
+ $state->observe_test(@_);
+ }
+ );
+ $h->callback(
+ after_runtests => sub {
+ $state->commit(@_);
+ }
+ );
+ }
+ $h->callback(
+ parser_args => sub {
+ my ( $args, $test ) = @_;
+ push @{ $args->{switches} }, '-I../lib';
+ }
+ );
$h->runtests(@tests);
} else {
Test::Harness::runtests @tests;