aboutsummaryrefslogtreecommitdiff
path: root/src/test/perl/TestLib.pm
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2017-07-26 17:15:59 -0400
committerAndrew Dunstan <andrew@dunslane.net>2017-07-26 22:46:55 -0400
commitefd7f8e36553cd32e445061cbbc80d32028f4248 (patch)
tree54eb43e7252b67c9673e0c5b11d8fdbabd6a8351 /src/test/perl/TestLib.pm
parent50d2426f5a6d6a47da9ea67be55c3e89069e7bec (diff)
downloadpostgresql-efd7f8e36553cd32e445061cbbc80d32028f4248.tar.gz
postgresql-efd7f8e36553cd32e445061cbbc80d32028f4248.zip
Work around Msys weakness in Testlib.pm's command_like()
When output of IPC::Run::run () is redirected to scalar references, in certain circumstances the Msys perl does not correctly detect that the end of file has been seen, making the test hang indefinitely. One such circumstance is when the command is 'pg_ctl start', and such a change was made in commit f13ea95f9e. The workaround, which only applies on MSys, is to redirect the output to temporary files and then read them in when the process has finished. Patch by me, reviewed and tweaked by Tom Lane.
Diffstat (limited to 'src/test/perl/TestLib.pm')
-rw-r--r--src/test/perl/TestLib.pm19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm
index fe09689fec2..bff6b3aed27 100644
--- a/src/test/perl/TestLib.pm
+++ b/src/test/perl/TestLib.pm
@@ -37,6 +37,7 @@ our @EXPORT = qw(
program_version_ok
program_options_handling_ok
command_like
+ command_like_safe
command_fails_like
$windows_os
@@ -300,6 +301,24 @@ sub command_like
like($stdout, $expected_stdout, "$test_name: matches");
}
+sub command_like_safe
+{
+ # Doesn't rely on detecting end of file on the file descriptors,
+ # which can fail, causing the process to hang, notably on Msys
+ # when used with 'pg_ctl start'
+ my ($cmd, $expected_stdout, $test_name) = @_;
+ my ($stdout, $stderr);
+ my $stdoutfile = File::Temp->new();
+ my $stderrfile = File::Temp->new();
+ print("# Running: " . join(" ", @{$cmd}) . "\n");
+ my $result = IPC::Run::run $cmd, '>', $stdoutfile, '2>', $stderrfile;
+ $stdout = slurp_file($stdoutfile);
+ $stderr = slurp_file($stderrfile);
+ ok($result, "$test_name: exit code 0");
+ is($stderr, '', "$test_name: no stderr");
+ like($stdout, $expected_stdout, "$test_name: matches");
+}
+
sub command_fails_like
{
my ($cmd, $expected_stderr, $test_name) = @_;