Skip to content

Commit 792dba7

Browse files
committed
Fix closing stdin in TestLib.pm
Commit 9af34f3 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
1 parent 553d2ec commit 792dba7

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/test/perl/TestLib.pm

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ TestLib - helper module for writing PostgreSQL's C<prove> tests.
2121
2222
# Miscellanea
2323
print "on Windows" if $TestLib::windows_os;
24+
print "IO::Pty is available" if $TestLib::have_io_pty;
2425
my $path = TestLib::perl2host($backup_dir);
2526
ok(check_mode_recursive($stream_dir, 0700, 0600),
2627
"check stream dir permissions");
@@ -83,9 +84,10 @@ our @EXPORT = qw(
8384
command_checks_all
8485
8586
$windows_os
87+
$have_io_pty
8688
);
8789

88-
our ($windows_os, $tmp_check, $log_path, $test_logfile);
90+
our ($windows_os, $tmp_check, $log_path, $test_logfile, $have_io_pty);
8991

9092
my @no_stdin;
9193

@@ -119,6 +121,9 @@ BEGIN
119121
require Win32API::File;
120122
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
121123
}
124+
125+
eval { require IO::Pty; };
126+
$have_io_pty = 1 unless $@;
122127
}
123128

124129
=pod
@@ -133,6 +138,12 @@ Set to true when running under Windows, except on Cygwin.
133138
134139
=back
135140
141+
=item C<$have_io_pty>
142+
143+
Set to true when IO::Pty is available.
144+
145+
=back
146+
136147
=cut
137148

138149
INIT
@@ -182,18 +193,17 @@ INIT
182193
autoflush $testlog 1;
183194

184195
# Settings to close stdin for certain commands.
185-
# On non-Windows, use a pseudo-terminal, so that libraries like openssl
186-
# which open the tty if they think stdin isn't one for a password
187-
# don't block. Windows doesn't have ptys, so just provide an empty
188-
# string for stdin.
189-
if ($windows_os)
196+
# If IO::Pty is present, use a pseudo-terminal, so that libraries like
197+
# openssl which open the tty if they think stdin isn't one for a password
198+
# don't block. Elsewhere just provide an empty string for stdin.
199+
if ($have_io_pty)
190200
{
191-
@no_stdin = ('<', \"");
201+
use charnames ':full';
202+
@no_stdin = ('<pty<', \"\N{END OF TRANSMISSION}");
192203
}
193204
else
194205
{
195-
use charnames ':full';
196-
@no_stdin = ('<pty<', \"\N{END OF TRANSMISSION}");
206+
@no_stdin = ('<', \"");
197207
}
198208
}
199209

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy