diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2020-12-15 10:00:18 -0500 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2020-12-15 10:29:33 -0500 |
commit | da7edca4630c5bcf7c0f0f5819ab6fb020d3c845 (patch) | |
tree | 7f511cfc91177998047cf0cba1b69f69a5a85fd2 /src | |
parent | 133a0906d5bf529ac2898c24b98ed87db1c6284d (diff) |
Use native methods to open input in TestLib::slurp_file on Windows.
This is a backport of commits 114541d58e and 6f59826f0 to the remaining
live branches.
Diffstat (limited to 'src')
-rw-r--r-- | src/test/perl/TestLib.pm | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm index b606e1b173f..6dbf3e6fc3b 100644 --- a/src/test/perl/TestLib.pm +++ b/src/test/perl/TestLib.pm @@ -44,7 +44,17 @@ use SimpleTee; use Test::More; -our $windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys'; +our $windows_os; + +BEGIN +{ + $windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys'; + if ($windows_os) + { + require Win32API::File; + Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle)); + } +} # Open log file. For each test, the log file name uses the name of the # file launching this module, without the .pl suffix. @@ -277,10 +287,24 @@ sub slurp_file { my ($filename) = @_; local $/; - open(my $in, '<', $filename) - or die "could not read \"$filename\": $!"; - my $contents = <$in>; - close $in; + my $contents; + if ($Config{osname} ne 'MSWin32') + { + open(my $in, '<', $filename) + or die "could not read \"$filename\": $!"; + $contents = <$in>; + close $in; + } + else + { + my $fHandle = createFile($filename, "r", "rwd") + or die "could not open \"$filename\": $^E"; + OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r') + or die "could not read \"$filename\": $^E\n"; + $contents = <$fh>; + CloseHandle($fHandle) + or die "could not close \"$filename\": $^E\n"; + } $contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys'; return $contents; } |