From: Vincent Pit Date: Mon, 31 Aug 2009 12:07:23 +0000 (+0200) Subject: Move more test options discovery from _run_test() to _scan_test() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=491c95723f4cf3d8c4bab14a98d1a073bcfa3c1e;p=p5sagit%2Fp5-mst-13.2.git Move more test options discovery from _run_test() to _scan_test() --- diff --git a/t/TEST b/t/TEST index 3c16180..39333af 100755 --- a/t/TEST +++ b/t/TEST @@ -164,37 +164,26 @@ sub _scan_test { } } - return { file => $file_opts, switch => $switch }; -} - -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); - my $return_dir; + close $script; my $perl = './perl'; my $lib = '../lib'; + my $run_dir; + my $return_dir; + $test =~ /^(.+)\/[^\/]+/; my $dir = $1; - my $ext_dir; - my $testswitch = $dir_to_switch{$dir}; if (!defined $testswitch) { if ($test =~ s!^(\.\./ext/[^/]+)/t!t!) { - $ext_dir = $1; + $run_dir = $1; $return_dir = '../../t'; $lib = '../../lib'; $perl = '../../t/perl'; $testswitch = "-I../.. -MTestInit=U2T,A"; - if ($temp_no_core{$ext_dir}) { + if ($temp_no_core{$run_dir}) { $testswitch = $testswitch . ',NC'; } - chdir $ext_dir or die "Can't chdir to '$ext_dir': $!"; } else { $testswitch = '-I.. -MTestInit'; # -T will remove . from @INC } @@ -202,17 +191,49 @@ sub _run_test { my $utf8 = $::with_utf8 ? '-I$lib -Mutf8' : ''; + 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 _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 + + if ($options->{run_dir}) { + my $run_dir = $options->{run_dir}; + chdir $run_dir or die "Can't chdir to '$run_dir': $!"; + } + my $results; if ($type eq 'deparse') { + my $perl = "$options->{perl} $options->{testswitch}"; + my $lib = $options->{lib}; my $deparse_cmd = - "$perl $testswitch $options->{switch} -I$lib -MO=-qq,Deparse,-sv1.,". + "$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 |"; + "&& $perl $options->{switch} -I$lib $test.dp |"; open($results, $deparse_cmd) or print "can't deparse '$deparse_cmd': $!.\n"; } elsif ($type eq 'perl') { + my $perl = $options->{perl}; my $redir = $^O eq 'VMS' ? '2>&1' : ''; if ($ENV{PERL_VALGRIND}) { @@ -225,14 +246,15 @@ sub _run_test { $redir = "3>$Valgrind_Log"; } - my $run = $perl . _quote_args("$testswitch $options->{switch} $utf8") - . " $test $redir|"; + my $args = "$options->{testswitch} $options->{switch} $options->{utf8}"; + my $run = $perl . _quote_args($args) . " $test $redir|"; open($results, $run) or print "can't run '$run': $!.\n"; } - if ($return_dir) { + if ($options->{return_dir}) { + my $return_dir = $options->{return_dir}; chdir $return_dir - or die "Can't chdir from '$ext_dir' to '$return_dir': $!"; + or die "Can't chdir from '$options->{run_dir}' to '$return_dir': $!"; } # Our environment may force us to use UTF-8, but we can't be sure that