t3600: use helpers to replace test -d/f/e/s <path>

Take advantage of helper functions test_path_is_dir(), test_path_is_missing(), etc. to replace `test -d|f|e|s` since the functions make the code more readable and have better error messages. Signed-off-by: Rohit Ashiwal <rohit.ashiwal265@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Rohit Ashiwal committed Mar 4, 2019 at 17:38 UTC 59a06e947bf880d72fb8358e95de93fa5c69158c
1 file changed +75 -75
t/t3600-rm.sh
+75 -75
@@ -26,7 +26,7 @@ test_expect_success FUNNYNAMES 'add files with funny names' '
26 '
27
28 test_expect_success 'Pre-check that foo exists and is in index before git rm foo' '
29 - test -f foo &&
29 + test_path_is_file foo &&
30 git ls-files --error-unmatch foo
31 '
32
@@ -69,12 +69,12 @@ test_expect_success 'Test that git rm --cached -f foo works in case where --cach
69 '
70
71 test_expect_success 'Post-check that foo exists but is not in index after git rm foo' '
72 - test -f foo &&
72 + test_path_is_file foo &&
73 test_must_fail git ls-files --error-unmatch foo
74 '
75
76 test_expect_success 'Pre-check that bar exists and is in index before "git rm bar"' '
77 - test -f bar &&
77 + test_path_is_file bar &&
78 git ls-files --error-unmatch bar
79 '
80
@@ -83,7 +83,7 @@ test_expect_success 'Test that "git rm bar" succeeds' '
83 '
84
85 test_expect_success 'Post-check that bar does not exist and is not in index after "git rm -f bar"' '
86 - ! test -f bar &&
86 + test_path_is_missing bar &&
87 test_must_fail git ls-files --error-unmatch bar
88 '
89
@@ -138,15 +138,15 @@ test_expect_success 'Re-add foo and baz' '
138 test_expect_success 'Modify foo -- rm should refuse' '
139 echo >>foo &&
140 test_must_fail git rm foo baz &&
141 - test -f foo &&
142 - test -f baz &&
141 + test_path_is_file foo &&
142 + test_path_is_file baz &&
143 git ls-files --error-unmatch foo baz
144 '
145
146 test_expect_success 'Modified foo -- rm -f should work' '
147 git rm -f foo baz &&
148 - test ! -f foo &&
149 - test ! -f baz &&
148 + test_path_is_missing foo &&
149 + test_path_is_missing baz &&
150 test_must_fail git ls-files --error-unmatch foo &&
151 test_must_fail git ls-files --error-unmatch bar
152 '
@@ -160,15 +160,15 @@ test_expect_success 'Re-add foo and baz for HEAD tests' '
160
161 test_expect_success 'foo is different in index from HEAD -- rm should refuse' '
162 test_must_fail git rm foo baz &&
163 - test -f foo &&
164 - test -f baz &&
163 + test_path_is_file foo &&
164 + test_path_is_file baz &&
165 git ls-files --error-unmatch foo baz
166 '
167
168 test_expect_success 'but with -f it should work.' '
169 git rm -f foo baz &&
170 - test ! -f foo &&
171 - test ! -f baz &&
170 + test_path_is_missing foo &&
171 + test_path_is_missing baz &&
172 test_must_fail git ls-files --error-unmatch foo &&
173 test_must_fail git ls-files --error-unmatch baz
174 '
@@ -195,21 +195,21 @@ test_expect_success 'Recursive test setup' '
195
196 test_expect_success 'Recursive without -r fails' '
197 test_must_fail git rm frotz &&
198 - test -d frotz &&
199 - test -f frotz/nitfol
198 + test_path_is_dir frotz &&
199 + test_path_is_file frotz/nitfol
200 '
201
202 test_expect_success 'Recursive with -r but dirty' '
203 echo qfwfq >>frotz/nitfol &&
204 test_must_fail git rm -r frotz &&
205 - test -d frotz &&
206 - test -f frotz/nitfol
205 + test_path_is_dir frotz &&
206 + test_path_is_file frotz/nitfol
207 '
208
209 test_expect_success 'Recursive with -r -f' '
210 git rm -f -r frotz &&
211 - ! test -f frotz/nitfol &&
212 - ! test -d frotz
211 + test_path_is_missing frotz/nitfol &&
212 + test_path_is_missing frotz
213 '
214
215 test_expect_success 'Remove nonexistent file returns nonzero exit status' '
@@ -236,7 +236,7 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
236 git reset --hard &&
237 test-tool chmtime -86400 frotz/nitfol &&
238 git rm frotz/nitfol &&
239 - test ! -f frotz/nitfol
239 + test_path_is_missing frotz/nitfol
240 '
241
242 test_expect_success 'choking "git rm" should not let it die with cruft' '
@@ -257,7 +257,7 @@ test_expect_success 'rm removes subdirectories recursively' '
257 echo content >dir/subdir/subsubdir/file &&
258 git add dir/subdir/subsubdir/file &&
259 git rm -f dir/subdir/subsubdir/file &&
260 - ! test -d dir
260 + test_path_is_missing dir
261 '
262
263 cat >expect <<EOF
@@ -295,7 +295,7 @@ test_expect_success 'rm removes empty submodules from work tree' '
295 git add .gitmodules &&
296 git commit -m "add submodule" &&
297 git rm submod &&
298 - test ! -e submod &&
298 + test_path_is_missing submod &&
299 git status -s -uno --ignore-submodules=none >actual &&
300 test_cmp expect actual &&
301 test_must_fail git config -f .gitmodules submodule.sub.url &&
@@ -317,7 +317,7 @@ test_expect_success 'rm removes work tree of unmodified submodules' '
317 git reset --hard &&
318 git submodule update &&
319 git rm submod &&
320 - test ! -d submod &&
320 + test_path_is_missing submod &&
321 git status -s -uno --ignore-submodules=none >actual &&
322 test_cmp expect actual &&
323 test_must_fail git config -f .gitmodules submodule.sub.url &&
@@ -328,7 +328,7 @@ test_expect_success 'rm removes a submodule with a trailing /' '
328 git reset --hard &&
329 git submodule update &&
330 git rm submod/ &&
331 - test ! -d submod &&
331 + test_path_is_missing submod &&
332 git status -s -uno --ignore-submodules=none >actual &&
333 test_cmp expect actual
334 '
@@ -346,12 +346,12 @@ test_expect_success 'rm of a populated submodule with different HEAD fails unles
346 git submodule update &&
347 git -C submod checkout HEAD^ &&
348 test_must_fail git rm submod &&
349 - test -d submod &&
350 - test -f submod/.git &&
349 + test_path_is_dir submod &&
350 + test_path_is_file submod/.git &&
351 git status -s -uno --ignore-submodules=none >actual &&
352 test_cmp expect.modified actual &&
353 git rm -f submod &&
354 - test ! -d submod &&
354 + test_path_is_missing submod &&
355 git status -s -uno --ignore-submodules=none >actual &&
356 test_cmp expect actual &&
357 test_must_fail git config -f .gitmodules submodule.sub.url &&
@@ -362,8 +362,8 @@ test_expect_success 'rm --cached leaves work tree of populated submodules and .g
362 git reset --hard &&
363 git submodule update &&
364 git rm --cached submod &&
365 - test -d submod &&
366 - test -f submod/.git &&
365 + test_path_is_dir submod &&
366 + test_path_is_file submod/.git &&
367 git status -s -uno >actual &&
368 test_cmp expect.cached actual &&
369 git config -f .gitmodules submodule.sub.url &&
@@ -374,7 +374,7 @@ test_expect_success 'rm --dry-run does not touch the submodule or .gitmodules' '
374 git reset --hard &&
375 git submodule update &&
376 git rm -n submod &&
377 - test -f submod/.git &&
377 + test_path_is_file submod/.git &&
378 git diff-index --exit-code HEAD
379 '
380
@@ -384,8 +384,8 @@ test_expect_success 'rm does not complain when no .gitmodules file is found' '
384 git rm .gitmodules &&
385 git rm submod >actual 2>actual.err &&
386 test_must_be_empty actual.err &&
387 - ! test -d submod &&
388 - ! test -f submod/.git &&
387 + test_path_is_missing submod &&
388 + test_path_is_missing submod/.git &&
389 git status -s -uno >actual &&
390 test_cmp expect.both_deleted actual
391 '
@@ -395,15 +395,15 @@ test_expect_success 'rm will error out on a modified .gitmodules file unless sta
395 git submodule update &&
396 git config -f .gitmodules foo.bar true &&
397 test_must_fail git rm submod >actual 2>actual.err &&
398 - test -s actual.err &&
399 - test -d submod &&
400 - test -f submod/.git &&
398 + test_file_not_empty actual.err &&
399 + test_path_is_dir submod &&
400 + test_path_is_file submod/.git &&
401 git diff-files --quiet -- submod &&
402 git add .gitmodules &&
403 git rm submod >actual 2>actual.err &&
404 test_must_be_empty actual.err &&
405 - ! test -d submod &&
406 - ! test -f submod/.git &&
405 + test_path_is_missing submod &&
406 + test_path_is_missing submod/.git &&
407 git status -s -uno >actual &&
408 test_cmp expect actual
409 '
@@ -416,8 +416,8 @@ test_expect_success 'rm issues a warning when section is not found in .gitmodule
416 echo "warning: Could not find section in .gitmodules where path=submod" >expect.err &&
417 git rm submod >actual 2>actual.err &&
418 test_i18ncmp expect.err actual.err &&
419 - ! test -d submod &&
420 - ! test -f submod/.git &&
419 + test_path_is_missing submod &&
420 + test_path_is_missing submod/.git &&
421 git status -s -uno >actual &&
422 test_cmp expect actual
423 '
@@ -427,12 +427,12 @@ test_expect_success 'rm of a populated submodule with modifications fails unless
427 git submodule update &&
428 echo X >submod/empty &&
429 test_must_fail git rm submod &&
430 - test -d submod &&
431 - test -f submod/.git &&
430 + test_path_is_dir submod &&
431 + test_path_is_file submod/.git &&
432 git status -s -uno --ignore-submodules=none >actual &&
433 test_cmp expect.modified_inside actual &&
434 git rm -f submod &&
435 - test ! -d submod &&
435 + test_path_is_missing submod &&
436 git status -s -uno --ignore-submodules=none >actual &&
437 test_cmp expect actual
438 '
@@ -442,12 +442,12 @@ test_expect_success 'rm of a populated submodule with untracked files fails unle
442 git submodule update &&
443 echo X >submod/untracked &&
444 test_must_fail git rm submod &&
445 - test -d submod &&
446 - test -f submod/.git &&
445 + test_path_is_dir submod &&
446 + test_path_is_file submod/.git &&
447 git status -s -uno --ignore-submodules=none >actual &&
448 test_cmp expect.modified_untracked actual &&
449 git rm -f submod &&
450 - test ! -d submod &&
450 + test_path_is_missing submod &&
451 git status -s -uno --ignore-submodules=none >actual &&
452 test_cmp expect actual
453 '
@@ -484,7 +484,7 @@ test_expect_success 'rm removes work tree of unmodified conflicted submodule' '
484 git submodule update &&
485 test_must_fail git merge conflict2 &&
486 git rm submod &&
487 - test ! -d submod &&
487 + test_path_is_missing submod &&
488 git status -s -uno --ignore-submodules=none >actual &&
489 test_cmp expect actual
490 '
@@ -496,12 +496,12 @@ test_expect_success 'rm of a conflicted populated submodule with different HEAD
496 git -C submod checkout HEAD^ &&
497 test_must_fail git merge conflict2 &&
498 test_must_fail git rm submod &&
499 - test -d submod &&
500 - test -f submod/.git &&
499 + test_path_is_dir submod &&
500 + test_path_is_file submod/.git &&
501 git status -s -uno --ignore-submodules=none >actual &&
502 test_cmp expect.conflict actual &&
503 git rm -f submod &&
504 - test ! -d submod &&
504 + test_path_is_missing submod &&
505 git status -s -uno --ignore-submodules=none >actual &&
506 test_cmp expect actual &&
507 test_must_fail git config -f .gitmodules submodule.sub.url &&
@@ -515,12 +515,12 @@ test_expect_success 'rm of a conflicted populated submodule with modifications f
515 echo X >submod/empty &&
516 test_must_fail git merge conflict2 &&
517 test_must_fail git rm submod &&
518 - test -d submod &&
519 - test -f submod/.git &&
518 + test_path_is_dir submod &&
519 + test_path_is_file submod/.git &&
520 git status -s -uno --ignore-submodules=none >actual &&
521 test_cmp expect.conflict actual &&
522 git rm -f submod &&
523 - test ! -d submod &&
523 + test_path_is_missing submod &&
524 git status -s -uno --ignore-submodules=none >actual &&
525 test_cmp expect actual &&
526 test_must_fail git config -f .gitmodules submodule.sub.url &&
@@ -534,12 +534,12 @@ test_expect_success 'rm of a conflicted populated submodule with untracked files
534 echo X >submod/untracked &&
535 test_must_fail git merge conflict2 &&
536 test_must_fail git rm submod &&
537 - test -d submod &&
538 - test -f submod/.git &&
537 + test_path_is_dir submod &&
538 + test_path_is_file submod/.git &&
539 git status -s -uno --ignore-submodules=none >actual &&
540 test_cmp expect.conflict actual &&
541 git rm -f submod &&
542 - test ! -d submod &&
542 + test_path_is_missing submod &&
543 git status -s -uno --ignore-submodules=none >actual &&
544 test_cmp expect actual
545 '
@@ -556,13 +556,13 @@ test_expect_success 'rm of a conflicted populated submodule with a .git director
556 ) &&
557 test_must_fail git merge conflict2 &&
558 test_must_fail git rm submod &&
559 - test -d submod &&
560 - test -d submod/.git &&
559 + test_path_is_dir submod &&
560 + test_path_is_dir submod/.git &&
561 git status -s -uno --ignore-submodules=none >actual &&
562 test_cmp expect.conflict actual &&
563 test_must_fail git rm -f submod &&
564 - test -d submod &&
565 - test -d submod/.git &&
564 + test_path_is_dir submod &&
565 + test_path_is_dir submod/.git &&
566 git status -s -uno --ignore-submodules=none >actual &&
567 test_cmp expect.conflict actual &&
568 git merge --abort &&
@@ -574,7 +574,7 @@ test_expect_success 'rm of a conflicted unpopulated submodule succeeds' '
574 git reset --hard &&
575 test_must_fail git merge conflict2 &&
576 git rm submod &&
577 - test ! -d submod &&
577 + test_path_is_missing submod &&
578 git status -s -uno --ignore-submodules=none >actual &&
579 test_cmp expect actual
580 '
@@ -591,10 +591,10 @@ test_expect_success 'rm of a populated submodule with a .git directory migrates
591 rm -r ../.git/modules/sub
592 ) &&
593 git rm submod 2>output.err &&
594 - ! test -d submod &&
595 - ! test -d submod/.git &&
594 + test_path_is_missing submod &&
595 + test_path_is_missing submod/.git &&
596 git status -s -uno --ignore-submodules=none >actual &&
597 - test -s actual &&
597 + test_file_not_empty actual &&
598 test_i18ngrep Migrating output.err
599 '
600
@@ -620,7 +620,7 @@ test_expect_success 'setup subsubmodule' '
620
621 test_expect_success 'rm recursively removes work tree of unmodified submodules' '
622 git rm submod &&
623 - test ! -d submod &&
623 + test_path_is_missing submod &&
624 git status -s -uno --ignore-submodules=none >actual &&
625 test_cmp expect actual
626 '
@@ -630,12 +630,12 @@ test_expect_success 'rm of a populated nested submodule with different nested HE
630 git submodule update --recursive &&
631 git -C submod/subsubmod checkout HEAD^ &&
632 test_must_fail git rm submod &&
633 - test -d submod &&
634 - test -f submod/.git &&
633 + test_path_is_dir submod &&
634 + test_path_is_file submod/.git &&
635 git status -s -uno --ignore-submodules=none >actual &&
636 test_cmp expect.modified_inside actual &&
637 git rm -f submod &&
638 - test ! -d submod &&
638 + test_path_is_missing submod &&
639 git status -s -uno --ignore-submodules=none >actual &&
640 test_cmp expect actual
641 '
@@ -645,12 +645,12 @@ test_expect_success 'rm of a populated nested submodule with nested modification
645 git submodule update --recursive &&
646 echo X >submod/subsubmod/empty &&
647 test_must_fail git rm submod &&
648 - test -d submod &&
649 - test -f submod/.git &&
648 + test_path_is_dir submod &&
649 + test_path_is_file submod/.git &&
650 git status -s -uno --ignore-submodules=none >actual &&
651 test_cmp expect.modified_inside actual &&
652 git rm -f submod &&
653 - test ! -d submod &&
653 + test_path_is_missing submod &&
654 git status -s -uno --ignore-submodules=none >actual &&
655 test_cmp expect actual
656 '
@@ -660,12 +660,12 @@ test_expect_success 'rm of a populated nested submodule with nested untracked fi
660 git submodule update --recursive &&
661 echo X >submod/subsubmod/untracked &&
662 test_must_fail git rm submod &&
663 - test -d submod &&
664 - test -f submod/.git &&
663 + test_path_is_dir submod &&
664 + test_path_is_file submod/.git &&
665 git status -s -uno --ignore-submodules=none >actual &&
666 test_cmp expect.modified_untracked actual &&
667 git rm -f submod &&
668 - test ! -d submod &&
668 + test_path_is_missing submod &&
669 git status -s -uno --ignore-submodules=none >actual &&
670 test_cmp expect actual
671 '
@@ -680,10 +680,10 @@ test_expect_success "rm absorbs submodule's nested .git directory" '
680 GIT_WORK_TREE=. git config --unset core.worktree
681 ) &&
682 git rm submod 2>output.err &&
683 - ! test -d submod &&
684 - ! test -d submod/subsubmod/.git &&
683 + test_path_is_missing submod &&
684 + test_path_is_missing submod/subsubmod/.git &&
685 git status -s -uno --ignore-submodules=none >actual &&
686 - test -s actual &&
686 + test_file_not_empty actual &&
687 test_i18ngrep Migrating output.err
688 '
689