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?
14 use TAP::Harness 3.13;
18 $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];
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";
106 sub _tests_from_manifest {
107 my ($extensions, $known_extensions) = @_;
109 my %extensions = _populate_hash($extensions);
110 my %known_extensions = _populate_hash($known_extensions);
112 foreach (keys %known_extensions) {
113 $skip{$_}++ unless $extensions{$_};
118 my $updir = File::Spec->updir;
119 my $mani = File::Spec->catfile(File::Spec->updir, "MANIFEST");
120 if (open(MANI, $mani)) {
121 while (<MANI>) { # similar code in t/TEST
122 if (m!^(ext/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
123 my ($test, $extension) = ($1, $2);
124 if (defined $extension) {
125 $extension =~ s!/t$!!;
126 # XXX Do I want to warn that I'm skipping these?
127 next if $skip{$extension};
128 my $flat_extension = $extension;
129 $flat_extension =~ s!-!/!g;
130 next if $skip{$flat_extension}; # Foo/Bar may live in Foo-Bar
132 push @results, File::Spec->catfile($updir, $test);
137 warn "$0: cannot open $mani: $!\n";
143 # If you want these run in speed order, just use prove
144 if ($^O eq 'MSWin32') {
145 @tests = map(glob($_),@ARGV);
151 # Ideally we'd get somewhere close to Tux's Oslo rules
154 # { seq => '../ext/DB_File/t/*' },
155 # { seq => '../ext/IO_Compress_Zlib/t/*' },
156 # { seq => '../lib/CPANPLUS/*' },
157 # { seq => '../lib/ExtUtils/t/*' },
162 # but for now, run all directories in sequence. In particular, it would be
163 # nice to get the tests in t/op/*.t able to run in parallel.
166 my @seq = <base/*.t>;
168 my @next = qw(comp run cmd io op uni mro lib porting);
169 push @next, 'japh' if $torture;
170 push @next, 'win32' if $^O eq 'MSWin32';
171 push @next, 'benchmark' if $ENV{PERL_BENCHMARK};
172 # Hopefully TAP::Parser::Scheduler will support this syntax soon.
173 # my $next = { par => '{' . join (',', @next) . '}/*.t' };
174 my $next = { par => [
175 map { "$_/*.t" } @next
177 @tests = _extract_tests ($next);
179 # This is a bit of a game, because we only want to sort these tests in
180 # speed order. base/*.t wants to run first, and ext,lib etc last and in
183 require App::Prove::State;
184 $state = App::Prove::State->new({ store => 'test_state' });
185 $state->apply_switch('slow', 'save');
186 # For some reason get_tests returns *all* the tests previously run,
187 # (in the right order), not simply the selection in @tests
188 # (in the right order). Not sure if this is a bug or a feature.
189 # Whatever, *we* are only interested in the ones that are in @tests
192 @tests = grep {exists $seen{$_} } $state->get_tests(0, @tests);
194 @tests = (@seq, @tests);
199 push @last, sort { lc $a cmp lc $b }
200 _tests_from_manifest($Config{extensions}, $Config{known_extensions});
201 push @last, <pod/*.t>;
202 push @last, <x2p/*.t>;
206 # Where known, collate the elapsed times by test name
207 foreach ($state->results->tests()) {
208 $times{$_->name} = $_->elapsed();
216 if ($^O eq 'MSWin32') {
217 s,\\,/,g; # canonicalize path
219 m!(.*[/])! or die "'$_'";
220 push @{$dir{$1}}, $_;
221 $total_time{$1} += $times{$_} || 0;
226 # Generate T::H schedule rules that run the contents of each directory
228 push @seq, { par => [ map { { seq => "$_*" } } sort {
229 # Directories, ordered by total time descending then name ascending
230 $total_time{$b} <=> $total_time{$a} || $a cmp $b
233 $rules = { seq => \@seq };
236 if ($^O eq 'MSWin32') {
239 @tests=grep /$re/, @tests
242 my $h = TAP::Harness->new({
246 verbosity => $Verbose,
252 $state->observe_test(@_);
256 after_runtests => sub {
264 my ( $args, $test ) = @_;
265 push @{ $args->{switches} }, '-I../lib';
268 $h->runtests(@tests);