Skip to content

Commit 996621e

Browse files
jrngitster
authored andcommitted
test_terminal: catch use without TTY prerequisite
It is easy to forget to declare the TTY prerequisite when writing tests on a system where it would always be satisfied (because IO::Pty is installed; see v1.7.3-rc0~33^2, 2010-08-16 for example). Automatically detect this problem so there is no need to remember. test_terminal: need to declare TTY prerequisite test_must_fail: command not found: test_terminal echo hi test_terminal returns status 127 in this case to simulate not being available. Also replace the SIMPLEPAGERTTY prerequisite on one test with "SIMPLEPAGER,TTY", since (1) the latter is supported now and (2) the prerequisite detection relies on the TTY prereq being explicitly declared. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 05236a5 commit 996621e

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

t/lib-terminal.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,23 @@ test_expect_success 'set up terminal for tests' '
1515

1616
if test -e have_tty
1717
then
18-
test_terminal() { "$@"; }
18+
test_terminal_() { "$@"; }
1919
test_set_prereq TTY
2020
elif test -e test_terminal_works
2121
then
22-
test_terminal() {
22+
test_terminal_() {
2323
"$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl "$@"
2424
}
2525
test_set_prereq TTY
2626
else
2727
say "# no usable terminal, so skipping some tests"
2828
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+
}

t/t7006-pager.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,6 @@ test_expect_success 'color when writing to a file intended for a pager' '
184184
colorful colorful.log
185185
'
186186

187-
if test_have_prereq SIMPLEPAGER && test_have_prereq TTY
188-
then
189-
test_set_prereq SIMPLEPAGERTTY
190-
fi
191-
192187
# Use this helper to make it easy for the caller of your
193188
# terminal-using function to specify whether it should fail.
194189
# If you write
@@ -224,7 +219,7 @@ parse_args() {
224219
test_default_pager() {
225220
parse_args "$@"
226221

227-
$test_expectation SIMPLEPAGERTTY "$cmd - default pager is used by default" "
222+
$test_expectation SIMPLEPAGER,TTY "$cmd - default pager is used by default" "
228223
unset PAGER GIT_PAGER;
229224
test_might_fail git config --unset core.pager &&
230225
rm -f default_pager_used ||

0 commit comments

Comments
 (0)