Fix parsing of readline(FH) [perl #68458]
[p5sagit/p5-mst-13.2.git] / t / harness
index 9c57626..1eb85f1 100644 (file)
--- a/t/harness
+++ b/t/harness
@@ -6,8 +6,8 @@
 BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';              # pick up only this build's lib
-    $ENV{PERL5LIB} = '../lib';    # so children will see it too
 }
+delete $ENV{PERL5LIB};
 
 my $torture; # torture testing?
 
@@ -55,19 +55,6 @@ sub _populate_hash {
     return map {$_, 1} split /\s+/, $_[0];
 }
 
-# Generate T::H schedule rules that run the contents of each directory
-# sequentially.
-sub _seq_dir_rules {
-    my @tests = @_;
-    my %dir;
-    for (@tests) {
-        s{[^/]+$}{\*};
-        $dir{$_}++;
-    }
-
-    return { par => [ map { { seq => $_ } } sort keys %dir ] };
-}
-
 sub _extract_tests;
 sub _extract_tests {
     # This can probably be done more tersely with a map, but I doubt that it
@@ -145,9 +132,10 @@ if (@ARGV) {
     unless (@tests) {
        my @seq = <base/*.t>;
 
-       my @next = qw(comp cmd run io op uni mro lib);
+       my @next = qw(comp cmd run io op uni mro lib porting);
        push @next, 'japh' if $torture;
        push @next, 'win32' if $^O eq 'MSWin32';
+       push @next, 'benchmark' if $ENV{PERL_BENCHMARK};
        # Hopefully TAP::Parser::Scheduler will support this syntax soon.
        # my $next = { par => '{' . join (',', @next) . '}/*.t' };
        my $next = { par => [
@@ -188,14 +176,16 @@ if (@ARGV) {
        my $mani  = File::Spec->catfile(File::Spec->updir, "MANIFEST");
        if (open(MANI, $mani)) {
            my @manitests = ();
-           my $ext_pat = $^O eq 'MSWin32' ? '(?:win32/)?ext' : 'ext';
            while (<MANI>) { # similar code in t/TEST
-               if (m!^($ext_pat/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
+               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);
                }
@@ -207,13 +197,37 @@ if (@ARGV) {
        } else {
            warn "$0: cannot open $mani: $!\n";
        }
-       push @last, <Module_Pluggable/*.t>;
        push @last, <pod/*.t>;
        push @last, <x2p/*.t>;
 
+       my %times;
+       if ($state) {
+           # Where known, collate the elapsed times by test name
+           foreach ($state->results->tests()) {
+               $times{$_->name} = $_->elapsed();
+           }
+       }
+
+       my %dir;
+       my %total_time;
+
+       for (@last) {
+           if ($^O eq 'MSWin32') {
+               s,\\,/,g; # canonicalize path
+           };
+           m!(.*[/])! or die "'$_'";
+           push @{$dir{$1}}, $_;
+           $total_time{$1} += $times{$_} || 0;
+       }
+
        push @tests, @last;
 
-       push @seq, _seq_dir_rules @last;
+       # Generate T::H schedule rules that run the contents of each directory
+       # sequentially.
+       push @seq, { par => [ map { { seq => "$_*" } } sort {
+           # Directories, ordered by total time descending then name ascending
+           $total_time{$b} <=> $total_time{$a} || $a cmp $b
+       } keys %dir ] };
 
        $rules = { seq => \@seq };
     }
@@ -242,6 +256,12 @@ if ($jobs) {
                     }
                    );
     }
+    $h->callback(
+                parser_args => sub {
+                    my ( $args, $test ) = @_;
+                    push @{ $args->{switches} }, '-I../lib';
+                }
+               );
     $h->runtests(@tests);
 } else {
     Test::Harness::runtests @tests;