Skip to content

Commit 7cccf5b

Browse files
fobiasic07ttaylorr
authored andcommitted
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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 63bba4f commit 7cccf5b

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

t/t7001-mv.sh

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ test_expect_success 'checking the commit' '
6060

6161
test_expect_success 'mv --dry-run does not move file' '
6262
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
6565
'
6666

6767
test_expect_success 'checking -k on non-existing file' '
@@ -71,25 +71,25 @@ test_expect_success 'checking -k on non-existing file' '
7171
test_expect_success 'checking -k on untracked file' '
7272
>untracked1 &&
7373
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
7676
'
7777

7878
test_expect_success 'checking -k on multiple untracked files' '
7979
>untracked2 &&
8080
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
8585
'
8686

8787
test_expect_success 'checking -f on untracked file with existing target' '
8888
>path0/untracked1 &&
8989
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
9393
'
9494

9595
# clean up the mess in case bad things happen
@@ -215,8 +215,8 @@ test_expect_success 'absolute pathname' '
215215
git add sub/file &&
216216
217217
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 &&
220220
git ls-files --error-unmatch in/file
221221
)
222222
'
@@ -234,8 +234,8 @@ test_expect_success 'absolute pathname outside should fail' '
234234
git add sub/file &&
235235
236236
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 &&
239239
git ls-files --error-unmatch sub/file
240240
)
241241
'
@@ -295,8 +295,8 @@ test_expect_success 'git mv should overwrite symlink to a file' '
295295
git add moved &&
296296
test_must_fail git mv moved symlink &&
297297
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 &&
300300
test "$(cat symlink)" = 1 &&
301301
git update-index --refresh &&
302302
git diff-files --quiet
@@ -312,13 +312,13 @@ test_expect_success 'git mv should overwrite file with a symlink' '
312312
git add moved &&
313313
test_must_fail git mv symlink moved &&
314314
git mv -f symlink moved &&
315-
! test -e symlink &&
315+
test_path_is_missing symlink &&
316316
git update-index --refresh &&
317317
git diff-files --quiet
318318
'
319319

320320
test_expect_success SYMLINKS 'check moved symlink' '
321-
test -h moved
321+
test_path_is_symlink moved
322322
'
323323

324324
rm -f moved symlink
@@ -352,7 +352,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and no .gitm
352352
) &&
353353
mkdir mod &&
354354
git mv sub mod/sub &&
355-
! test -e sub &&
355+
test_path_is_missing sub &&
356356
test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" &&
357357
git -C mod/sub status &&
358358
git update-index --refresh &&
@@ -372,7 +372,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and .gitmodu
372372
) &&
373373
mkdir mod &&
374374
git mv sub mod/sub &&
375-
! test -e sub &&
375+
test_path_is_missing sub &&
376376
test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" &&
377377
git -C mod/sub status &&
378378
echo mod/sub >expected &&
@@ -389,7 +389,7 @@ test_expect_success 'git mv moves a submodule with gitfile' '
389389
entry="$(git ls-files --stage sub | cut -f 1)" &&
390390
mkdir mod &&
391391
git -C mod mv ../sub/ . &&
392-
! test -e sub &&
392+
test_path_is_missing sub &&
393393
test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" &&
394394
git -C mod/sub status &&
395395
echo mod/sub >expected &&
@@ -408,7 +408,7 @@ test_expect_success 'mv does not complain when no .gitmodules file is found' '
408408
mkdir mod &&
409409
git mv sub mod/sub 2>actual.err &&
410410
test_must_be_empty actual.err &&
411-
! test -e sub &&
411+
test_path_is_missing sub &&
412412
test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" &&
413413
git -C mod/sub status &&
414414
git update-index --refresh &&
@@ -423,13 +423,13 @@ test_expect_success 'mv will error out on a modified .gitmodules file unless sta
423423
entry="$(git ls-files --stage sub | cut -f 1)" &&
424424
mkdir mod &&
425425
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 &&
428428
git diff-files --quiet -- sub &&
429429
git add .gitmodules &&
430430
git mv sub mod/sub 2>actual.err &&
431431
test_must_be_empty actual.err &&
432-
! test -e sub &&
432+
test_path_is_missing sub &&
433433
test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" &&
434434
git -C mod/sub status &&
435435
git update-index --refresh &&
@@ -447,7 +447,7 @@ test_expect_success 'mv issues a warning when section is not found in .gitmodule
447447
mkdir mod &&
448448
git mv sub mod/sub 2>actual.err &&
449449
test_cmp expect.err actual.err &&
450-
! test -e sub &&
450+
test_path_is_missing sub &&
451451
test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" &&
452452
git -C mod/sub status &&
453453
git update-index --refresh &&
@@ -460,7 +460,7 @@ test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
460460
git submodule update &&
461461
mkdir mod &&
462462
git mv -n sub mod/sub 2>actual.err &&
463-
test -f sub/.git &&
463+
test_path_is_file sub/.git &&
464464
git diff-index --exit-code HEAD &&
465465
git update-index --refresh &&
466466
git diff-files --quiet -- sub .gitmodules
@@ -474,10 +474,10 @@ test_expect_success 'checking out a commit before submodule moved needs manual u
474474
git status -s sub2 >actual &&
475475
echo "?? sub2/" >expected &&
476476
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 &&
479479
git submodule update &&
480-
test -f sub/.git &&
480+
test_path_is_file sub/.git &&
481481
rm -rf sub2 &&
482482
git diff-index --exit-code HEAD &&
483483
git update-index --refresh &&

0 commit comments

Comments
 (0)