Documentation/config.txt: default gc.aggressiveWindow is 250, not 10
[git/git.git] / t / t7006-pager.sh
CommitLineData
60b6e220
JN
1#!/bin/sh
2
3test_description='Test automatic use of a pager.'
4
5. ./test-lib.sh
6
7rm -f stdout_is_tty
2d3ca216 8test_expect_success 'set up terminal for tests' '
60b6e220
JN
9 if test -t 1
10 then
11 : > stdout_is_tty
2d3ca216
JN
12 elif
13 test_have_prereq PERL &&
14 "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \
15 sh -c "test -t 1"
16 then
17 : > test_terminal_works
60b6e220
JN
18 fi
19'
20
21if test -e stdout_is_tty
22then
2d3ca216
JN
23 test_terminal() { "$@"; }
24 test_set_prereq TTY
25elif test -e test_terminal_works
26then
27 test_terminal() {
28 "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl "$@"
29 }
60b6e220
JN
30 test_set_prereq TTY
31else
2d3ca216 32 say no usable terminal, so skipping some tests
60b6e220
JN
33fi
34
35unset GIT_PAGER GIT_PAGER_IN_USE
36git config --unset core.pager
37PAGER='cat > paginated.out'
38export PAGER
39
40test_expect_success 'setup' '
41 test_commit initial
42'
43
44rm -f paginated.out
45test_expect_success TTY 'some commands use a pager' '
2d3ca216 46 test_terminal git log &&
60b6e220
JN
47 test -e paginated.out
48'
49
50rm -f paginated.out
51test_expect_success TTY 'some commands do not use a pager' '
2d3ca216 52 test_terminal git rev-list HEAD &&
60b6e220
JN
53 ! test -e paginated.out
54'
55
56rm -f paginated.out
57test_expect_success 'no pager when stdout is a pipe' '
58 git log | cat &&
59 ! test -e paginated.out
60'
61
62rm -f paginated.out
63test_expect_success 'no pager when stdout is a regular file' '
64 git log > file &&
65 ! test -e paginated.out
66'
67
68rm -f paginated.out
69test_expect_success TTY 'git --paginate rev-list uses a pager' '
2d3ca216 70 test_terminal git --paginate rev-list HEAD &&
60b6e220
JN
71 test -e paginated.out
72'
73
74rm -f file paginated.out
75test_expect_success 'no pager even with --paginate when stdout is a pipe' '
76 git --paginate log | cat &&
77 ! test -e paginated.out
78'
79
80rm -f paginated.out
81test_expect_success TTY 'no pager with --no-pager' '
2d3ca216 82 test_terminal git --no-pager log &&
60b6e220
JN
83 ! test -e paginated.out
84'
85
86# A colored commit log will begin with an appropriate ANSI escape
87# for the first color; the text "commit" comes later.
88colorful() {
89 read firstline < $1
90 ! expr "$firstline" : "^[a-zA-Z]" >/dev/null
91}
92
93rm -f colorful.log colorless.log
94test_expect_success 'tests can detect color' '
95 git log --no-color > colorless.log &&
96 git log --color > colorful.log &&
97 ! colorful colorless.log &&
98 colorful colorful.log
99'
100
101rm -f colorless.log
102git config color.ui auto
103test_expect_success 'no color when stdout is a regular file' '
104 git log > colorless.log &&
105 ! colorful colorless.log
106'
107
108rm -f paginated.out
109git config color.ui auto
110test_expect_success TTY 'color when writing to a pager' '
2d3ca216 111 TERM=vt100 test_terminal git log &&
60b6e220
JN
112 colorful paginated.out
113'
114
115rm -f colorful.log
116git config color.ui auto
117test_expect_success 'color when writing to a file intended for a pager' '
118 TERM=vt100 GIT_PAGER_IN_USE=true git log > colorful.log &&
119 colorful colorful.log
120'
121
122unset PAGER GIT_PAGER
123git config --unset core.pager
124test_expect_success 'determine default pager' '
125 less=$(git var GIT_PAGER) &&
126 test -n "$less"
127'
128
129if expr "$less" : '^[a-z]*$' > /dev/null && test_have_prereq TTY
130then
131 test_set_prereq SIMPLEPAGER
132fi
133
134unset PAGER GIT_PAGER
135git config --unset core.pager
136rm -f default_pager_used
137test_expect_success SIMPLEPAGER 'default pager is used by default' '
138 cat > $less <<-EOF &&
139 #!$SHELL_PATH
8c33b4cf 140 wc > default_pager_used
60b6e220
JN
141 EOF
142 chmod +x $less &&
2d3ca216 143 PATH=.:$PATH test_terminal git log &&
60b6e220
JN
144 test -e default_pager_used
145'
146
147unset GIT_PAGER
148git config --unset core.pager
149rm -f PAGER_used
150test_expect_success TTY 'PAGER overrides default pager' '
8c33b4cf 151 PAGER="wc > PAGER_used" &&
60b6e220 152 export PAGER &&
2d3ca216 153 test_terminal git log &&
60b6e220
JN
154 test -e PAGER_used
155'
156
157unset GIT_PAGER
158rm -f core.pager_used
159test_expect_success TTY 'core.pager overrides PAGER' '
8c33b4cf 160 PAGER=wc &&
60b6e220 161 export PAGER &&
8c33b4cf 162 git config core.pager "wc > core.pager_used" &&
2d3ca216 163 test_terminal git log &&
60b6e220
JN
164 test -e core.pager_used
165'
166
167rm -f GIT_PAGER_used
168test_expect_success TTY 'GIT_PAGER overrides core.pager' '
8c33b4cf
JN
169 git config core.pager wc &&
170 GIT_PAGER="wc > GIT_PAGER_used" &&
60b6e220 171 export GIT_PAGER &&
2d3ca216 172 test_terminal git log &&
60b6e220
JN
173 test -e GIT_PAGER_used
174'
175
176test_done