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) {
49 my (@tests, $rules, $re);
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 sub _glob_and_parallelise {
60 # Run the tests in each of these directories in sequence, but the
61 # directories themselves can be parallelised.
63 push @dirs, { seq => [ glob "$_/*.t" ] };
68 # Generate T::H schedule rules that run the contents of each directory
78 return { par => [ map { { seq => $_ } } sort keys %dir ] };
83 # This can probably be done more tersely with a map, but I doubt that it
89 if ($ref eq 'ARRAY') {
90 push @results, _extract_tests @$_;
91 } elsif ($ref eq 'HASH') {
92 push @results, _extract_tests values %$_;
94 die "Unknown reference type $ref";
103 if ($ARGV[0] && $ARGV[0]=~/^-re/) {
109 (undef,$re)=split/=/,shift;
114 if ($^O eq 'MSWin32') {
115 @tests = map(glob($_),@ARGV);
121 # Ideally we'd get somewhere close to Tux's Oslo rules
124 # { seq => '../ext/DB_File/t/*' },
125 # { seq => '../ext/IO_Compress_Zlib/t/*' },
126 # { seq => '../lib/CPANPLUS/*' },
127 # { seq => '../lib/ExtUtils/t/*' },
132 # but for now, run all directories in sequence. In particular, it would be
133 # nice to get the tests in t/op/*.t able to run in parallel.
137 push @seq, <base/*.t>;
139 push @seq, _glob_and_parallelise qw(comp cmd run io);
140 my @next = qw(op uni mro lib);
141 push @next, 'japh' if $torture;
142 push @next, 'win32' if $^O eq 'MSWin32';
143 push @seq, _glob_and_parallelise @next;
149 my %extensions = _populate_hash $Config{'extensions'};
150 my %known_extensions = _populate_hash $Config{'known_extensions'};
151 foreach (keys %known_extensions) {
152 $skip{$_}++ unless $extensions{$_};
156 my $updir = File::Spec->updir;
157 my $mani = File::Spec->catfile(File::Spec->updir, "MANIFEST");
158 if (open(MANI, $mani)) {
160 my $ext_pat = $^O eq 'MSWin32' ? '(?:win32/)?ext' : 'ext';
161 while (<MANI>) { # similar code in t/TEST
162 if (m!^($ext_pat/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
163 my ($test, $extension) = ($1, $2);
164 if (defined $extension) {
165 $extension =~ s!/t$!!;
166 # XXX Do I want to warn that I'm skipping these?
167 next if $skip{$extension};
169 push @manitests, File::Spec->catfile($updir, $test);
173 # Sort the list of test files read from MANIFEST into a sensible
174 # order instead of using the order in which they are listed there
175 push @last, sort { lc $a cmp lc $b } @manitests;
177 warn "$0: cannot open $mani: $!\n";
179 push @last, <Module_Pluggable/*.t>;
180 push @last, <pod/*.t>;
181 push @last, <x2p/*.t>;
183 @tests = (_extract_tests (@seq), @last);
185 push @seq, _seq_dir_rules @last;
187 $rules = { seq => \@seq };
191 if ($^O eq 'MSWin32') {
194 @tests=grep /$re/, @tests
197 my $jobs = $ENV{TEST_JOBS};
199 eval 'use TAP::Harness 3.13; 1' or die $@;
200 my $h = TAP::Harness->new({ jobs => $jobs, rules => $rules});
201 $h->runtests(@tests);
203 Test::Harness::runtests @tests;