diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2019-11-26 16:23:00 -0500 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2019-11-26 16:32:06 -0500 |
commit | 792dba73c8f30528e51c4967d3be8ec4bdc5234b (patch) | |
tree | a984e68ab1f6fe5a86ff962c572771cf2872ca09 | |
parent | 553d2ec2710be5ae304c40134643c8f6d754af67 (diff) | |
download | postgresql-792dba73c8f30528e51c4967d3be8ec4bdc5234b.tar.gz postgresql-792dba73c8f30528e51c4967d3be8ec4bdc5234b.zip |
Fix closing stdin in TestLib.pm
Commit 9af34f3c6b naively assumed that all non-windows platforms would
have pseudoterminals and that perl would have IO::Pty. Such is not the
case. Instead of assumung anything, test for the presence of IO::Pty and
only use code that might depend on it if it's present. The test result is
exposed in $TestLib::have_io_pty so that it can be conveniently used in
SKIP tests.
Discussion: https://postgr.es/m/20191126044110.GB5435@paquier.xyz
-rw-r--r-- | src/test/perl/TestLib.pm | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm index 18b4ce35c20..3f89d753102 100644 --- a/src/test/perl/TestLib.pm +++ b/src/test/perl/TestLib.pm @@ -21,6 +21,7 @@ TestLib - helper module for writing PostgreSQL's C<prove> tests. # Miscellanea print "on Windows" if $TestLib::windows_os; + print "IO::Pty is available" if $TestLib::have_io_pty; my $path = TestLib::perl2host($backup_dir); ok(check_mode_recursive($stream_dir, 0700, 0600), "check stream dir permissions"); @@ -83,9 +84,10 @@ our @EXPORT = qw( command_checks_all $windows_os + $have_io_pty ); -our ($windows_os, $tmp_check, $log_path, $test_logfile); +our ($windows_os, $tmp_check, $log_path, $test_logfile, $have_io_pty); my @no_stdin; @@ -119,6 +121,9 @@ BEGIN require Win32API::File; Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle)); } + + eval { require IO::Pty; }; + $have_io_pty = 1 unless $@; } =pod @@ -133,6 +138,12 @@ Set to true when running under Windows, except on Cygwin. =back +=item C<$have_io_pty> + +Set to true when IO::Pty is available. + +=back + =cut INIT @@ -182,18 +193,17 @@ INIT autoflush $testlog 1; # Settings to close stdin for certain commands. - # On non-Windows, use a pseudo-terminal, so that libraries like openssl - # which open the tty if they think stdin isn't one for a password - # don't block. Windows doesn't have ptys, so just provide an empty - # string for stdin. - if ($windows_os) + # If IO::Pty is present, use a pseudo-terminal, so that libraries like + # openssl which open the tty if they think stdin isn't one for a password + # don't block. Elsewhere just provide an empty string for stdin. + if ($have_io_pty) { - @no_stdin = ('<', \""); + use charnames ':full'; + @no_stdin = ('<pty<', \"\N{END OF TRANSMISSION}"); } else { - use charnames ':full'; - @no_stdin = ('<pty<', \"\N{END OF TRANSMISSION}"); + @no_stdin = ('<', \""); } } |