@@ -4,17 +4,24 @@ test_description='Test automatic use of a pager.'
44
55. ./test-lib.sh
66
7- rm -f stdout_is_tty
7+ cleanup_fail () {
8+ echo >&2 cleanup failed
9+ (exit 1)
10+ }
11+
812test_expect_success ' set up terminal for tests' '
13+ rm -f stdout_is_tty ||
14+ cleanup_fail &&
15+
916 if test -t 1
1017 then
11- : > stdout_is_tty
18+ > stdout_is_tty
1219 elif
1320 test_have_prereq PERL &&
1421 "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \
1522 sh -c "test -t 1"
1623 then
17- : > test_terminal_works
24+ > test_terminal_works
1825 fi
1926'
2027
@@ -32,142 +39,188 @@ else
3239 say no usable terminal, so skipping some tests
3340fi
3441
35- unset GIT_PAGER GIT_PAGER_IN_USE
36- git config --unset core.pager
37- PAGER=' cat > paginated.out'
38- export PAGER
39-
4042test_expect_success ' setup' '
43+ unset GIT_PAGER GIT_PAGER_IN_USE &&
44+ test_might_fail git config --unset core.pager &&
45+
46+ PAGER="cat >paginated.out" &&
47+ export PAGER &&
48+
4149 test_commit initial
4250'
4351
44- rm -f paginated.out
4552test_expect_success TTY ' some commands use a pager' '
53+ rm -f paginated.out ||
54+ cleanup_fail &&
55+
4656 test_terminal git log &&
4757 test -e paginated.out
4858'
4959
50- rm -f paginated.out
5160test_expect_success TTY ' some commands do not use a pager' '
61+ rm -f paginated.out ||
62+ cleanup_fail &&
63+
5264 test_terminal git rev-list HEAD &&
5365 ! test -e paginated.out
5466'
5567
56- rm -f paginated.out
5768test_expect_success ' no pager when stdout is a pipe' '
69+ rm -f paginated.out ||
70+ cleanup_fail &&
71+
5872 git log | cat &&
5973 ! test -e paginated.out
6074'
6175
62- rm -f paginated.out
6376test_expect_success ' no pager when stdout is a regular file' '
64- git log > file &&
77+ rm -f paginated.out ||
78+ cleanup_fail &&
79+
80+ git log >file &&
6581 ! test -e paginated.out
6682'
6783
68- rm -f paginated.out
6984test_expect_success TTY ' git --paginate rev-list uses a pager' '
85+ rm -f paginated.out ||
86+ cleanup_fail &&
87+
7088 test_terminal git --paginate rev-list HEAD &&
7189 test -e paginated.out
7290'
7391
74- rm -f file paginated.out
7592test_expect_success ' no pager even with --paginate when stdout is a pipe' '
93+ rm -f file paginated.out ||
94+ cleanup_fail &&
95+
7696 git --paginate log | cat &&
7797 ! test -e paginated.out
7898'
7999
80- rm -f paginated.out
81100test_expect_success TTY ' no pager with --no-pager' '
101+ rm -f paginated.out ||
102+ cleanup_fail &&
103+
82104 test_terminal git --no-pager log &&
83105 ! test -e paginated.out
84106'
85107
86108# A colored commit log will begin with an appropriate ANSI escape
87109# for the first color; the text "commit" comes later.
88110colorful () {
89- read firstline < $1
111+ read firstline < $1
90112 ! expr " $firstline " : " ^[a-zA-Z]" > /dev/null
91113}
92114
93- rm -f colorful.log colorless.log
94115test_expect_success ' tests can detect color' '
95- git log --no-color > colorless.log &&
96- git log --color > colorful.log &&
116+ rm -f colorful.log colorless.log ||
117+ cleanup_fail &&
118+
119+ git log --no-color >colorless.log &&
120+ git log --color >colorful.log &&
97121 ! colorful colorless.log &&
98122 colorful colorful.log
99123'
100124
101- rm -f colorless.log
102- git config color.ui auto
103125test_expect_success ' no color when stdout is a regular file' '
104- git log > colorless.log &&
126+ rm -f colorless.log &&
127+ git config color.ui auto ||
128+ cleanup_fail &&
129+
130+ git log >colorless.log &&
105131 ! colorful colorless.log
106132'
107133
108- rm -f paginated.out
109- git config color.ui auto
110134test_expect_success TTY ' color when writing to a pager' '
111- TERM=vt100 test_terminal git log &&
135+ rm -f paginated.out &&
136+ git config color.ui auto ||
137+ cleanup_fail &&
138+
139+ (
140+ TERM=vt100 &&
141+ export TERM &&
142+ test_terminal git log
143+ ) &&
112144 colorful paginated.out
113145'
114146
115- rm -f colorful.log
116- git config color.ui auto
117147test_expect_success ' color when writing to a file intended for a pager' '
118- TERM=vt100 GIT_PAGER_IN_USE=true git log > colorful.log &&
148+ rm -f colorful.log &&
149+ git config color.ui auto ||
150+ cleanup_fail &&
151+
152+ (
153+ TERM=vt100 &&
154+ GIT_PAGER_IN_USE=true &&
155+ export TERM GIT_PAGER_IN_USE &&
156+ git log >colorful.log
157+ ) &&
119158 colorful colorful.log
120159'
121160
122- unset PAGER GIT_PAGER
123- git config --unset core.pager
124161test_expect_success ' determine default pager' '
162+ unset PAGER GIT_PAGER &&
163+ test_might_fail git config --unset core.pager ||
164+ cleanup_fail &&
165+
125166 less=$(git var GIT_PAGER) &&
126167 test -n "$less"
127168'
128169
129- if expr " $less " : ' ^[a-z]*$' > /dev/null && test_have_prereq TTY
170+ if expr " $less " : ' ^[a-z][a-z] *$' > /dev/null && test_have_prereq TTY
130171then
131172 test_set_prereq SIMPLEPAGER
132173fi
133174
134- unset PAGER GIT_PAGER
135- git config --unset core.pager
136- rm -f default_pager_used
137175test_expect_success SIMPLEPAGER ' default pager is used by default' '
138- cat > $less <<-EOF &&
139- #!$SHELL_PATH
140- wc > default_pager_used
176+ unset PAGER GIT_PAGER &&
177+ test_might_fail git config --unset core.pager &&
178+ rm -f default_pager_used ||
179+ cleanup_fail &&
180+
181+ cat >$less <<-\EOF &&
182+ #!/bin/sh
183+ wc >default_pager_used
141184 EOF
142185 chmod +x $less &&
143- PATH=.:$PATH test_terminal git log &&
186+ (
187+ PATH=.:$PATH &&
188+ export PATH &&
189+ test_terminal git log
190+ ) &&
144191 test -e default_pager_used
145192'
146193
147- unset GIT_PAGER
148- git config --unset core.pager
149- rm -f PAGER_used
150194test_expect_success TTY ' PAGER overrides default pager' '
151- PAGER="wc > PAGER_used" &&
195+ unset GIT_PAGER &&
196+ test_might_fail git config --unset core.pager &&
197+ rm -f PAGER_used ||
198+ cleanup_fail &&
199+
200+ PAGER="wc >PAGER_used" &&
152201 export PAGER &&
153202 test_terminal git log &&
154203 test -e PAGER_used
155204'
156205
157- unset GIT_PAGER
158- rm -f core.pager_used
159206test_expect_success TTY ' core.pager overrides PAGER' '
207+ unset GIT_PAGER &&
208+ rm -f core.pager_used ||
209+ cleanup_fail &&
210+
160211 PAGER=wc &&
161212 export PAGER &&
162- git config core.pager "wc > core.pager_used" &&
213+ git config core.pager "wc >core.pager_used" &&
163214 test_terminal git log &&
164215 test -e core.pager_used
165216'
166217
167- rm -f GIT_PAGER_used
168218test_expect_success TTY ' GIT_PAGER overrides core.pager' '
219+ rm -f GIT_PAGER_used ||
220+ cleanup_fail &&
221+
169222 git config core.pager wc &&
170- GIT_PAGER="wc > GIT_PAGER_used" &&
223+ GIT_PAGER="wc >GIT_PAGER_used" &&
171224 export GIT_PAGER &&
172225 test_terminal git log &&
173226 test -e GIT_PAGER_used
0 commit comments