@@ -652,7 +652,7 @@ sub _create_runperl { # Create the string to qx in runperl().
652652 $runperl = " $ENV {PERL_RUNPERL_DEBUG } $runperl " ;
653653 }
654654 unless ($args {nolib}) {
655- $runperl = $runperl . ' " -I../lib" '; # doublequotes because of VMS
655+ $runperl = $runperl . ' " -I../lib" " -I. " '; # doublequotes because of VMS
656656 }
657657 if ($args {switches}) {
658658 local $Level = 2;
@@ -953,11 +953,19 @@ sub register_tempfile {
953953 return $count ;
954954}
955955
956- # This is the temporary file for _fresh_perl
956+ # This is the temporary file for fresh_perl
957957my $tmpfile = tempfile();
958958
959- sub _fresh_perl {
960- my ($prog , $action , $expect , $runperl_args , $name ) = @_ ;
959+ sub fresh_perl {
960+ my ($prog , $runperl_args ) = @_ ;
961+
962+ # Run 'runperl' with the complete perl program contained in '$prog', and
963+ # arguments in the hash referred to by '$runperl_args'. The results are
964+ # returned, with $? set to the exit code. Unless overridden, stderr is
965+ # redirected to stdout.
966+
967+ die sprintf " Third argument to fresh_perl_.* must be hashref of args to fresh_perl (or {})"
968+ unless !(defined $runperl_args ) || ref ($runperl_args ) eq ' HASH' ;
961969
962970 # Given the choice of the mis-parsable {}
963971 # (we want an anon hash, but a borked lexer might think that it's a block)
@@ -970,12 +978,13 @@ sub _fresh_perl {
970978 $runperl_args -> {progfile } ||= $tmpfile ;
971979 $runperl_args -> {stderr } = 1 unless exists $runperl_args -> {stderr };
972980
973- open TEST, " > $tmpfile " or die " Cannot open $tmpfile : $! " ;
981+ open TEST, ' > ' , $tmpfile or die " Cannot open $tmpfile : $! " ;
974982 print TEST $prog ;
975983 close TEST or die " Cannot close $tmpfile : $! " ;
976984
977985 my $results = runperl(%$runperl_args );
978- my $status = $? ;
986+ my $status = $? ; # Not necessary to save this, but it makes it clear to
987+ # future maintainers.
979988
980989 # Clean up the results into something a bit more predictable.
981990 $results =~ s /\n +$// ;
@@ -994,6 +1003,17 @@ sub _fresh_perl {
9941003 $results =~ s /\n\n / \n / g ;
9951004 }
9961005
1006+ $? = $status ;
1007+ return $results ;
1008+ }
1009+
1010+
1011+ sub _fresh_perl {
1012+ my ($prog , $action , $expect , $runperl_args , $name ) = @_ ;
1013+
1014+ my $results = fresh_perl($prog , $runperl_args );
1015+ my $status = $? ;
1016+
9971017 # Use the first line of the program as a name if none was given
9981018 unless ( $name ) {
9991019 ($first_line , $name ) = $prog =~ / ^((.{1,50}).*)/ ;
@@ -1058,8 +1078,9 @@ sub fresh_perl_like {
10581078# Each program is source code to run followed by an "EXPECT" line, followed
10591079# by the expected output.
10601080#
1061- # The code to run may begin with a command line switch such as -w or -0777
1062- # (alphanumerics only), and may contain (note the '# ' on each):
1081+ # The first line of the code to run may be a command line switch such as -wE
1082+ # or -0777 (alphanumerics only; only one cluster, beginning with a minus is
1083+ # allowed). Later lines may contain (note the '# ' on each):
10631084# # TODO reason for todo
10641085# # SKIP reason for skip
10651086# # SKIP ?code to test if this should be skipped
@@ -1241,6 +1262,7 @@ sub run_multiple_progs {
12411262 open my $fh , ' >' , $tmpfile or die " Cannot open >$tmpfile : $! " ;
12421263 print $fh q{
12431264 BEGIN {
1265+ push @INC, '.';
12441266 open STDERR, '>&', STDOUT
12451267 or die "Can't dup STDOUT->STDERR: $!;";
12461268 }
0 commit comments