Skip to content

Commit f6203e9

Browse files
committed
t/test.pl: Add fresh_perl() function
This will be useful for cases where the results don't readily fall into fresh_perl_is and fresh_perl_like, such as when a bunch of massaging of the results is needed before it is convenient to test them. fresh_perl_like() could be used, but in the case of failure there could be lines and lines of noise output.
1 parent f0858b7 commit f6203e9

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

t/test.pl

+21-4
Original file line numberDiff line numberDiff line change
@@ -953,11 +953,16 @@ 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
957957
my $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.
961966

962967
# Given the choice of the mis-parsable {}
963968
# (we want an anon hash, but a borked lexer might think that it's a block)
@@ -975,7 +980,8 @@ sub _fresh_perl {
975980
close TEST or die "Cannot close $tmpfile: $!";
976981

977982
my $results = runperl(%$runperl_args);
978-
my $status = $?;
983+
my $status = $?; # Not necessary to save this, but it makes it clear to
984+
# future maintainers.
979985

980986
# Clean up the results into something a bit more predictable.
981987
$results =~ s/\n+$//;
@@ -994,6 +1000,17 @@ sub _fresh_perl {
9941000
$results =~ s/\n\n/\n/g;
9951001
}
9961002

1003+
$? = $status;
1004+
return $results;
1005+
}
1006+
1007+
1008+
sub _fresh_perl {
1009+
my($prog, $action, $expect, $runperl_args, $name) = @_;
1010+
1011+
my $results = fresh_perl($prog, $runperl_args);
1012+
my $status = $?;
1013+
9971014
# Use the first line of the program as a name if none was given
9981015
unless( $name ) {
9991016
($first_line, $name) = $prog =~ /^((.{1,50}).*)/;

0 commit comments

Comments
 (0)