t7300-clean.sh: use test_path_* helper functions for error logging

This test script uses "test - [def]", but when a test fails because the file passed to it does not exist, it fails silently without an error message. Use test_path_* helper functions, which are designed to give better error messages when their expectations are not met. I have added a mechanical validation that applies the same transformation done in this patch, when the test script is passed to a sed script as shown below. sed -e 's/^\( *\)test -f /\1test_path_is_file /' \ -e 's/^\( *\)test -d /\1test_path_is_dir /' \ -e 's/^\( *\)test -e /\1test_path_exists /' \ -e 's/^\( *\)! test -[edf] /\1test_path_is_missing /' \ -e 's/^\( *\)test ! -[edf] /\1test_path_is_missing /' \ "$1" >foo.sh Reviewers can use the sed script to tranform the original test script and compare the result in foo.sh with the results of applying the patch. You will see an instance of "!(test -e 3)" which was manually replaced with ""test_path_is_missing 3", and everything else should match. Careful and deliberate observation was done to check instances where "test ! - [df] foo" was used in the test script to make sure that the test instances were expecting foo to EITHER be a file or a directory, and NOT a possibility of being both as this would make replacing "test ! -f foo" with "test_path_is_missing foo" unreasonable. In the tests control flow, foo has been created as EITHER a reguar file OR a directory and should NOT exist after "git clean" or "git clean -d", as the case maybe, has been called. This made it reasonable to replace "test ! -[df] foo" with "test_path_is_missing foo". Signed-off-by: Abraham Samuel Adekunle <abrahamadekunle50@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Abraham Samuel Adekunle committed Oct 9, 2024 at 18:22 UTC 77af53f56f100b49fdcf294f687b36064d16feca
1 file changed +185 -185
t/t7300-clean.sh
+185 -185
@@ -29,15 +29,15 @@ test_expect_success 'git clean with skip-worktree .gitignore' '
29 mkdir -p build docs &&
30 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
31 git clean &&
32 - test -f Makefile &&
33 - test -f README &&
34 - test -f src/part1.c &&
35 - test -f src/part2.c &&
36 - test ! -f a.out &&
37 - test ! -f src/part3.c &&
38 - test -f docs/manual.txt &&
39 - test -f obj.o &&
40 - test -f build/lib.so &&
32 + test_path_is_file Makefile &&
33 + test_path_is_file README &&
34 + test_path_is_file src/part1.c &&
35 + test_path_is_file src/part2.c &&
36 + test_path_is_missing a.out &&
37 + test_path_is_missing src/part3.c &&
38 + test_path_is_file docs/manual.txt &&
39 + test_path_is_file obj.o &&
40 + test_path_is_file build/lib.so &&
41 git update-index --no-skip-worktree .gitignore &&
42 git checkout .gitignore
43 '
@@ -47,15 +47,15 @@ test_expect_success 'git clean' '
47 mkdir -p build docs &&
48 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
49 git clean &&
50 - test -f Makefile &&
51 - test -f README &&
52 - test -f src/part1.c &&
53 - test -f src/part2.c &&
54 - test ! -f a.out &&
55 - test ! -f src/part3.c &&
56 - test -f docs/manual.txt &&
57 - test -f obj.o &&
58 - test -f build/lib.so
50 + test_path_is_file Makefile &&
51 + test_path_is_file README &&
52 + test_path_is_file src/part1.c &&
53 + test_path_is_file src/part2.c &&
54 + test_path_is_missing a.out &&
55 + test_path_is_missing src/part3.c &&
56 + test_path_is_file docs/manual.txt &&
57 + test_path_is_file obj.o &&
58 + test_path_is_file build/lib.so
59
60 '
61
@@ -64,15 +64,15 @@ test_expect_success 'git clean src/' '
64 mkdir -p build docs &&
65 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
66 git clean src/ &&
67 - test -f Makefile &&
68 - test -f README &&
69 - test -f src/part1.c &&
70 - test -f src/part2.c &&
71 - test -f a.out &&
72 - test ! -f src/part3.c &&
73 - test -f docs/manual.txt &&
74 - test -f obj.o &&
75 - test -f build/lib.so
67 + test_path_is_file Makefile &&
68 + test_path_is_file README &&
69 + test_path_is_file src/part1.c &&
70 + test_path_is_file src/part2.c &&
71 + test_path_is_file a.out &&
72 + test_path_is_missing src/part3.c &&
73 + test_path_is_file docs/manual.txt &&
74 + test_path_is_file obj.o &&
75 + test_path_is_file build/lib.so
76
77 '
78
@@ -81,15 +81,15 @@ test_expect_success 'git clean src/ src/' '
81 mkdir -p build docs &&
82 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
83 git clean src/ src/ &&
84 - test -f Makefile &&
85 - test -f README &&
86 - test -f src/part1.c &&
87 - test -f src/part2.c &&
88 - test -f a.out &&
89 - test ! -f src/part3.c &&
90 - test -f docs/manual.txt &&
91 - test -f obj.o &&
92 - test -f build/lib.so
84 + test_path_is_file Makefile &&
85 + test_path_is_file README &&
86 + test_path_is_file src/part1.c &&
87 + test_path_is_file src/part2.c &&
88 + test_path_is_file a.out &&
89 + test_path_is_missing src/part3.c &&
90 + test_path_is_file docs/manual.txt &&
91 + test_path_is_file obj.o &&
92 + test_path_is_file build/lib.so
93
94 '
95
@@ -98,16 +98,16 @@ test_expect_success 'git clean with prefix' '
98 mkdir -p build docs src/test &&
99 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so src/test/1.c &&
100 (cd src/ && git clean) &&
101 - test -f Makefile &&
102 - test -f README &&
103 - test -f src/part1.c &&
104 - test -f src/part2.c &&
105 - test -f a.out &&
106 - test ! -f src/part3.c &&
107 - test -f src/test/1.c &&
108 - test -f docs/manual.txt &&
109 - test -f obj.o &&
110 - test -f build/lib.so
101 + test_path_is_file Makefile &&
102 + test_path_is_file README &&
103 + test_path_is_file src/part1.c &&
104 + test_path_is_file src/part2.c &&
105 + test_path_is_file a.out &&
106 + test_path_is_missing src/part3.c &&
107 + test_path_is_file src/test/1.c &&
108 + test_path_is_file docs/manual.txt &&
109 + test_path_is_file obj.o &&
110 + test_path_is_file build/lib.so
111
112 '
113
@@ -163,16 +163,16 @@ test_expect_success 'git clean -d with prefix and path' '
163 mkdir -p build docs src/feature &&
164 touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so &&
165 (cd src/ && git clean -d feature/) &&
166 - test -f Makefile &&
167 - test -f README &&
168 - test -f src/part1.c &&
169 - test -f src/part2.c &&
170 - test -f a.out &&
171 - test -f src/part3.c &&
172 - test ! -f src/feature/file.c &&
173 - test -f docs/manual.txt &&
174 - test -f obj.o &&
175 - test -f build/lib.so
166 + test_path_is_file Makefile &&
167 + test_path_is_file README &&
168 + test_path_is_file src/part1.c &&
169 + test_path_is_file src/part2.c &&
170 + test_path_is_file a.out &&
171 + test_path_is_file src/part3.c &&
172 + test_path_is_missing src/feature/file.c &&
173 + test_path_is_file docs/manual.txt &&
174 + test_path_is_file obj.o &&
175 + test_path_is_file build/lib.so
176
177 '
178
@@ -182,16 +182,16 @@ test_expect_success SYMLINKS 'git clean symbolic link' '
182 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
183 ln -s docs/manual.txt src/part4.c &&
184 git clean &&
185 - test -f Makefile &&
186 - test -f README &&
187 - test -f src/part1.c &&
188 - test -f src/part2.c &&
189 - test ! -f a.out &&
190 - test ! -f src/part3.c &&
191 - test ! -f src/part4.c &&
192 - test -f docs/manual.txt &&
193 - test -f obj.o &&
194 - test -f build/lib.so
185 + test_path_is_file Makefile &&
186 + test_path_is_file README &&
187 + test_path_is_file src/part1.c &&
188 + test_path_is_file src/part2.c &&
189 + test_path_is_missing a.out &&
190 + test_path_is_missing src/part3.c &&
191 + test_path_is_missing src/part4.c &&
192 + test_path_is_file docs/manual.txt &&
193 + test_path_is_file obj.o &&
194 + test_path_is_file build/lib.so
195
196 '
197
@@ -199,13 +199,13 @@ test_expect_success 'git clean with wildcard' '
199
200 touch a.clean b.clean other.c &&
201 git clean "*.clean" &&
202 - test -f Makefile &&
203 - test -f README &&
204 - test -f src/part1.c &&
205 - test -f src/part2.c &&
206 - test ! -f a.clean &&
207 - test ! -f b.clean &&
208 - test -f other.c
202 + test_path_is_file Makefile &&
203 + test_path_is_file README &&
204 + test_path_is_file src/part1.c &&
205 + test_path_is_file src/part2.c &&
206 + test_path_is_missing a.clean &&
207 + test_path_is_missing b.clean &&
208 + test_path_is_file other.c
209
210 '
211
@@ -214,15 +214,15 @@ test_expect_success 'git clean -n' '
214 mkdir -p build docs &&
215 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
216 git clean -n &&
217 - test -f Makefile &&
218 - test -f README &&
219 - test -f src/part1.c &&
220 - test -f src/part2.c &&
221 - test -f a.out &&
222 - test -f src/part3.c &&
223 - test -f docs/manual.txt &&
224 - test -f obj.o &&
225 - test -f build/lib.so
217 + test_path_is_file Makefile &&
218 + test_path_is_file README &&
219 + test_path_is_file src/part1.c &&
220 + test_path_is_file src/part2.c &&
221 + test_path_is_file a.out &&
222 + test_path_is_file src/part3.c &&
223 + test_path_is_file docs/manual.txt &&
224 + test_path_is_file obj.o &&
225 + test_path_is_file build/lib.so
226
227 '
228
@@ -231,15 +231,15 @@ test_expect_success 'git clean -d' '
231 mkdir -p build docs &&
232 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
233 git clean -d &&
234 - test -f Makefile &&
235 - test -f README &&
236 - test -f src/part1.c &&
237 - test -f src/part2.c &&
238 - test ! -f a.out &&
239 - test ! -f src/part3.c &&
240 - test ! -d docs &&
241 - test -f obj.o &&
242 - test -f build/lib.so
234 + test_path_is_file Makefile &&
235 + test_path_is_file README &&
236 + test_path_is_file src/part1.c &&
237 + test_path_is_file src/part2.c &&
238 + test_path_is_missing a.out &&
239 + test_path_is_missing src/part3.c &&
240 + test_path_is_missing docs &&
241 + test_path_is_file obj.o &&
242 + test_path_is_file build/lib.so
243
244 '
245
@@ -248,16 +248,16 @@ test_expect_success 'git clean -d src/ examples/' '
248 mkdir -p build docs examples &&
249 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c &&
250 git clean -d src/ examples/ &&
251 - test -f Makefile &&
252 - test -f README &&
253 - test -f src/part1.c &&
254 - test -f src/part2.c &&
255 - test -f a.out &&
256 - test ! -f src/part3.c &&
257 - test ! -f examples/1.c &&
258 - test -f docs/manual.txt &&
259 - test -f obj.o &&
260 - test -f build/lib.so
251 + test_path_is_file Makefile &&
252 + test_path_is_file README &&
253 + test_path_is_file src/part1.c &&
254 + test_path_is_file src/part2.c &&
255 + test_path_is_file a.out &&
256 + test_path_is_missing src/part3.c &&
257 + test_path_is_missing examples/1.c &&
258 + test_path_is_file docs/manual.txt &&
259 + test_path_is_file obj.o &&
260 + test_path_is_file build/lib.so
261
262 '
263
@@ -266,15 +266,15 @@ test_expect_success 'git clean -x' '
266 mkdir -p build docs &&
267 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
268 git clean -x &&
269 - test -f Makefile &&
270 - test -f README &&
271 - test -f src/part1.c &&
272 - test -f src/part2.c &&
273 - test ! -f a.out &&
274 - test ! -f src/part3.c &&
275 - test -f docs/manual.txt &&
276 - test ! -f obj.o &&
277 - test -f build/lib.so
269 + test_path_is_file Makefile &&
270 + test_path_is_file README &&
271 + test_path_is_file src/part1.c &&
272 + test_path_is_file src/part2.c &&
273 + test_path_is_missing a.out &&
274 + test_path_is_missing src/part3.c &&
275 + test_path_is_file docs/manual.txt &&
276 + test_path_is_missing obj.o &&
277 + test_path_is_file build/lib.so
278
279 '
280
@@ -283,15 +283,15 @@ test_expect_success 'git clean -d -x' '
283 mkdir -p build docs &&
284 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
285 git clean -d -x &&
286 - test -f Makefile &&
287 - test -f README &&
288 - test -f src/part1.c &&
289 - test -f src/part2.c &&
290 - test ! -f a.out &&
291 - test ! -f src/part3.c &&
292 - test ! -d docs &&
293 - test ! -f obj.o &&
294 - test ! -d build
286 + test_path_is_file Makefile &&
287 + test_path_is_file README &&
288 + test_path_is_file src/part1.c &&
289 + test_path_is_file src/part2.c &&
290 + test_path_is_missing a.out &&
291 + test_path_is_missing src/part3.c &&
292 + test_path_is_missing docs &&
293 + test_path_is_missing obj.o &&
294 + test_path_is_missing build
295
296 '
297
@@ -300,15 +300,15 @@ test_expect_success 'git clean -d -x with ignored tracked directory' '
300 mkdir -p build docs &&
301 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
302 git clean -d -x -e src &&
303 - test -f Makefile &&
304 - test -f README &&
305 - test -f src/part1.c &&
306 - test -f src/part2.c &&
307 - test ! -f a.out &&
308 - test -f src/part3.c &&
309 - test ! -d docs &&
310 - test ! -f obj.o &&
311 - test ! -d build
303 + test_path_is_file Makefile &&
304 + test_path_is_file README &&
305 + test_path_is_file src/part1.c &&
306 + test_path_is_file src/part2.c &&
307 + test_path_is_missing a.out &&
308 + test_path_is_file src/part3.c &&
309 + test_path_is_missing docs &&
310 + test_path_is_missing obj.o &&
311 + test_path_is_missing build
312
313 '
314
@@ -317,15 +317,15 @@ test_expect_success 'git clean -X' '
317 mkdir -p build docs &&
318 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
319 git clean -X &&
320 - test -f Makefile &&
321 - test -f README &&
322 - test -f src/part1.c &&
323 - test -f src/part2.c &&
324 - test -f a.out &&
325 - test -f src/part3.c &&
326 - test -f docs/manual.txt &&
327 - test ! -f obj.o &&
328 - test -f build/lib.so
320 + test_path_is_file Makefile &&
321 + test_path_is_file README &&
322 + test_path_is_file src/part1.c &&
323 + test_path_is_file src/part2.c &&
324 + test_path_is_file a.out &&
325 + test_path_is_file src/part3.c &&
326 + test_path_is_file docs/manual.txt &&
327 + test_path_is_missing obj.o &&
328 + test_path_is_file build/lib.so
329
330 '
331
@@ -334,15 +334,15 @@ test_expect_success 'git clean -d -X' '
334 mkdir -p build docs &&
335 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
336 git clean -d -X &&
337 - test -f Makefile &&
338 - test -f README &&
339 - test -f src/part1.c &&
340 - test -f src/part2.c &&
341 - test -f a.out &&
342 - test -f src/part3.c &&
343 - test -f docs/manual.txt &&
344 - test ! -f obj.o &&
345 - test ! -d build
337 + test_path_is_file Makefile &&
338 + test_path_is_file README &&
339 + test_path_is_file src/part1.c &&
340 + test_path_is_file src/part2.c &&
341 + test_path_is_file a.out &&
342 + test_path_is_file src/part3.c &&
343 + test_path_is_file docs/manual.txt &&
344 + test_path_is_missing obj.o &&
345 + test_path_is_missing build
346
347 '
348
@@ -351,15 +351,15 @@ test_expect_success 'git clean -d -X with ignored tracked directory' '
351 mkdir -p build docs &&
352 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
353 git clean -d -X -e src &&
354 - test -f Makefile &&
355 - test -f README &&
356 - test -f src/part1.c &&
357 - test -f src/part2.c &&
358 - test -f a.out &&
359 - test ! -f src/part3.c &&
360 - test -f docs/manual.txt &&
361 - test ! -f obj.o &&
362 - test ! -d build
354 + test_path_is_file Makefile &&
355 + test_path_is_file README &&
356 + test_path_is_file src/part1.c &&
357 + test_path_is_file src/part2.c &&
358 + test_path_is_file a.out &&
359 + test_path_is_missing src/part3.c &&
360 + test_path_is_file docs/manual.txt &&
361 + test_path_is_missing obj.o &&
362 + test_path_is_missing build
363
364 '
365
@@ -382,29 +382,29 @@ test_expect_success 'clean.requireForce and -n' '
382 mkdir -p build docs &&
383 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
384 git clean -n &&
385 - test -f Makefile &&
386 - test -f README &&
387 - test -f src/part1.c &&
388 - test -f src/part2.c &&
389 - test -f a.out &&
390 - test -f src/part3.c &&
391 - test -f docs/manual.txt &&
392 - test -f obj.o &&
393 - test -f build/lib.so
385 + test_path_is_file Makefile &&
386 + test_path_is_file README &&
387 + test_path_is_file src/part1.c &&
388 + test_path_is_file src/part2.c &&
389 + test_path_is_file a.out &&
390 + test_path_is_file src/part3.c &&
391 + test_path_is_file docs/manual.txt &&
392 + test_path_is_file obj.o &&
393 + test_path_is_file build/lib.so
394
395 '
396
397 test_expect_success 'clean.requireForce and -f' '
398
399 git clean -f &&
400 - test -f README &&
401 - test -f src/part1.c &&
402 - test -f src/part2.c &&
403 - test ! -f a.out &&
404 - test ! -f src/part3.c &&
405 - test -f docs/manual.txt &&
406 - test -f obj.o &&
407 - test -f build/lib.so
400 + test_path_is_file README &&
401 + test_path_is_file src/part1.c &&
402 + test_path_is_file src/part2.c &&
403 + test_path_is_missing a.out &&
404 + test_path_is_missing src/part3.c &&
405 + test_path_is_file docs/manual.txt &&
406 + test_path_is_file obj.o &&
407 + test_path_is_file build/lib.so
408
409 '
410
@@ -453,11 +453,11 @@ test_expect_success 'nested git work tree' '
453 test_commit deeply.nested deeper.world
454 ) &&
455 git clean -f -d &&
456 - test -f foo/.git/index &&
457 - test -f foo/hello.world &&
458 - test -f baz/boo/.git/index &&
459 - test -f baz/boo/deeper.world &&
460 - ! test -d bar
456 + test_path_is_file foo/.git/index &&
457 + test_path_is_file foo/hello.world &&
458 + test_path_is_file baz/boo/.git/index &&
459 + test_path_is_file baz/boo/deeper.world &&
460 + test_path_is_missing bar
461 '
462
463 test_expect_success 'should clean things that almost look like git but are not' '
@@ -624,9 +624,9 @@ test_expect_success 'force removal of nested git work tree' '
624 test_commit deeply.nested deeper.world
625 ) &&
626 git clean -f -f -d &&
627 - ! test -d foo &&
628 - ! test -d bar &&
629 - ! test -d baz
627 + test_path_is_missing foo &&
628 + test_path_is_missing bar &&
629 + test_path_is_missing baz
630 '
631
632 test_expect_success 'git clean -e' '
@@ -638,10 +638,10 @@ test_expect_success 'git clean -e' '
638 touch known 1 2 3 &&
639 git add known &&
640 git clean -f -e 1 -e 2 &&
641 - test -e 1 &&
642 - test -e 2 &&
643 - ! (test -e 3) &&
644 - test -e known
641 + test_path_exists 1 &&
642 + test_path_exists 2 &&
643 + test_path_is_missing 3 &&
644 + test_path_exists known
645 )
646 '
647
@@ -649,7 +649,7 @@ test_expect_success SANITY 'git clean -d with an unreadable empty directory' '
649 mkdir foo &&
650 chmod a= foo &&
651 git clean -dfx foo &&
652 - ! test -d foo
652 + test_path_is_missing foo
653 '
654
655 test_expect_success 'git clean -d respects pathspecs (dir is prefix of pathspec)' '