# In which case, we need to stop t/TEST actually running tests, as all
# t/harness needs are its subroutines.
+
+# directories with special sets of test switches
+my %dir_to_switch =
+ (base => '',
+ comp => '',
+ run => '',
+ '../ext/File-Glob/t' => '-I.. -MTestInit', # FIXME - tests assume t/
+ );
+
+my %temp_no_core =
+ ('../ext/B-Debug' => 1,
+ '../ext/Compress-Raw-Bzip2' => 1,
+ '../ext/Compress-Raw-Zlib' => 1,
+ '../ext/Devel-PPPort' => 1,
+ '../ext/Encode' => 1,
+ '../ext/IO-Compress' => 1,
+ '../ext/IPC-SysV' => 1,
+ '../ext/MIME-Base64' => 1,
+ '../ext/Time-HiRes' => 1,
+ '../ext/Unicode-Normalize' => 1,
+ );
+
if ($::do_nothing) {
return 1;
}
#BEGIN { require '../lib/warnings.pm'; "warnings"->import() };
delete $ENV{PERL5LIB};
+delete $ENV{PERLLIB};
+delete $ENV{PERL5OPT};
# remove empty elements due to insertion of empty symbols via "''p1'" syntax
@ARGV = grep($_,@ARGV) if $^O eq 'VMS';
our $show_elapsed_time = $ENV{HARNESS_TIMER} || 0;
-# Cheesy version of Getopt::Std. Maybe we should replace it with that.
+# Cheesy version of Getopt::Std. We can't replace it with that, because we
+# can't rely on require working.
{
my @argv = ();
foreach my $idx (0..$#ARGV) {
$ENV{EMXSHELL} = 'sh'; # For OS/2
-# Roll your own File::Find!
if ($show_elapsed_time) { require Time::HiRes }
my %skip = (
'.svn' => 1,
);
+# Roll your own File::Find!
sub _find_tests {
my($dir) = @_;
opendir DIR, $dir or die "Trouble opening $dir: $!";
my $switch = "";
if ($first_line =~ /#!.*\bperl.*\s-\w*([tT])/) {
- $switch = qq{"-$1"};
+ $switch = "-$1";
} else {
if ($::taintwarn) {
# not all tests are expected to pass with this option
- $switch = '"-t"';
+ $switch = '-t';
} else {
$switch = '';
}
}
}
- return { file => $file_opts, switch => $switch };
-}
-
-# directories with special sets of test switches
-my %dir_to_switch =
- (base => '',
- comp => '',
- run => '',
- );
-
-sub _run_test {
- my($test, $type) = @_;
-
- my $options = _scan_test($test, $type);
+ close $script;
my $perl = './perl';
my $lib = '../lib';
- $test =~ /^([^\/]+)/;
+ my $run_dir;
+ my $return_dir;
- my $testswitch = $dir_to_switch{$1};
+ $test =~ /^(.+)\/[^\/]+/;
+ my $dir = $1;
+ my $testswitch = $dir_to_switch{$dir};
if (!defined $testswitch) {
- $testswitch = '-I. -MTestInit'; # -T will remove . from @INC
+ if ($test =~ s!^(\.\./ext/[^/]+)/t!t!) {
+ $run_dir = $1;
+ $return_dir = '../../t';
+ $lib = '../../lib';
+ $perl = '../../t/perl';
+ $testswitch = "-I../.. -MTestInit=U2T,A";
+ if ($temp_no_core{$run_dir}) {
+ $testswitch = $testswitch . ',NC';
+ }
+ } else {
+ $testswitch = '-I.. -MTestInit'; # -T will remove . from @INC
+ }
}
my $utf8 = $::with_utf8 ? '-I$lib -Mutf8' : '';
- my $results;
+ return {
+ perl => $perl,
+ lib => $lib,
+ test => $test,
+ run_dir => $run_dir,
+ return_dir => $return_dir,
+ testswitch => $testswitch,
+ utf8 => $utf8,
+ file => $file_opts,
+ switch => $switch,
+ };
+}
+
+sub _cmd {
+ my($options, $type) = @_;
+
+ my $test = $options->{test};
+
+ my $cmd;
if ($type eq 'deparse') {
- my $deparse_cmd =
- "$perl $testswitch $options->{switch} -I$lib -MO=-qq,Deparse,-sv1.,".
+ my $perl = "$options->{perl} $options->{testswitch}";
+ my $lib = $options->{lib};
+
+ $cmd = (
+ "$perl $options->{switch} -I$lib -MO=-qq,Deparse,-sv1.,".
"-l$::deparse_opts$options->{file} ".
"$test > $test.dp ".
- "&& $perl $testswitch $options->{switch} -I$lib $test.dp |";
- open($results, $deparse_cmd)
- or print "can't deparse '$deparse_cmd': $!.\n";
+ "&& $perl $options->{switch} -I$lib $test.dp"
+ );
}
elsif ($type eq 'perl') {
- my $perl = $ENV{PERL} || $perl;
+ my $perl = $options->{perl};
my $redir = $^O eq 'VMS' ? '2>&1' : '';
if ($ENV{PERL_VALGRIND}) {
my $vg_opts = $ENV{VG_OPTS}
// "--suppressions=perl.supp --leak-check=yes "
. "--leak-resolution=high --show-reachable=yes "
- . "--num-callers=50";
+ . "--num-callers=50";
$perl = "$valgrind --log-fd=3 $vg_opts $perl";
$redir = "3>$Valgrind_Log";
}
- my $run = $perl . _quote_args("$testswitch $options->{switch} $utf8")
- . " $test $redir|";
- open($results, $run) or print "can't run '$run': $!.\n";
+ my $args = "$options->{testswitch} $options->{switch} $options->{utf8}";
+ $cmd = $perl . _quote_args($args) . " $test $redir";
+ }
+
+ return $cmd;
+}
+
+sub _before_fork {
+ my ($options) = @_;
+
+ if ($options->{run_dir}) {
+ my $run_dir = $options->{run_dir};
+ chdir $run_dir or die "Can't chdir to '$run_dir': $!";
+ }
+
+ return;
+}
+
+sub _after_fork {
+ my ($options) = @_;
+
+ if ($options->{return_dir}) {
+ my $return_dir = $options->{return_dir};
+ chdir $return_dir
+ or die "Can't chdir from '$options->{run_dir}' to '$return_dir': $!";
}
+ return;
+}
+
+sub _run_test {
+ my($harness, $test, $type) = @_;
+ if (!defined $type) {
+ # To conform to the interface expected by exec in TAP::Harness
+ $type = 'perl';
+ }
+
+ my $options = _scan_test($test, $type);
+
+ $test = $options->{test}; # Might have changed if we're in ext/Foo
+
+ _before_fork($options);
+
+ my $cmd = _cmd($options, $type);
+
+ open(my $results, "$cmd |") or print "can't run '$cmd': $!.\n";
+
+ _after_fork($options);
+
# Our environment may force us to use UTF-8, but we can't be sure that
# anything we're reading from will be generating (well formed) UTF-8
# This may not be the best way - possibly we should unset ${^OPEN} up
my @results;
my $mani = '../MANIFEST';
if (open(MANI, $mani)) {
- while (<MANI>) { # similar code in t/harness
+ while (<MANI>) {
if (m!^(ext/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
my $t = $1;
my $extension = $2;
$te = '';
}
- my $results = _run_test($test, $type);
+ my $results = _run_test(undef, $test, $type);
my $failure;
my $next = 0;