From: Michael G. Schwern Date: Mon, 2 Mar 2009 00:55:01 +0000 (-0800) Subject: Refactoring to move the code to read the test for special options into its own function. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3fd4b35989;p=p5sagit%2Fp5-mst-13.2.git Refactoring to move the code to read the test for special options into its own function. Get the hell out of the way so I can read this mess. [ammended slightly by Nicholas Clark to keep require strict commented out] --- diff --git a/t/TEST b/t/TEST index d333c84..776bf01 100755 --- a/t/TEST +++ b/t/TEST @@ -95,6 +95,41 @@ sub _find_tests { } } + +# Scan the text of the test program to find switches and special options +# we might need to apply. +sub _scan_test { + my($test, $type) = @_; + + open(my $script, "<", $test) or die "Can't read $test.\n"; + my $first_line = <$script>; + + $first_line =~ tr/\0//d if $::with_utf16; + + my $switch = ""; + if ($first_line =~ /#!.*\bperl.*\s-\w*([tT])/) { + $switch = qq{"-$1"}; + } else { + if ($::taintwarn) { + # not all tests are expected to pass with this option + $switch = '"-t"'; + } else { + $switch = ''; + } + } + + my $file_opts = ""; + if ($type eq 'deparse') { + # Look for #line directives which change the filename + while (<$script>) { + $file_opts .= ",-f$3$4" + if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/; + } + } + + return { file => $file_opts, switch => $switch }; +} + sub _quote_args { my ($args) = @_; my $argstring = ''; @@ -279,44 +314,16 @@ EOT # XXX DAPM %OVER not defined anywhere # $test = $OVER{$test} if exists $OVER{$test}; - open(SCRIPT,"<",$test) or die "Can't read $test.\n"; - $_ =