t7006: Use test_path_is_* functions in test script

Modernize the test by replacing `test -e` instances with `test_path_is_file` helper functions, and `! test -e` with `test_path_is_missing`, for better readability and diagnostic messages. Signed-off-by: Joey Salazar <jgsal@protonmail.com> Reviewed-by: Phillip Wood <phillip.wood123@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Joey Salazar committed Oct 20, 2020 at 19:53 UTC 4e1bee9a99fa2ebab176c9730fa5218363f2548b
1 file changed +42 -42
t/t7006-pager.sh
+42 -42
@@ -19,7 +19,7 @@ test_expect_success 'setup' '
19 test_expect_success TTY 'some commands use a pager' '
20 rm -f paginated.out &&
21 test_terminal git log &&
22 - test -e paginated.out
22 + test_path_is_file paginated.out
23 '
24
25 test_expect_failure TTY 'pager runs from subdir' '
@@ -65,49 +65,49 @@ test_expect_success !MINGW,TTY 'LESS and LV envvars set by git-sh-setup' '
65 test_expect_success TTY 'some commands do not use a pager' '
66 rm -f paginated.out &&
67 test_terminal git rev-list HEAD &&
68 - ! test -e paginated.out
68 + test_path_is_missing paginated.out
69 '
70
71 test_expect_success 'no pager when stdout is a pipe' '
72 rm -f paginated.out &&
73 git log | cat &&
74 - ! test -e paginated.out
74 + test_path_is_missing paginated.out
75 '
76
77 test_expect_success 'no pager when stdout is a regular file' '
78 rm -f paginated.out &&
79 git log >file &&
80 - ! test -e paginated.out
80 + test_path_is_missing paginated.out
81 '
82
83 test_expect_success TTY 'git --paginate rev-list uses a pager' '
84 rm -f paginated.out &&
85 test_terminal git --paginate rev-list HEAD &&
86 - test -e paginated.out
86 + test_path_is_file paginated.out
87 '
88
89 test_expect_success 'no pager even with --paginate when stdout is a pipe' '
90 rm -f file paginated.out &&
91 git --paginate log | cat &&
92 - ! test -e paginated.out
92 + test_path_is_missing paginated.out
93 '
94
95 test_expect_success TTY 'no pager with --no-pager' '
96 rm -f paginated.out &&
97 test_terminal git --no-pager log &&
98 - ! test -e paginated.out
98 + test_path_is_missing paginated.out
99 '
100
101 test_expect_success TTY 'configuration can disable pager' '
102 rm -f paginated.out &&
103 test_unconfig pager.grep &&
104 test_terminal git grep initial &&
105 - test -e paginated.out &&
105 + test_path_is_file paginated.out &&
106
107 rm -f paginated.out &&
108 test_config pager.grep false &&
109 test_terminal git grep initial &&
110 - ! test -e paginated.out
110 + test_path_is_missing paginated.out
111 '
112
113 test_expect_success TTY 'configuration can enable pager (from subdir)' '
@@ -122,107 +122,107 @@ test_expect_success TTY 'configuration can enable pager (from subdir)' '
122 test_terminal git bundle unbundle ../test.bundle
123 ) &&
124 {
125 - test -e paginated.out ||
126 - test -e subdir/paginated.out
125 + test_path_is_file paginated.out ||
126 + test_path_is_file subdir/paginated.out
127 }
128 '
129
130 test_expect_success TTY 'git tag -l defaults to paging' '
131 rm -f paginated.out &&
132 test_terminal git tag -l &&
133 - test -e paginated.out
133 + test_path_is_file paginated.out
134 '
135
136 test_expect_success TTY 'git tag -l respects pager.tag' '
137 rm -f paginated.out &&
138 test_terminal git -c pager.tag=false tag -l &&
139 - ! test -e paginated.out
139 + test_path_is_missing paginated.out
140 '
141
142 test_expect_success TTY 'git tag -l respects --no-pager' '
143 rm -f paginated.out &&
144 test_terminal git -c pager.tag --no-pager tag -l &&
145 - ! test -e paginated.out
145 + test_path_is_missing paginated.out
146 '
147
148 test_expect_success TTY 'git tag with no args defaults to paging' '
149 # no args implies -l so this should page like -l
150 rm -f paginated.out &&
151 test_terminal git tag &&
152 - test -e paginated.out
152 + test_path_is_file paginated.out
153 '
154
155 test_expect_success TTY 'git tag with no args respects pager.tag' '
156 # no args implies -l so this should page like -l
157 rm -f paginated.out &&
158 test_terminal git -c pager.tag=false tag &&
159 - ! test -e paginated.out
159 + test_path_is_missing paginated.out
160 '
161
162 test_expect_success TTY 'git tag --contains defaults to paging' '
163 # --contains implies -l so this should page like -l
164 rm -f paginated.out &&
165 test_terminal git tag --contains &&
166 - test -e paginated.out
166 + test_path_is_file paginated.out
167 '
168
169 test_expect_success TTY 'git tag --contains respects pager.tag' '
170 # --contains implies -l so this should page like -l
171 rm -f paginated.out &&
172 test_terminal git -c pager.tag=false tag --contains &&
173 - ! test -e paginated.out
173 + test_path_is_missing paginated.out
174 '
175
176 test_expect_success TTY 'git tag -a defaults to not paging' '
177 test_when_finished "git tag -d newtag" &&
178 rm -f paginated.out &&
179 test_terminal git tag -am message newtag &&
180 - ! test -e paginated.out
180 + test_path_is_missing paginated.out
181 '
182
183 test_expect_success TTY 'git tag -a ignores pager.tag' '
184 test_when_finished "git tag -d newtag" &&
185 rm -f paginated.out &&
186 test_terminal git -c pager.tag tag -am message newtag &&
187 - ! test -e paginated.out
187 + test_path_is_missing paginated.out
188 '
189
190 test_expect_success TTY 'git tag -a respects --paginate' '
191 test_when_finished "git tag -d newtag" &&
192 rm -f paginated.out &&
193 test_terminal git --paginate tag -am message newtag &&
194 - test -e paginated.out
194 + test_path_is_file paginated.out
195 '
196
197 test_expect_success TTY 'git tag as alias ignores pager.tag with -a' '
198 test_when_finished "git tag -d newtag" &&
199 rm -f paginated.out &&
200 test_terminal git -c pager.tag -c alias.t=tag t -am message newtag &&
201 - ! test -e paginated.out
201 + test_path_is_missing paginated.out
202 '
203
204 test_expect_success TTY 'git tag as alias respects pager.tag with -l' '
205 rm -f paginated.out &&
206 test_terminal git -c pager.tag=false -c alias.t=tag t -l &&
207 - ! test -e paginated.out
207 + test_path_is_missing paginated.out
208 '
209
210 test_expect_success TTY 'git branch defaults to paging' '
211 rm -f paginated.out &&
212 test_terminal git branch &&
213 - test -e paginated.out
213 + test_path_is_file paginated.out
214 '
215
216 test_expect_success TTY 'git branch respects pager.branch' '
217 rm -f paginated.out &&
218 test_terminal git -c pager.branch=false branch &&
219 - ! test -e paginated.out
219 + test_path_is_missing paginated.out
220 '
221
222 test_expect_success TTY 'git branch respects --no-pager' '
223 rm -f paginated.out &&
224 test_terminal git --no-pager branch &&
225 - ! test -e paginated.out
225 + test_path_is_missing paginated.out
226 '
227
228 test_expect_success TTY 'git branch --edit-description ignores pager.branch' '
@@ -232,8 +232,8 @@ test_expect_success TTY 'git branch --edit-description ignores pager.branch' '
232 touch editor.used
233 EOF
234 EDITOR=./editor test_terminal git -c pager.branch branch --edit-description &&
235 - ! test -e paginated.out &&
236 - test -e editor.used
235 + test_path_is_missing paginated.out &&
236 + test_path_is_file editor.used
237 '
238
239 test_expect_success TTY 'git branch --set-upstream-to ignores pager.branch' '
@@ -242,13 +242,13 @@ test_expect_success TTY 'git branch --set-upstream-to ignores pager.branch' '
242 test_when_finished "git branch -D other" &&
243 test_terminal git -c pager.branch branch --set-upstream-to=other &&
244 test_when_finished "git branch --unset-upstream" &&
245 - ! test -e paginated.out
245 + test_path_is_missing paginated.out
246 '
247
248 test_expect_success TTY 'git config ignores pager.config when setting' '
249 rm -f paginated.out &&
250 test_terminal git -c pager.config config foo.bar bar &&
251 - ! test -e paginated.out
251 + test_path_is_missing paginated.out
252 '
253
254 test_expect_success TTY 'git config --edit ignores pager.config' '
@@ -257,33 +257,33 @@ test_expect_success TTY 'git config --edit ignores pager.config' '
257 touch editor.used
258 EOF
259 EDITOR=./editor test_terminal git -c pager.config config --edit &&
260 - ! test -e paginated.out &&
261 - test -e editor.used
260 + test_path_is_missing paginated.out &&
261 + test_path_is_file editor.used
262 '
263
264 test_expect_success TTY 'git config --get ignores pager.config' '
265 rm -f paginated.out &&
266 test_terminal git -c pager.config config --get foo.bar &&
267 - ! test -e paginated.out
267 + test_path_is_missing paginated.out
268 '
269
270 test_expect_success TTY 'git config --get-urlmatch defaults to paging' '
271 rm -f paginated.out &&
272 test_terminal git -c http."https://foo.com/".bar=foo \
273 config --get-urlmatch http https://foo.com &&
274 - test -e paginated.out
274 + test_path_is_file paginated.out
275 '
276
277 test_expect_success TTY 'git config --get-all respects pager.config' '
278 rm -f paginated.out &&
279 test_terminal git -c pager.config=false config --get-all foo.bar &&
280 - ! test -e paginated.out
280 + test_path_is_missing paginated.out
281 '
282
283 test_expect_success TTY 'git config --list defaults to paging' '
284 rm -f paginated.out &&
285 test_terminal git config --list &&
286 - test -e paginated.out
286 + test_path_is_file paginated.out
287 '
288
289
@@ -392,7 +392,7 @@ test_default_pager() {
392 export PATH &&
393 $full_command
394 ) &&
395 - test -e default_pager_used
395 + test_path_is_file default_pager_used
396 "
397 }
398
@@ -406,7 +406,7 @@ test_PAGER_overrides() {
406 PAGER='wc >PAGER_used' &&
407 export PAGER &&
408 $full_command &&
409 - test -e PAGER_used
409 + test_path_is_file PAGER_used
410 "
411 }
412
@@ -432,7 +432,7 @@ test_core_pager() {
432 export PAGER &&
433 test_config core.pager 'wc >core.pager_used' &&
434 $full_command &&
435 - ${if_local_config}test -e core.pager_used
435 + ${if_local_config}test_path_is_file core.pager_used
436 "
437 }
438
@@ -464,7 +464,7 @@ test_pager_subdir_helper() {
464 cd sub &&
465 $full_command
466 ) &&
467 - ${if_local_config}test -e core.pager_used
467 + ${if_local_config}test_path_is_file core.pager_used
468 "
469 }
470
@@ -477,7 +477,7 @@ test_GIT_PAGER_overrides() {
477 GIT_PAGER='wc >GIT_PAGER_used' &&
478 export GIT_PAGER &&
479 $full_command &&
480 - test -e GIT_PAGER_used
480 + test_path_is_file GIT_PAGER_used
481 "
482 }
483
@@ -489,7 +489,7 @@ test_doesnt_paginate() {
489 GIT_PAGER='wc >GIT_PAGER_used' &&
490 export GIT_PAGER &&
491 $full_command &&
492 - ! test -e GIT_PAGER_used
492 + test_path_is_missing GIT_PAGER_used
493 "
494 }
495