3 test_description
='Test automatic use of a pager.'
8 echo >&2 cleanup failed
12 test_expect_success
'set up terminal for tests' '
13 rm -f stdout_is_tty ||
20 test_have_prereq PERL &&
21 "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \
28 if test -e stdout_is_tty
30 test_terminal
() { "$@"; }
32 elif test -e test_terminal_works
35 "$PERL_PATH" "$TEST_DIRECTORY"/t7006
/test-terminal.perl
"$@"
39 say no usable terminal
, so skipping some tests
42 test_expect_success
'setup' '
43 unset GIT_PAGER GIT_PAGER_IN_USE;
44 test_might_fail git config --unset core.pager &&
46 PAGER="cat >paginated.out" &&
52 test_expect_success TTY
'some commands use a pager' '
53 rm -f paginated.out ||
56 test_terminal git log &&
60 test_expect_success TTY
'some commands do not use a pager' '
61 rm -f paginated.out ||
64 test_terminal git rev-list HEAD &&
65 ! test -e paginated.out
68 test_expect_success
'no pager when stdout is a pipe' '
69 rm -f paginated.out ||
73 ! test -e paginated.out
76 test_expect_success
'no pager when stdout is a regular file' '
77 rm -f paginated.out ||
81 ! test -e paginated.out
84 test_expect_success TTY
'git --paginate rev-list uses a pager' '
85 rm -f paginated.out ||
88 test_terminal git --paginate rev-list HEAD &&
92 test_expect_success
'no pager even with --paginate when stdout is a pipe' '
93 rm -f file paginated.out ||
96 git --paginate log | cat &&
97 ! test -e paginated.out
100 test_expect_success TTY
'no pager with --no-pager' '
101 rm -f paginated.out ||
104 test_terminal git --no-pager log &&
105 ! test -e paginated.out
108 # A colored commit log will begin with an appropriate ANSI escape
109 # for the first color; the text "commit" comes later.
112 ! expr "$firstline" : "[a-zA-Z]" >/dev
/null
115 test_expect_success
'tests can detect color' '
116 rm -f colorful.log colorless.log ||
119 git log --no-color >colorless.log &&
120 git log --color >colorful.log &&
121 ! colorful colorless.log &&
122 colorful colorful.log
125 test_expect_success
'no color when stdout is a regular file' '
126 rm -f colorless.log &&
127 git config color.ui auto ||
130 git log >colorless.log &&
131 ! colorful colorless.log
134 test_expect_success TTY
'color when writing to a pager' '
135 rm -f paginated.out &&
136 git config color.ui auto ||
142 test_terminal git log
144 colorful paginated.out
147 test_expect_success
'color when writing to a file intended for a pager' '
148 rm -f colorful.log &&
149 git config color.ui auto ||
154 GIT_PAGER_IN_USE=true &&
155 export TERM GIT_PAGER_IN_USE &&
156 git log >colorful.log
158 colorful colorful.log
161 test_expect_success
'determine default pager' '
162 unset PAGER GIT_PAGER;
163 test_might_fail git config --unset core.pager ||
166 less=$(git var GIT_PAGER) &&
170 if expr "$less" : '[a-z][a-z]*$' >/dev
/null
&& test_have_prereq TTY
172 test_set_prereq SIMPLEPAGER
175 # Use this helper to make it easy for the caller of your
176 # terminal-using function to specify whether it should fail.
182 # $test_expectation "$cmd - behaves well" "
189 # then your test can be used like this:
191 # your_test expect_(success|failure) [test_must_fail] 'git foo'
194 test_expectation
="test_$1"
196 if test "$1" = test_must_fail
198 full_command
="test_must_fail test_terminal "
201 full_command
="test_terminal "
204 full_command
="$full_command $1"
207 test_default_pager
() {
210 $test_expectation SIMPLEPAGER
"$cmd - default pager is used by default" "
211 unset PAGER GIT_PAGER;
212 test_might_fail git config --unset core.pager &&
213 rm -f default_pager_used ||
216 cat >\$less <<-\EOF &&
218 wc >default_pager_used
226 test -e default_pager_used
230 test_PAGER_overrides
() {
233 $test_expectation TTY
"$cmd - PAGER overrides default pager" "
235 test_might_fail git config --unset core.pager &&
239 PAGER='wc >PAGER_used' &&
246 test_core_pager_overrides
() {
248 used_if_wanted
='overrides PAGER'
252 test_local_config_ignored
() {
254 used_if_wanted
='is not used'
261 $test_expectation TTY
"$cmd - repository-local core.pager setting $used_if_wanted" "
263 rm -f core.pager_used ||
268 git config core.pager 'wc >core.pager_used' &&
270 ${if_local_config}test -e core.pager_used
274 test_core_pager_subdir
() {
276 used_if_wanted
='overrides PAGER'
277 test_pager_subdir_helper
"$@"
280 test_no_local_config_subdir
() {
282 used_if_wanted
='is not used'
283 test_pager_subdir_helper
"$@"
286 test_pager_subdir_helper
() {
289 $test_expectation TTY
"$cmd - core.pager $used_if_wanted from subdirectory" "
291 rm -f core.pager_used &&
296 stampname=\$(pwd)/core.pager_used &&
297 export PAGER stampname &&
298 git config core.pager 'wc >\"\$stampname\"' &&
304 ${if_local_config}test -e core.pager_used
308 test_GIT_PAGER_overrides
() {
311 $test_expectation TTY
"$cmd - GIT_PAGER overrides core.pager" "
312 rm -f GIT_PAGER_used ||
315 git config core.pager wc &&
316 GIT_PAGER='wc >GIT_PAGER_used' &&
319 test -e GIT_PAGER_used
323 test_doesnt_paginate
() {
326 $test_expectation TTY
"no pager for '$cmd'" "
327 rm -f GIT_PAGER_used ||
330 GIT_PAGER='wc >GIT_PAGER_used' &&
333 ! test -e GIT_PAGER_used
337 test_default_pager expect_success
'git log'
338 test_PAGER_overrides expect_success
'git log'
339 test_core_pager_overrides expect_success
'git log'
340 test_core_pager_subdir expect_success
'git log'
341 test_GIT_PAGER_overrides expect_success
'git log'
343 test_default_pager expect_success
'git -p log'
344 test_PAGER_overrides expect_success
'git -p log'
345 test_core_pager_overrides expect_success
'git -p log'
346 test_core_pager_subdir expect_success
'git -p log'
347 test_GIT_PAGER_overrides expect_success
'git -p log'
349 test_default_pager expect_success test_must_fail
'git -p'
350 test_PAGER_overrides expect_success test_must_fail
'git -p'
351 test_local_config_ignored expect_failure test_must_fail
'git -p'
352 test_no_local_config_subdir expect_success test_must_fail
'git -p'
353 test_GIT_PAGER_overrides expect_success test_must_fail
'git -p'
355 test_doesnt_paginate expect_success test_must_fail
'git -p nonsense'