Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Avoid odd portability problem in TestLib.pm's slurp_file function.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 8 Dec 2015 21:58:05 +0000 (16:58 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 8 Dec 2015 21:58:05 +0000 (16:58 -0500)
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.

src/test/perl/TestLib.pm

index 478f855462ff05632c3a8d1caa6aa0c56544561e..8eb27df796ff9ef7f233ff593f3f9d19c37e6d67 100644 (file)
@@ -242,9 +242,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;
 }