From 20b4e1390cbdfcef3666735d92e7a75c8149e673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Bl=C3=A5udd?= Date: Mon, 4 Jan 2010 12:17:58 +0100 Subject: Bug#47526 unit.pl fails to execute binaries when using Test::Harness 3.10 - Rewrite unit.pl so it prefers to use TAP::Harness directly. - Also add support for --verbose --noverbose --- unittest/unit.pl | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'unittest/unit.pl') diff --git a/unittest/unit.pl b/unittest/unit.pl index 9d328985012..c1c64b3d538 100644 --- a/unittest/unit.pl +++ b/unittest/unit.pl @@ -14,8 +14,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -use Test::Harness qw(&runtests $verbose); use File::Find; +use Getopt::Long; use strict; @@ -35,6 +35,11 @@ unit - Run unit tests in directory =cut +my $opt_verbose; +GetOptions ( + "verbose!" => \$opt_verbose, +) or die "Failed to parse options!: $!"; + my $cmd = shift; if (defined $cmd && exists $dispatch{$cmd}) { @@ -51,6 +56,21 @@ Run all unit tests in the current directory and all subdirectories. =cut +BEGIN { + # Test::Harness have been extensively rewritten in newer perl + # versions and is now just a backward compatibility wrapper + # (with a bug causing the HARNESS_PERL_SWITCHES to be mangled) + # Prefer to use TAP::Harness directly if available + if (eval "use TAP::Harness; 1") { + eval 'sub NEW_HARNESS { 1 }'; + warn "using TAP::Harness"; + } else { + eval "use Test::Harness; 1" or die "couldn't find Test::Harness!"; + eval 'sub NEW_HARNESS { 0 }'; + } +} + + sub _find_test_files (@) { my @dirs = @_; my @files; @@ -92,8 +112,19 @@ sub run_cmd (@) { if (@files > 0) { # Removing the first './' from the file names foreach (@files) { s!^\./!! } - $ENV{'HARNESS_PERL_SWITCHES'} .= q" -e 'exec @ARGV'"; - runtests @files; + + if (NEW_HARNESS()) + { + my %args = ( exec => [ ], verbosity => $opt_verbose ); + my $harness = TAP::Harness->new( \%args ); + $harness->runtests(@files); + } + else + { + $ENV{'HARNESS_VERBOSE'} = $opt_verbose; + $ENV{'HARNESS_PERL_SWITCHES'} .= ' -e "exec @ARGV"'; + runtests(@files); + } } } -- cgit v1.2.1