test_terminal: redirect child process' stdin to a pty
commit18d8c26930acbba1627d2a8b7323be30ac2bd9bb
authorPaul Tan <pyokagan@gmail.com>
Tue, 4 Aug 2015 14:08:49 +0000 (4 22:08 +0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Aug 2015 17:33:46 +0000 (12 10:33 -0700)
tree34999601b1c55a10394a901b70827e2c754e0c34
parente97a5e765db06995c3b027a5d7dceb6b4f2cba02
test_terminal: redirect child process' stdin to a pty

When resuming, git-am detects if we are trying to feed it patches or not
by checking if stdin is a TTY.

However, the test library redirects stdin to /dev/null. This makes it
difficult, for instance, to test the behavior of "git am -3" when
resuming, as git-am will think we are trying to feed it patches and
error out.

Support this use case by extending test-terminal.perl to create a
pseudo-tty for the child process' standard input as well.

Note that due to the way the code is structured, the child's stdin
pseudo-tty will be closed when we finish reading from our stdin. This
means that in the common case, where our stdin is attached to /dev/null,
the child's stdin pseudo-tty will be closed immediately. Some operations
like isatty(), which git-am uses, require the file descriptor to be
open, and hence if the success of the command depends on such functions,
test_terminal's stdin should be redirected to a source with large amount
of data to ensure that the child's stdin is not closed, e.g.

test_terminal git am --3way </dev/zero

Cc: Jonathan Nieder <jrnieder@gmail.com>
Cc: Jeff King <peff@peff.net>
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/test-terminal.perl