Avoid odd portability problem in TestLib.pm's slurp_file function.

For unclear reasons, this function doesn't always read the expected data
in some old Perl versions.  Rewriting it to avoid use of ARGV seems to
dodge the problem, and this version is clearer anyway if you ask me.

In passing, also improve error message in adjacent append_to_file function.
This commit is contained in:
Tom Lane 2015-12-08 16:58:05 -05:00
parent d5563d7df9
commit 938d797b84
1 changed files with 7 additions and 4 deletions

View File

@ -158,9 +158,12 @@ sub slurp_dir
sub slurp_file
{
my ($filename) = @_;
local $/;
local @ARGV = @_;
my $contents = <>;
open(my $in, '<', $filename)
or die "could not read \"$filename\": $!";
my $contents = <$in>;
close $in;
$contents =~ s/\r//g if $Config{osname} eq 'msys';
return $contents;
}
@ -168,8 +171,8 @@ sub slurp_file
sub append_to_file
{
my ($filename, $str) = @_;
open my $fh, ">>", $filename or die "could not open \"$filename\": $!";
open my $fh, ">>", $filename
or die "could not write \"$filename\": $!";
print $fh $str;
close $fh;
}