Skip to content
Permalink
Browse files

Item400: Fix bug when running test Suites (thanks Kenneth for spottin…

…g it). Added favoring of suites when found, to avoid running twice the same tests.

git-svn-id: http://svn.foswiki.org/trunk@3334 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OlivierRaginel OlivierRaginel
OlivierRaginel authored and OlivierRaginel committed Mar 30, 2009
1 parent 1e6f413 commit 1838e2ec686b5d85ac0e79ba417d112e949c1a09
Showing with 27 additions and 11 deletions.
  1. +27 −11 UnitTestContrib/lib/Unit/TestRunner.pm
@@ -19,33 +19,49 @@ sub start {
# First use all the tests to get them compiled
while ( scalar(@files) ) {
my $suite = shift @files;
$suite =~ s/::(\w+)$//;
my $testToRun = $1;
$suite =~ s/^(.*?)(\w+)\.pm$/$2/;
push( @INC, $1 ) if $1 && -d $1;
$suite =~ s/\/$//; # Trim final slash, for completion lovers like Sven
my $testToRun;
if ( $suite =~ s/::(\w+)$// ) {
$testToRun = $1;
}
if ( $suite =~ s/^(.*?)(\w+)\.pm$/$2/ ) {
push( @INC, $1 ) if $1 && -d $1;
}
eval "use $suite";
if ($@) {

# Try to be clever, look for it
if ( $@ =~ /Can't locate \Q$suite\E\.pm in \@INC/ ) {
$testToRun = $testToRun ? "::$testToRun" : '';
print "Looking for $suite$testToRun...\n";
my $testToFind = $testToRun ? "::$testToRun" : '';
print "Looking for $suite$testToFind...\n";
require File::Find;
my $found = 0;
my @found;
File::Find::find(
{
wanted => sub {
/^$suite/
&& $File::Find::name =~ /^\.\/(.*\.pm)$/
&& ( $found = 1 )
&& ( print("Found $1\n") )
&& unshift( @files, $1 . $testToRun );
&& ( print("\tFound $1\n") )
&& push( @found, $1 . $testToFind );
},
follow => 1
},
'.'
);
next if $found;

# Try to be even smarter: favor test suites
my @suite = grep { /Suite.pm/ } @found;
if ( $#found and @suite ) {
print "Found "
. scalar(@found)
. " tests,"
. " favoring @suite\n";
unshift @files, @suite;
}
else {
unshift @files, @found;
}
next if @found;
}
my $m = "*** Failed to use $suite: $@";
print $m;

0 comments on commit 1838e2e

Please sign in to comment.
You can’t perform that action at this time.