diff options
author | Tom Lane | 2015-12-08 21:58:05 +0000 |
---|---|---|
committer | Tom Lane | 2015-12-08 21:58:05 +0000 |
commit | 938d797b84467ebbaed432da72d1d7f7bb266110 (patch) | |
tree | 25f87ed115a4519bdc8e0dd3a226c0c4da191a3b | |
parent | d5563d7df94488bf0ab52ac0678e8a07e5b8297e (diff) |
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.
-rw-r--r-- | src/test/perl/TestLib.pm | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm index da67f33c7e..3d11cbb453 100644 --- a/src/test/perl/TestLib.pm +++ b/src/test/perl/TestLib.pm @@ -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; } |