This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
test.pl's runperl() can now optionally redirect STDIN from /dev/null
authorNicholas Clark <nick@ccl4.org>
Wed, 7 Aug 2013 10:23:57 +0000 (12:23 +0200)
committerNicholas Clark <nick@ccl4.org>
Sun, 11 Aug 2013 14:01:22 +0000 (16:01 +0200)
commit53f2736e93810ee2954fb2a08b4d43366caae935
tree44867278ec72bd598fbd42027b4f20b03796f816
parent7682ed921500841e8c45793174078f853106a4c4
test.pl's runperl() can now optionally redirect STDIN from /dev/null

There is existing code to pipe fixed input to the test perl's STDIN, which
means that STDIN can be made to be an immediate end-of-file by giving an
empty string. However, it turns out that on platforms which use ksh as
/bin/sh, ksh's setup of shell pipelines differs from a traditional Bourne
shell (and bash), using one less process in total, with the result that the
test perl starts with a child process already - the process piping to its
STDIN. This unexpected child process confuses tests for wait() which are
only expecting to see return values from processes that the test script
itself started.

As the problem case is specifically for setting up STDIN to be at EOF, it's
easier to it by enhancing test.pl's runperl() to be able to redirect STDIN
from the null device than by making the tests themselves more complex.
This approach also avoids spawning a process for quite a few of the tests.
Fortuitously it seems that the string /dev/null is portable enough to work
with the command line parsing code on VMS and Win32 too.

Thanks to Zefram for helping diagnose the problem.

It turns out that this also fixes regressions on VMS, where the pipe
implementation returns the exit code of the process at the front of the
pipeline, not the end. The result is that adding a pipeline messes up any
test using OPTION FATAL to check exit status.
t/test.pl