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

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 <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 17, 2010 at 02:36 UTC cc4e48fc1eafdb9bec037f10c22708a26fd25ef6
3 files changed +29 -30
t/lib-terminal.sh new
+28
@@ -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
+1 -30
@@ -4,42 +4,13 @@ test_description='Test automatic use of a pager.'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-pager.sh
7 +. "$TEST_DIRECTORY"/lib-terminal.sh
8
9 cleanup_fail() {
10 echo >&2 cleanup failed
11 (exit 1)
12 }
13
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 -
14 test_expect_success 'setup' '
15 unset GIT_PAGER GIT_PAGER_IN_USE;
16 test_might_fail git config --unset core.pager &&
t/test-terminal.perl renamed