@matheusbsbs / matheus-bagliano / commits / e674c17db2
Fork 0

test_terminal: ensure redirections work reliably

For terminal tests that capture output/stderr, the TTY prerequisite warning does not quite work for commands like test_terminal foo >out 2>err because the warning gets "swallowed" up by the redirection that's supposed only to be done by the subcommand. Even worse, the outcome depends on whether stdout was already a terminal (in which case test_terminal is a noop) or not (in which case test_terminal introduces a pseudo-tty in the middle of the pipeline). $ test_terminal.perl sh -c 'test -t 1 && echo >&2 YES' >out YES $ sh -c 'test -t 1 && echo >&2 YES' >out $ So: - use the test_terminal script even when running with "-v". - skip tests that require a terminal when the test_terminal script is unusable because IO::Pty is not installed. - write the "need to declare TTY prerequisite" message to fd 4, where it will be printed when running tests with -v, rather than being swallowed up by an unrelated redireciton. Noticed-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Oct 16, 2010 at 19:38 UTC e674c17db25750f14c1dd1d8f588eb3135b5cea9
1 file changed +10 -28
t/lib-terminal.sh
+10 -28
@@ -1,37 +1,19 @@
1 #!/bin/sh
2
3 test_expect_success 'set up terminal for tests' '
4 - if test -t 1 && test -t 2
5 - then
6 - >have_tty
7 - elif
4 + if
5 test_have_prereq PERL &&
6 "$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl \
7 sh -c "test -t 1 && test -t 2"
8 then
12 - >test_terminal_works
9 + test_set_prereq TTY &&
10 + test_terminal () {
11 + if ! test_declared_prereq TTY
12 + then
13 + echo >&4 "test_terminal: need to declare TTY prerequisite"
14 + return 127
15 + fi
16 + "$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl "$@"
17 + }
18 fi
19 '
15 -
16 -if test -e have_tty
17 -then
18 - test_terminal_() { "$@"; }
19 - test_set_prereq TTY
20 -elif test -e test_terminal_works
21 -then
22 - test_terminal_() {
23 - "$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl "$@"
24 - }
25 - test_set_prereq TTY
26 -else
27 - say "# no usable terminal, so skipping some tests"
28 -fi
29 -
30 -test_terminal () {
31 - if ! test_declared_prereq TTY
32 - then
33 - echo >&2 'test_terminal: need to declare TTY prerequisite'
34 - return 127
35 - fi
36 - test_terminal_ "$@"
37 -}