t7001-mv.sh: modernizing test script using functions

Test script to verify the presence/absence of files, paths, directories, symlinks and other features in 'git mv' command are using the command format: 'test (-e|f|d|h|...)' Replace them with helper functions of format: 'test_path_is_*' Replacing idiomatic helper functions: '! test_path_is_*' with 'test_path_is_missing' This uses values of 'test_path_bar' in place of '! test_path_foo' to bring in the helpful factor of indicating the failure of tests after the mv command has been used, that is, it echoes if the feature/test_path exists. Signed-off-by: Debra Obondo <debraobondo@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Debra Obondo committed Nov 4, 2022 at 15:05 UTC 7cccf5b6c98ccca1a21fccbf3cd60978c5f8257d
1 file changed +31 -31
t/t7001-mv.sh
+31 -31
@@ -60,8 +60,8 @@ test_expect_success 'checking the commit' '
60
61 test_expect_success 'mv --dry-run does not move file' '
62 git mv -n path0/COPYING MOVED &&
63 - test -f path0/COPYING &&
64 - test ! -f MOVED
63 + test_path_is_file path0/COPYING &&
64 + test_path_is_missing MOVED
65 '
66
67 test_expect_success 'checking -k on non-existing file' '
@@ -71,25 +71,25 @@ test_expect_success 'checking -k on non-existing file' '
71 test_expect_success 'checking -k on untracked file' '
72 >untracked1 &&
73 git mv -k untracked1 path0 &&
74 - test -f untracked1 &&
75 - test ! -f path0/untracked1
74 + test_path_is_file untracked1 &&
75 + test_path_is_missing path0/untracked1
76 '
77
78 test_expect_success 'checking -k on multiple untracked files' '
79 >untracked2 &&
80 git mv -k untracked1 untracked2 path0 &&
81 - test -f untracked1 &&
82 - test -f untracked2 &&
83 - test ! -f path0/untracked1 &&
84 - test ! -f path0/untracked2
81 + test_path_is_file untracked1 &&
82 + test_path_is_file untracked2 &&
83 + test_path_is_missing path0/untracked1 &&
84 + test_path_is_missing path0/untracked2
85 '
86
87 test_expect_success 'checking -f on untracked file with existing target' '
88 >path0/untracked1 &&
89 test_must_fail git mv -f untracked1 path0 &&
90 - test ! -f .git/index.lock &&
91 - test -f untracked1 &&
92 - test -f path0/untracked1
90 + test_path_is_missing .git/index.lock &&
91 + test_path_is_file untracked1 &&
92 + test_path_is_file path0/untracked1
93 '
94
95 # clean up the mess in case bad things happen
@@ -215,8 +215,8 @@ test_expect_success 'absolute pathname' '
215 git add sub/file &&
216
217 git mv sub "$(pwd)/in" &&
218 - ! test -d sub &&
219 - test -d in &&
218 + test_path_is_missing sub &&
219 + test_path_is_dir in &&
220 git ls-files --error-unmatch in/file
221 )
222 '
@@ -234,8 +234,8 @@ test_expect_success 'absolute pathname outside should fail' '
234 git add sub/file &&
235
236 test_must_fail git mv sub "$out/out" &&
237 - test -d sub &&
238 - ! test -d ../in &&
237 + test_path_is_dir sub &&
238 + test_path_is_missing ../in &&
239 git ls-files --error-unmatch sub/file
240 )
241 '
@@ -295,8 +295,8 @@ test_expect_success 'git mv should overwrite symlink to a file' '
295 git add moved &&
296 test_must_fail git mv moved symlink &&
297 git mv -f moved symlink &&
298 - ! test -e moved &&
299 - test -f symlink &&
298 + test_path_is_missing moved &&
299 + test_path_is_file symlink &&
300 test "$(cat symlink)" = 1 &&
301 git update-index --refresh &&
302 git diff-files --quiet
@@ -312,13 +312,13 @@ test_expect_success 'git mv should overwrite file with a symlink' '
312 git add moved &&
313 test_must_fail git mv symlink moved &&
314 git mv -f symlink moved &&
315 - ! test -e symlink &&
315 + test_path_is_missing symlink &&
316 git update-index --refresh &&
317 git diff-files --quiet
318 '
319
320 test_expect_success SYMLINKS 'check moved symlink' '
321 - test -h moved
321 + test_path_is_symlink moved
322 '
323
324 rm -f moved symlink
@@ -352,7 +352,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and no .gitm
352 ) &&
353 mkdir mod &&
354 git mv sub mod/sub &&
355 - ! test -e sub &&
355 + test_path_is_missing sub &&
356 test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" &&
357 git -C mod/sub status &&
358 git update-index --refresh &&
@@ -372,7 +372,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and .gitmodu
372 ) &&
373 mkdir mod &&
374 git mv sub mod/sub &&
375 - ! test -e sub &&
375 + test_path_is_missing sub &&
376 test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" &&
377 git -C mod/sub status &&
378 echo mod/sub >expected &&
@@ -389,7 +389,7 @@ test_expect_success 'git mv moves a submodule with gitfile' '
389 entry="$(git ls-files --stage sub | cut -f 1)" &&
390 mkdir mod &&
391 git -C mod mv ../sub/ . &&
392 - ! test -e sub &&
392 + test_path_is_missing sub &&
393 test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" &&
394 git -C mod/sub status &&
395 echo mod/sub >expected &&
@@ -408,7 +408,7 @@ test_expect_success 'mv does not complain when no .gitmodules file is found' '
408 mkdir mod &&
409 git mv sub mod/sub 2>actual.err &&
410 test_must_be_empty actual.err &&
411 - ! test -e sub &&
411 + test_path_is_missing sub &&
412 test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" &&
413 git -C mod/sub status &&
414 git update-index --refresh &&
@@ -423,13 +423,13 @@ test_expect_success 'mv will error out on a modified .gitmodules file unless sta
423 entry="$(git ls-files --stage sub | cut -f 1)" &&
424 mkdir mod &&
425 test_must_fail git mv sub mod/sub 2>actual.err &&
426 - test -s actual.err &&
427 - test -e sub &&
426 + test_file_not_empty actual.err &&
427 + test_path_exists sub &&
428 git diff-files --quiet -- sub &&
429 git add .gitmodules &&
430 git mv sub mod/sub 2>actual.err &&
431 test_must_be_empty actual.err &&
432 - ! test -e sub &&
432 + test_path_is_missing sub &&
433 test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" &&
434 git -C mod/sub status &&
435 git update-index --refresh &&
@@ -447,7 +447,7 @@ test_expect_success 'mv issues a warning when section is not found in .gitmodule
447 mkdir mod &&
448 git mv sub mod/sub 2>actual.err &&
449 test_cmp expect.err actual.err &&
450 - ! test -e sub &&
450 + test_path_is_missing sub &&
451 test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" &&
452 git -C mod/sub status &&
453 git update-index --refresh &&
@@ -460,7 +460,7 @@ test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
460 git submodule update &&
461 mkdir mod &&
462 git mv -n sub mod/sub 2>actual.err &&
463 - test -f sub/.git &&
463 + test_path_is_file sub/.git &&
464 git diff-index --exit-code HEAD &&
465 git update-index --refresh &&
466 git diff-files --quiet -- sub .gitmodules
@@ -474,10 +474,10 @@ test_expect_success 'checking out a commit before submodule moved needs manual u
474 git status -s sub2 >actual &&
475 echo "?? sub2/" >expected &&
476 test_cmp expected actual &&
477 - ! test -f sub/.git &&
478 - test -f sub2/.git &&
477 + test_path_is_missing sub/.git &&
478 + test_path_is_file sub2/.git &&
479 git submodule update &&
480 - test -f sub/.git &&
480 + test_path_is_file sub/.git &&
481 rm -rf sub2 &&
482 git diff-index --exit-code HEAD &&
483 git update-index --refresh &&