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
10 delete $ENV{PERL5LIB};
12 my $torture; # torture testing?
17 $Test::Harness::switches = ""; # Too much noise otherwise
18 $Test::Harness::Verbose++ while @ARGV && $ARGV[0] eq '-v' && shift;
20 if ($ARGV[0] && $ARGV[0] eq '-torture') {
25 # Let tests know they're running in the perl core. Useful for modules
26 # which live dual lives on CPAN.
45 foreach (keys %datahandle) {
51 # [.VMS]TEST.COM calls harness with empty arguments, so clean-up @ARGV
52 @ARGV = grep $_ && length( $_ ) => @ARGV;
55 return map {$_, 1} split /\s+/, $_[0];
58 # Generate T::H schedule rules that run the contents of each directory
68 return { par => [ map { { seq => $_ } } sort keys %dir ] };
73 # This can probably be done more tersely with a map, but I doubt that it
79 if ($ref eq 'ARRAY') {
80 push @results, _extract_tests @$_;
81 } elsif ($ref eq 'HASH') {
82 push @results, _extract_tests values %$_;
84 die "Unknown reference type $ref";
87 push @results, glob $_;
93 if ($ARGV[0] && $ARGV[0]=~/^-re/) {
99 (undef,$re)=split/=/,shift;
103 my $jobs = $ENV{TEST_JOBS};
104 my ($fork, $rules, $state);
105 if ($ENV{HARNESS_OPTIONS}) {
106 for my $opt ( split /:/, $ENV{HARNESS_OPTIONS} ) {
107 if ( $opt =~ /^j(\d*)$/ ) {
110 elsif ( $opt eq 'f' ) {
113 elsif ( $opt eq 'c' ) {
114 # $args->{color} = 1;
117 die "Unknown HARNESS_OPTIONS item: $opt\n";
123 # If you want these run in speed order, just use prove
124 if ($^O eq 'MSWin32') {
125 @tests = map(glob($_),@ARGV);
131 # Ideally we'd get somewhere close to Tux's Oslo rules
134 # { seq => '../ext/DB_File/t/*' },
135 # { seq => '../ext/IO_Compress_Zlib/t/*' },
136 # { seq => '../lib/CPANPLUS/*' },
137 # { seq => '../lib/ExtUtils/t/*' },
142 # but for now, run all directories in sequence. In particular, it would be
143 # nice to get the tests in t/op/*.t able to run in parallel.
146 my @seq = <base/*.t>;
148 my @next = qw(comp cmd run io op uni mro lib);
149 push @next, 'japh' if $torture;
150 push @next, 'win32' if $^O eq 'MSWin32';
151 # Hopefully TAP::Parser::Scheduler will support this syntax soon.
152 # my $next = { par => '{' . join (',', @next) . '}/*.t' };
153 my $next = { par => [
154 map { "$_/*.t" } @next
156 @tests = _extract_tests ($next);
158 # This is a bit of a game, because we only want to sort these tests in
159 # speed order. base/*.t wants to run first, and ext,lib etc last and in
162 require App::Prove::State;
163 $state = App::Prove::State->new({ store => 'test_state' });
164 $state->apply_switch('slow', 'save');
165 # For some reason get_tests returns *all* the tests previously run,
166 # (in the right order), not simply the selection in @tests
167 # (in the right order). Not sure if this is a bug or a feature.
168 # Whatever, *we* are only interested in the ones that are in @tests
171 @tests = grep {exists $seen{$_} } $state->get_tests(0, @tests);
173 @tests = (@seq, @tests);
180 my %extensions = _populate_hash $Config{'extensions'};
181 my %known_extensions = _populate_hash $Config{'known_extensions'};
182 foreach (keys %known_extensions) {
183 $skip{$_}++ unless $extensions{$_};
187 my $updir = File::Spec->updir;
188 my $mani = File::Spec->catfile(File::Spec->updir, "MANIFEST");
189 if (open(MANI, $mani)) {
191 while (<MANI>) { # similar code in t/TEST
192 if (m!^(ext/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
193 my ($test, $extension) = ($1, $2);
194 if (defined $extension) {
195 $extension =~ s!/t$!!;
196 # XXX Do I want to warn that I'm skipping these?
197 next if $skip{$extension};
198 my $flat_extension = $extension;
199 $flat_extension =~ s!-!/!g;
200 next if $skip{$flat_extension}; # Foo/Bar may live in Foo-Bar
202 push @manitests, File::Spec->catfile($updir, $test);
206 # Sort the list of test files read from MANIFEST into a sensible
207 # order instead of using the order in which they are listed there
208 push @last, sort { lc $a cmp lc $b } @manitests;
210 warn "$0: cannot open $mani: $!\n";
212 push @last, <Module_Pluggable/*.t>;
213 push @last, <pod/*.t>;
214 push @last, <x2p/*.t>;
218 push @seq, _seq_dir_rules @last;
220 $rules = { seq => \@seq };
223 if ($^O eq 'MSWin32') {
226 @tests=grep /$re/, @tests
230 eval 'use TAP::Harness 3.13; 1' or die $@;
232 # Test::Harness parses $ENV{HARNESS_OPTIONS}, TAP::Harness does not
233 local $ENV{HARNESS_OPTIONS};
234 my $h = TAP::Harness->new({ jobs => $jobs, rules => $rules, ($fork ? (fork => $fork) : ())});
238 $state->observe_test(@_);
242 after_runtests => sub {
249 my ( $args, $test ) = @_;
250 push @{ $args->{switches} }, '-I../lib';
253 $h->runtests(@tests);
255 Test::Harness::runtests @tests;