Skip to content

Commit cc4e48f

Browse files
peffgitster
authored andcommitted
tests: factor out terminal handling from t7006
Other tests besides the pager ones may want to check how we handle output to a terminal. This patch makes the code reusable. Signed-off-by: Jeff King <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c752e7f commit cc4e48f

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

t/lib-terminal.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
test_expect_success 'set up terminal for tests' '
4+
if test -t 1
5+
then
6+
>stdout_is_tty
7+
elif
8+
test_have_prereq PERL &&
9+
"$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl \
10+
sh -c "test -t 1"
11+
then
12+
>test_terminal_works
13+
fi
14+
'
15+
16+
if test -e stdout_is_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

t/t7006-pager.sh

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,13 @@ test_description='Test automatic use of a pager.'
44

55
. ./test-lib.sh
66
. "$TEST_DIRECTORY"/lib-pager.sh
7+
. "$TEST_DIRECTORY"/lib-terminal.sh
78

89
cleanup_fail() {
910
echo >&2 cleanup failed
1011
(exit 1)
1112
}
1213

13-
test_expect_success 'set up terminal for tests' '
14-
rm -f stdout_is_tty ||
15-
cleanup_fail &&
16-
17-
if test -t 1
18-
then
19-
>stdout_is_tty
20-
elif
21-
test_have_prereq PERL &&
22-
"$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \
23-
sh -c "test -t 1"
24-
then
25-
>test_terminal_works
26-
fi
27-
'
28-
29-
if test -e stdout_is_tty
30-
then
31-
test_terminal() { "$@"; }
32-
test_set_prereq TTY
33-
elif test -e test_terminal_works
34-
then
35-
test_terminal() {
36-
"$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl "$@"
37-
}
38-
test_set_prereq TTY
39-
else
40-
say "# no usable terminal, so skipping some tests"
41-
fi
42-
4314
test_expect_success 'setup' '
4415
unset GIT_PAGER GIT_PAGER_IN_USE;
4516
test_might_fail git config --unset core.pager &&
File renamed without changes.

0 commit comments

Comments
 (0)