- use File::Spec;
- my $updir = File::Spec->updir;
- my $mani = File::Spec->catfile(File::Spec->updir, "MANIFEST");
- if (open(MANI, $mani)) {
- my @manitests = ();
- while (<MANI>) { # similar code in t/TEST
- 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);
- }
- }
- close MANI;
- # Sort the list of test files read from MANIFEST into a sensible
- # order instead of using the order in which they are listed there
- push @last, sort { lc $a cmp lc $b } @manitests;
- } else {
- warn "$0: cannot open $mani: $!\n";
+
+ my %dir;
+ my %total_time;
+ my %serials;
+ my %all_dirs;
+
+ # Preprocess the list of tests
+ for (@last) {
+ if ($^O eq 'MSWin32') {
+ s,\\,/,g; # canonicalize path
+ };
+
+ # Keep a list of the distinct directory names, and another list of
+ # those which contain a file whose name begins with a 0
+ if ( m! \A \.\. /
+ ( .*? ) # $1 is the directory path name
+ /
+ ( [^/]* \.t ) # $2 is the .t name
+ \z !x)
+ {
+ my $path = $1;
+
+ $all_dirs{$path} = 1;
+ $serials{$path} = 1 if $2 =~ / \A 0 /x;
+ }
+ }
+
+ # We assume that the reason a test file's name begins with a 0 is to
+ # order its execution among the tests in its directory. Hence, a
+ # directory containing such files should be tested in serial order.
+ #
+ # Add exceptions to the above rule
+ for (qw(ext/Pod-Html/t cpan/IO-Zlib/t ext/File-Find/t)) {
+ $serials{$_} = 1;
+ }
+
+ my @nonexistent_serials = grep { not exists $all_dirs{$_} } keys %serials;
+ if (@nonexistent_serials) {
+ die "These directories to be run serially don't exist."
+ . " Check your spelling:\n" . join "\n", @nonexistent_serials;
+ }
+
+ # Remove the serial testing directories from the list of all
+ # directories. The remaining ones are testable in parallel. Make the
+ # parallel list a scalar with names separated by '|' so that below
+ # they will be added to a regular expression.
+ my $non_serials = join "|", grep { not exists $serials{$_} } keys %all_dirs;
+ undef %all_dirs;
+ undef %serials;
+
+ for (@last) {
+ # Treat every file in each non-serial directory as its own
+ # "directory", so that it can be executed in parallel
+ m! \A ( \.\. / (?: $non_serials )
+ / [^/]+ \.t \z | .* [/] ) !x
+ or die "'$_'";
+ push @{$dir{$1}}, $_;
+
+ # This file contributes time to the total needed for the directory
+ # as a whole
+ $total_time{$1} += $times{$_} || 0;