Skip to content

Commit e674c17

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 996621e commit e674c17

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

t/lib-terminal.sh

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,19 @@
11
#!/bin/sh
22

33
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
85
test_have_prereq PERL &&
96
"$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl \
107
sh -c "test -t 1 && test -t 2"
118
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+
}
1318
fi
1419
'
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-
}

0 commit comments

Comments
 (0)