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
9 $ENV{PERL5LIB} = '../lib'; # so children will see it too
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};
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 cmd run io op uni mro lib);
133 push @next, 'japh' if $torture;
134 push @next, 'win32' if $^O eq 'MSWin32';
135 # Hopefully TAP::Parser::Scheduler will support this syntax soon.
136 # my $next = { par => '{' . join (',', @next) . '}/*.t' };
137 my $next = { par => [
138 map { "$_/*.t" } @next
140 @tests = _extract_tests ($next);
142 # This is a bit of a game, because we only want to sort these tests in
143 # speed order. base/*.t wants to run first, and ext,lib etc last and in
146 require App::Prove::State;
147 $state = App::Prove::State->new({ store => 'test_state' });
148 $state->apply_switch('slow', 'save');
149 # For some reason get_tests returns *all* the tests previously run,
150 # (in the right order), not simply the selection in @tests
151 # (in the right order). Not sure if this is a bug or a feature.
152 # Whatever, *we* are only interested in the ones that are in @tests
155 @tests = grep {exists $seen{$_} } $state->get_tests(0, @tests);
157 @tests = (@seq, @tests);
164 my %extensions = _populate_hash $Config{'extensions'};
165 my %known_extensions = _populate_hash $Config{'known_extensions'};
166 foreach (keys %known_extensions) {
167 $skip{$_}++ unless $extensions{$_};
171 my $updir = File::Spec->updir;
172 my $mani = File::Spec->catfile(File::Spec->updir, "MANIFEST");
173 if (open(MANI, $mani)) {
175 my $ext_pat = $^O eq 'MSWin32' ? '(?:win32/)?ext' : 'ext';
176 while (<MANI>) { # similar code in t/TEST
177 if (m!^($ext_pat/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
178 my ($test, $extension) = ($1, $2);
179 if (defined $extension) {
180 $extension =~ s!/t$!!;
181 # XXX Do I want to warn that I'm skipping these?
182 next if $skip{$extension};
184 push @manitests, File::Spec->catfile($updir, $test);
188 # Sort the list of test files read from MANIFEST into a sensible
189 # order instead of using the order in which they are listed there
190 push @last, sort { lc $a cmp lc $b } @manitests;
192 warn "$0: cannot open $mani: $!\n";
194 push @last, <Module_Pluggable/*.t>;
195 push @last, <pod/*.t>;
196 push @last, <x2p/*.t>;
200 push @seq, _seq_dir_rules @last;
202 $rules = { seq => \@seq };
205 if ($^O eq 'MSWin32') {
208 @tests=grep /$re/, @tests
212 eval 'use TAP::Harness 3.13; 1' or die $@;
213 my $h = TAP::Harness->new({ jobs => $jobs, rules => $rules});
217 $state->observe_test(@_);
221 $h->runtests(@tests);
223 Test::Harness::runtests @tests;