Modernizing the t7001 test script
cover Modernizing the t7001 test script
In this patch series modernize the t7001 test script by changing the style of its tests from an old one to the modern one and by cleaning up the test script.
Shubham Verma (11):
t7001: convert tests from the old style to the current style
t7001: use TAB instead of spaces
t7001: remove unnecessary blank lines
t7001: change the style for cd according to subshell
t7001: remove whitespace after redirect operators
t7001: change (cd <path> && git foo) to (git -C <path> foo)
t7001: use ': >' rather than 'touch'
t7001: put each command on a separate line
t7001: use here-docs instead of echo
t7001: use test rather than [
t7001: move cleanup code from outside the tests into them
t/t7001-mv.sh | 393 +++++++++++++++++++++++--------------------------- 1 file changed, 181 insertions(+), 212 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/11 t7001: convert tests from the old style to the current style
From: Shubham Verma <[email protected]>
To modernize the t7001 test script, let's change the style of its tests from an old one to the modern one.
--- t/t7001-mv.sh | 192 +++++++++++++++++++++++++------------------------- 1 file changed, 96 insertions(+), 96 deletions(-)
t/t7001-mv.sh +96 -96
@@ -3,74 +3,74 @@ test_description='git mv in subdirs' . ./test-lib.sh -test_expect_success \ - 'prepare reference tree' \ - 'mkdir path0 path1 && +test_expect_success 'prepare reference tree' ' + mkdir path0 path1 && cp "$TEST_DIRECTORY"/../COPYING path0/COPYING && git add path0/COPYING && - git commit -m add -a' + git commit -m add -a +' -test_expect_success \ - 'moving the file out of subdirectory' \ - 'cd path0 && git mv COPYING ../path1/COPYING' +test_expect_success 'moving the file out of subdirectory' ' + cd path0 && git mv COPYING ../path1/COPYING +' # in path0 currently -test_expect_success \ - 'commiting the change' \ - 'cd .. && git commit -m move-out -a' +test_expect_success 'commiting the change' ' + cd .. && git commit -m move-out -a +' -test_expect_success \ - 'checking the commit' \ - 'git diff-tree -r -M --name-status HEAD^ HEAD >actual && - grep "^R100..*path0/COPYING..*path1/COPYING" actual' +test_expect_success 'checking the commit' ' + git diff-tree -r -M --name-status HEAD^ HEAD >actual && + grep "^R100..*path0/COPYING..*path1/COPYING" actual +' -test_expect_success \ - 'moving the file back into subdirectory' \ - 'cd path0 && git mv ../path1/COPYING COPYING' +test_expect_success 'moving the file back into subdirectory' ' + cd path0 && git mv ../path1/COPYING COPYING +' # in path0 currently -test_expect_success \ - 'commiting the change' \ - 'cd .. && git commit -m move-in -a' - -test_expect_success \ - 'checking the commit' \ - 'git diff-tree -r -M --name-status HEAD^ HEAD >actual && - grep "^R100..*path1/COPYING..*path0/COPYING" actual' - -test_expect_success \ - 'mv --dry-run does not move file' \ - 'git mv -n path0/COPYING MOVED && +test_expect_success 'commiting the change' ' + cd .. && git commit -m move-in -a +' + +test_expect_success 'checking the commit' ' + git diff-tree -r -M --name-status HEAD^ HEAD >actual && + grep "^R100..*path1/COPYING..*path0/COPYING" actual +' + +test_expect_success 'mv --dry-run does not move file' ' + git mv -n path0/COPYING MOVED && test -f path0/COPYING && - test ! -f MOVED' + test ! -f MOVED +' -test_expect_success \ - 'checking -k on non-existing file' \ - 'git mv -k idontexist path0' +test_expect_success 'checking -k on non-existing file' ' + git mv -k idontexist path0 +' -test_expect_success \ - 'checking -k on untracked file' \ - 'touch untracked1 && +test_expect_success 'checking -k on untracked file' ' + touch untracked1 && git mv -k untracked1 path0 && test -f untracked1 && - test ! -f path0/untracked1' + test ! -f path0/untracked1 +' -test_expect_success \ - 'checking -k on multiple untracked files' \ - 'touch untracked2 && +test_expect_success 'checking -k on multiple untracked files' ' + touch untracked2 && git mv -k untracked1 untracked2 path0 && test -f untracked1 && test -f untracked2 && test ! -f path0/untracked1 && - test ! -f path0/untracked2' + test ! -f path0/untracked2 +' -test_expect_success \ - 'checking -f on untracked file with existing target' \ - 'touch path0/untracked1 && +test_expect_success 'checking -f on untracked file with existing target' ' + touch path0/untracked1 && test_must_fail git mv -f untracked1 path0 && test ! -f .git/index.lock && test -f untracked1 && - test -f path0/untracked1' + test -f path0/untracked1 +' # clean up the mess in case bad things happen rm -f idontexist untracked1 untracked2 \
@@ -78,79 +78,79 @@ rm -f idontexist untracked1 untracked2 \ .git/index.lock rmdir path1 -test_expect_success \ - 'moving to absent target with trailing slash' \ - 'test_must_fail git mv path0/COPYING no-such-dir/ && +test_expect_success 'moving to absent target with trailing slash' ' + test_must_fail git mv path0/COPYING no-such-dir/ && test_must_fail git mv path0/COPYING no-such-dir// && git mv path0/ no-such-dir/ && - test_path_is_dir no-such-dir' + test_path_is_dir no-such-dir +' -test_expect_success \ - 'clean up' \ - 'git reset --hard' +test_expect_success 'clean up' ' + git reset --hard +' -test_expect_success \ - 'moving to existing untracked target with trailing slash' \ - 'mkdir path1 && +test_expect_success 'moving to existing untracked target with trailing slash' ' + mkdir path1 && git mv path0/ path1/ && - test_path_is_dir path1/path0/' + test_path_is_dir path1/path0/ +' -test_expect_success \ - 'moving to existing tracked target with trailing slash' \ - 'mkdir path2 && +test_expect_success 'moving to existing tracked target with trailing slash' ' + mkdir path2 && >path2/file && git add path2/file && git mv path1/path0/ path2/ && - test_path_is_dir path2/path0/' + test_path_is_dir path2/path0/ +' -test_expect_success \ - 'clean up' \ - 'git reset --hard' +test_expect_success 'clean up' ' + git reset --hard +' -test_expect_success \ - 'adding another file' \ - 'cp "$TEST_DIRECTORY"/../README.md path0/README && +test_expect_success 'adding another file' ' + cp "$TEST_DIRECTORY"/../README.md path0/README && git add path0/README && - git commit -m add2 -a' + git commit -m add2 -a +' -test_expect_success \ - 'moving whole subdirectory' \ - 'git mv path0 path2' +test_expect_success 'moving whole subdirectory' ' + git mv path0 path2 +' -test_expect_success \ - 'commiting the change' \ - 'git commit -m dir-move -a' +test_expect_success 'commiting the change' ' + git commit -m dir-move -a +' -test_expect_success \ - 'checking the commit' \ - 'git diff-tree -r -M --name-status HEAD^ HEAD >actual && +test_expect_success 'checking the commit' ' + git diff-tree -r -M --name-status HEAD^ HEAD >actual && grep "^R100..*path0/COPYING..*path2/COPYING" actual && - grep "^R100..*path0/README..*path2/README" actual' + grep "^R100..*path0/README..*path2/README" actual +' -test_expect_success \ - 'succeed when source is a prefix of destination' \ - 'git mv path2/COPYING path2/COPYING-renamed' +test_expect_success 'succeed when source is a prefix of destination' ' + git mv path2/COPYING path2/COPYING-renamed +' -test_expect_success \ - 'moving whole subdirectory into subdirectory' \ - 'git mv path2 path1' +test_expect_success 'moving whole subdirectory into subdirectory' ' + git mv path2 path1 +' -test_expect_success \ - 'commiting the change' \ - 'git commit -m dir-move -a' +test_expect_success 'commiting the change' ' + git commit -m dir-move -a +' -test_expect_success \ - 'checking the commit' \ - 'git diff-tree -r -M --name-status HEAD^ HEAD >actual && +test_expect_success 'checking the commit' ' + git diff-tree -r -M --name-status HEAD^ HEAD >actual && grep "^R100..*path2/COPYING..*path1/path2/COPYING" actual && - grep "^R100..*path2/README..*path1/path2/README" actual' + grep "^R100..*path2/README..*path1/path2/README" actual +' -test_expect_success \ - 'do not move directory over existing directory' \ - 'mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0' +test_expect_success 'do not move directory over existing directory' ' + mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0 +' -test_expect_success \ - 'move into "."' \ - 'git mv path1/path2/ .' +test_expect_success 'move into "."' ' + git mv path1/path2/ . +' test_expect_success "Michael Cassar's test case" ' rm -fr .git papers partA &&
Signature · 1 line
2.25.1
Re: [PATCH 01/11] t7001: convert tests from the old style to the current style
Quoted 4 lines · shubham verma
t7001: convert tests from the old style to the current style
To modernize the t7001 test script, let's change the style of its tests from an old one to the modern one.
This commit message could help reviewers more by giving an example of how the style is being updated because it's not so easy to pick up the details from the patch itself since it's so noisy. Perhaps the commit message could say something like:
t7001: modernize test formatting
Some tests in this script are formatted using a very old style:
test_expect_success \
'title' \
'body line 1 &&
body line 2'
Update the formatting to the modern style:
test_expect_success 'title' '
body line 1 &&
body line 2
'
Quoted 1 line
Signed-off-by shubham verma <[email protected]>
PATCH 2/11 t7001: use TAB instead of spaces
In reply to shubham vermaFrom: Shubham Verma <[email protected]>
Change indentation style from spaces to TAB.
--- t/t7001-mv.sh | 120 +++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 60 deletions(-)
t/t7001-mv.sh +60 -60
@@ -4,72 +4,72 @@ test_description='git mv in subdirs' . ./test-lib.sh test_expect_success 'prepare reference tree' ' - mkdir path0 path1 && - cp "$TEST_DIRECTORY"/../COPYING path0/COPYING && - git add path0/COPYING && - git commit -m add -a + mkdir path0 path1 && + cp "$TEST_DIRECTORY"/../COPYING path0/COPYING && + git add path0/COPYING && + git commit -m add -a ' test_expect_success 'moving the file out of subdirectory' ' - cd path0 && git mv COPYING ../path1/COPYING + cd path0 && git mv COPYING ../path1/COPYING ' # in path0 currently test_expect_success 'commiting the change' ' - cd .. && git commit -m move-out -a + cd .. && git commit -m move-out -a ' test_expect_success 'checking the commit' ' - git diff-tree -r -M --name-status HEAD^ HEAD >actual && - grep "^R100..*path0/COPYING..*path1/COPYING" actual + git diff-tree -r -M --name-status HEAD^ HEAD >actual && + grep "^R100..*path0/COPYING..*path1/COPYING" actual ' test_expect_success 'moving the file back into subdirectory' ' - cd path0 && git mv ../path1/COPYING COPYING + cd path0 && git mv ../path1/COPYING COPYING ' # in path0 currently test_expect_success 'commiting the change' ' - cd .. && git commit -m move-in -a + cd .. && git commit -m move-in -a ' test_expect_success 'checking the commit' ' - git diff-tree -r -M --name-status HEAD^ HEAD >actual && - grep "^R100..*path1/COPYING..*path0/COPYING" actual + git diff-tree -r -M --name-status HEAD^ HEAD >actual && + grep "^R100..*path1/COPYING..*path0/COPYING" actual ' test_expect_success 'mv --dry-run does not move file' ' - git mv -n path0/COPYING MOVED && - test -f path0/COPYING && - test ! -f MOVED + git mv -n path0/COPYING MOVED && + test -f path0/COPYING && + test ! -f MOVED ' test_expect_success 'checking -k on non-existing file' ' - git mv -k idontexist path0 + git mv -k idontexist path0 ' test_expect_success 'checking -k on untracked file' ' - touch untracked1 && - git mv -k untracked1 path0 && - test -f untracked1 && - test ! -f path0/untracked1 + touch untracked1 && + git mv -k untracked1 path0 && + test -f untracked1 && + test ! -f path0/untracked1 ' test_expect_success 'checking -k on multiple untracked files' ' - touch untracked2 && - git mv -k untracked1 untracked2 path0 && - test -f untracked1 && - test -f untracked2 && - test ! -f path0/untracked1 && - test ! -f path0/untracked2 + touch untracked2 && + git mv -k untracked1 untracked2 path0 && + test -f untracked1 && + test -f untracked2 && + test ! -f path0/untracked1 && + test ! -f path0/untracked2 ' test_expect_success 'checking -f on untracked file with existing target' ' - touch path0/untracked1 && - test_must_fail git mv -f untracked1 path0 && - test ! -f .git/index.lock && - test -f untracked1 && - test -f path0/untracked1 + touch path0/untracked1 && + test_must_fail git mv -f untracked1 path0 && + test ! -f .git/index.lock && + test -f untracked1 && + test -f path0/untracked1 ' # clean up the mess in case bad things happen
@@ -79,77 +79,77 @@ rm -f idontexist untracked1 untracked2 \ rmdir path1 test_expect_success 'moving to absent target with trailing slash' ' - test_must_fail git mv path0/COPYING no-such-dir/ && - test_must_fail git mv path0/COPYING no-such-dir// && - git mv path0/ no-such-dir/ && - test_path_is_dir no-such-dir + test_must_fail git mv path0/COPYING no-such-dir/ && + test_must_fail git mv path0/COPYING no-such-dir// && + git mv path0/ no-such-dir/ && + test_path_is_dir no-such-dir ' test_expect_success 'clean up' ' - git reset --hard + git reset --hard ' test_expect_success 'moving to existing untracked target with trailing slash' ' - mkdir path1 && - git mv path0/ path1/ && - test_path_is_dir path1/path0/ + mkdir path1 && + git mv path0/ path1/ && + test_path_is_dir path1/path0/ ' test_expect_success 'moving to existing tracked target with trailing slash' ' - mkdir path2 && - >path2/file && git add path2/file && - git mv path1/path0/ path2/ && - test_path_is_dir path2/path0/ + mkdir path2 && + >path2/file && git add path2/file && + git mv path1/path0/ path2/ && + test_path_is_dir path2/path0/ ' test_expect_success 'clean up' ' - git reset --hard + git reset --hard ' test_expect_success 'adding another file' ' - cp "$TEST_DIRECTORY"/../README.md path0/README && - git add path0/README && - git commit -m add2 -a + cp "$TEST_DIRECTORY"/../README.md path0/README && + git add path0/README && + git commit -m add2 -a ' test_expect_success 'moving whole subdirectory' ' - git mv path0 path2 + git mv path0 path2 ' test_expect_success 'commiting the change' ' - git commit -m dir-move -a + git commit -m dir-move -a ' test_expect_success 'checking the commit' ' - git diff-tree -r -M --name-status HEAD^ HEAD >actual && - grep "^R100..*path0/COPYING..*path2/COPYING" actual && - grep "^R100..*path0/README..*path2/README" actual + git diff-tree -r -M --name-status HEAD^ HEAD >actual && + grep "^R100..*path0/COPYING..*path2/COPYING" actual && + grep "^R100..*path0/README..*path2/README" actual ' test_expect_success 'succeed when source is a prefix of destination' ' - git mv path2/COPYING path2/COPYING-renamed + git mv path2/COPYING path2/COPYING-renamed ' test_expect_success 'moving whole subdirectory into subdirectory' ' - git mv path2 path1 + git mv path2 path1 ' test_expect_success 'commiting the change' ' - git commit -m dir-move -a + git commit -m dir-move -a ' test_expect_success 'checking the commit' ' - git diff-tree -r -M --name-status HEAD^ HEAD >actual && - grep "^R100..*path2/COPYING..*path1/path2/COPYING" actual && - grep "^R100..*path2/README..*path1/path2/README" actual + git diff-tree -r -M --name-status HEAD^ HEAD >actual && + grep "^R100..*path2/COPYING..*path1/path2/COPYING" actual && + grep "^R100..*path2/README..*path1/path2/README" actual ' test_expect_success 'do not move directory over existing directory' ' - mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0 + mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0 ' test_expect_success 'move into "."' ' - git mv path1/path2/ . + git mv path1/path2/ . ' test_expect_success "Michael Cassar's test case" '
Signature · 1 line
2.25.1
Re: [PATCH 02/11] t7001: use TAB instead of spaces
Quoted 1 line · shubham verma
t7001: use TAB instead of spaces
Nit: "use" is a bit nebulous; I'd probably say:
t7001: indent with TABs instead of spaces
Quoted 1 line
Change indentation style from spaces to TAB.
...which would also allow you to drop this line altogether.
If you feel that you must write something in the body of the commit messages, then perhaps say something about how modern style is to indent test bodies with TABs rather than spaces.
Quoted 1 line
Signed-off-by shubham verma <[email protected]>
PATCH 3/11 t7001: remove unnecessary blank lines
In reply to shubham vermaFrom: Shubham Verma <[email protected]>
Some tests use a deprecated style in which there are unnecessary blank lines after the opening quote of the test body and before the closing quote. So we should removed these unnecessary blank lines.
--- t/t7001-mv.sh | 12 ------------ 1 file changed, 12 deletions(-)
t/t7001-mv.sh +0 -12
@@ -182,7 +182,6 @@ test_expect_success "Sergey Vlasov's test case" ' ' test_expect_success 'absolute pathname' '( - rm -fr mine && mkdir mine && cd mine &&
@@ -196,12 +195,9 @@ test_expect_success 'absolute pathname' '( ! test -d sub && test -d in && git ls-files --error-unmatch in/file - - )' test_expect_success 'absolute pathname outside should fail' '( - rm -fr mine && mkdir mine && cd mine &&
@@ -216,7 +212,6 @@ test_expect_success 'absolute pathname outside should fail' '( test -d sub && ! test -d ../in && git ls-files --error-unmatch sub/file - )' test_expect_success 'git mv to move multiple sources into a directory' '
@@ -232,7 +227,6 @@ test_expect_success 'git mv to move multiple sources into a directory' ' ' test_expect_success 'git mv should not change sha1 of moved cache entry' ' - rm -fr .git && git init && echo 1 >dirty &&
@@ -243,7 +237,6 @@ test_expect_success 'git mv should not change sha1 of moved cache entry' ' echo 2 >dirty2 && git mv dirty2 dirty && [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ] - ' rm -f dirty dirty2
@@ -266,7 +259,6 @@ test_expect_success 'git mv error on conflicted file' ' ' test_expect_success 'git mv should overwrite symlink to a file' ' - rm -fr .git && git init && echo 1 >moved &&
@@ -279,13 +271,11 @@ test_expect_success 'git mv should overwrite symlink to a file' ' test "$(cat symlink)" = 1 && git update-index --refresh && git diff-files --quiet - ' rm -f moved symlink test_expect_success 'git mv should overwrite file with a symlink' ' - rm -fr .git && git init && echo 1 >moved &&
@@ -296,11 +286,9 @@ test_expect_success 'git mv should overwrite file with a symlink' ' ! test -e symlink && git update-index --refresh && git diff-files --quiet - ' test_expect_success SYMLINKS 'check moved symlink' ' - test -h moved '
Signature · 1 line
2.25.1
Re: [PATCH 03/11] t7001: remove unnecessary blank lines
Quoted 3 lines · shubham verma
Some tests use a deprecated style in which there are unnecessary blank lines after the opening quote of the test body and before the closing quote. So we should removed these unnecessary blank lines.
s/So we should removed/Remove/
Otherwise, nice explanatory commit message.
One comment below not related directly to this patch (just something noticed in the patch conext lines)...
t/t7001-mv.sh test_expect_success "Sergey Vlasov's test case" '
Quoted 10 lines
Signed-off-by shubham verma <[email protected]>---
t/t7001-mv.sh +0
-0@@ -182,7 +182,6 @@ test_expect_success "Sergey Vlasov's test case" ' test_expect_success 'absolute pathname' '( )' test_expect_success 'absolute pathname outside should fail' '( )'
It is very uncommon style to hide the subshell as these two tests do:
test_expect_success 'title' '(
...
)'Instead, these should be formatted as:
test_expect_success 'title' '
(
...
)
'Note that the "(" and ")" of the subshell are indented with a TAB, and then the body of the subshell is indented again with another TAB in order to comply with current style guidelines.
Fixing these might possibly be done in patch [1/11], however, they are so unusual and would change indentation of the body lines that they might deserve a patch of their own to avoid being lost in the noise of [1/11].
Re: [PATCH 03/11] t7001: remove unnecessary blank lines
Quoted 14 lines · Eric Sunshine
It is very uncommon style to hide the subshell as these two tests do:
test_expect_success 'title' '( ... )'Instead, these should be formatted as:
test_expect_success 'title' ' ( ... ) '
Quoted 8 lines
Note that the "(" and ")" of the subshell are indented with a TAB, and then the body of the subshell is indented again with another TAB in order to comply with current style guidelines.
Fixing these might possibly be done in patch [1/11], however, they are so unusual and would change indentation of the body lines that they might deserve a patch of their own to avoid being lost in the noise of [1/11].
I agree that adding that to 01/11 might be too noisy, but 04/11 may be a good match.
Thanks.
PATCH 4/11 t7001: change the style for cd according to subshell
In reply to shubham vermaFrom: Shubham Verma <[email protected]>
In some tests there is not a proper spaces after opening paranthesis and before cd. So, Lets change the style for cd according to subshell.
--- t/t7001-mv.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
t/t7001-mv.sh +4 -2
@@ -503,14 +503,16 @@ test_expect_success 'moving a submodule in nested directories' ' test_expect_success 'moving nested submodules' ' git commit -am "cleanup commit" && mkdir sub_nested_nested && - (cd sub_nested_nested && + ( + cd sub_nested_nested && touch nested_level2 && git init && git add . && git commit -m "nested level 2" ) && mkdir sub_nested && - (cd sub_nested && + ( + cd sub_nested && touch nested_level1 && git init && git add . &&
Signature · 1 line
2.25.1
Re: [PATCH 04/11] t7001: change the style for cd according to subshell
Quoted 4 lines · shubham verma
t7001: change the style for cd according to subshell
In some tests there is not a proper spaces after opening paranthesis and before cd. So, Lets change the style for cd according to subshell.
Nits:
s/space/newline/
s/paranthesis/parenthesis/
s/So, Lets change/Change/
However, a more significant observation is that this change is actually specific to the formatting of subshells, and has nothing to do with placement of cd, so calling out cd in the commit message is misleading. I'd probably drop mention of cd altogether and write the commit message something like this:
t7001: modernize subshell formatting
Some test use an old style for formatting subshells:
(command &&
...
Update them to the modern style:
(
command &&
...The actual patch is fine.
Quoted 1 line
Signed-off-by shubham verma <[email protected]>
PATCH 5/11 t7001: remove whitespace after redirect operators
In reply to shubham vermaFrom: Shubham Verma <[email protected]>
According to Documentation/CodingGuidelines, there should be no whitespace after redirect operators. So, we should remove these whitespaces after redirect operators.
--- t/t7001-mv.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
t/t7001-mv.sh +3 -3
@@ -156,9 +156,9 @@ test_expect_success "Michael Cassar's test case" ' rm -fr .git papers partA && git init && mkdir -p papers/unsorted papers/all-papers partA && - echo a > papers/unsorted/Thesis.pdf && - echo b > partA/outline.txt && - echo c > papers/unsorted/_another && + echo a >papers/unsorted/Thesis.pdf && + echo b >partA/outline.txt && + echo c >papers/unsorted/_another && git add papers partA && T1=$(git write-tree) &&
Signature · 1 line
2.25.1
PATCH 6/11 t7001: change (cd <path> && git foo) to (git -C <path> foo)
In reply to shubham vermaFrom: Shubham Verma <[email protected]>
Let's avoid the use of cd outside subshells by encapsulating them inside subshells or by using git -C <dir> ....
--- t/t7001-mv.sh | 45 +++++++++++---------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-)
t/t7001-mv.sh +11 -34
@@ -11,12 +11,11 @@ test_expect_success 'prepare reference tree' ' ' test_expect_success 'moving the file out of subdirectory' ' - cd path0 && git mv COPYING ../path1/COPYING + git -C path0 mv COPYING ../path1/COPYING ' -# in path0 currently test_expect_success 'commiting the change' ' - cd .. && git commit -m move-out -a + git commit -m move-out -a ' test_expect_success 'checking the commit' '
@@ -25,12 +24,11 @@ test_expect_success 'checking the commit' ' ' test_expect_success 'moving the file back into subdirectory' ' - cd path0 && git mv ../path1/COPYING COPYING + git -C path0 mv ../path1/COPYING COPYING ' -# in path0 currently test_expect_success 'commiting the change' ' - cd .. && git commit -m move-in -a + git commit -m move-in -a ' test_expect_success 'checking the commit' '
@@ -324,10 +322,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and no .gitm git mv sub mod/sub && ! test -e sub && [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && - ( - cd mod/sub && - git status - ) && + git -C mod/sub status && git update-index --refresh && git diff-files --quiet '
@@ -347,10 +342,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and .gitmodu git mv sub mod/sub && ! test -e sub && [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && - ( - cd mod/sub && - git status - ) && + git -C mod/sub status && echo mod/sub >expected && git config -f .gitmodules submodule.sub.path >actual && test_cmp expected actual &&
@@ -364,16 +356,10 @@ test_expect_success 'git mv moves a submodule with gitfile' ' git submodule update && entry="$(git ls-files --stage sub | cut -f 1)" && mkdir mod && - ( - cd mod && - git mv ../sub/ . - ) && + git -C mod mv ../sub/ . && ! test -e sub && [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && - ( - cd mod/sub && - git status - ) && + git -C mod/sub status && echo mod/sub >expected && git config -f .gitmodules submodule.sub.path >actual && test_cmp expected actual &&
@@ -392,10 +378,7 @@ test_expect_success 'mv does not complain when no .gitmodules file is found' ' test_must_be_empty actual.err && ! test -e sub && [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && - ( - cd mod/sub && - git status - ) && + git -C mod/sub status && git update-index --refresh && git diff-files --quiet '
@@ -416,10 +399,7 @@ test_expect_success 'mv will error out on a modified .gitmodules file unless sta test_must_be_empty actual.err && ! test -e sub && [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && - ( - cd mod/sub && - git status - ) && + git -C mod/sub status && git update-index --refresh && git diff-files --quiet '
@@ -437,10 +417,7 @@ test_expect_success 'mv issues a warning when section is not found in .gitmodule test_i18ncmp expect.err actual.err && ! test -e sub && [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && - ( - cd mod/sub && - git status - ) && + git -C mod/sub status && git update-index --refresh && git diff-files --quiet '
Signature · 1 line
2.25.1
Re: [PATCH 06/11] t7001: change (cd <path> && git foo) to (git -C <path> foo)
Quoted 1 line · shubham verma
t7001: change (cd <path> && git foo) to (git -C <path> foo)
This is misleading. We don't want the git -C form in a subshell, so it shouldn't be enclosed in parentheses. Perhaps write it like this:
t7001 use git -C to avoid cd outside of subshells
Quoted 2 lines
Let's avoid the use of
cdoutside subshells by encapsulating them inside subshells or by usinggit -C <dir> ....
This is misleading in two ways. First, none of the changes made by this patch add subshell encapsulation. Second, many of the changes drop the subhsell in favor of git -C, so describing them as "cd outside of subshells" is wrong.
It's also important for the commit message to explain _why_ this change is important when cd is used outside of a subshell. A possible rewrite might be:
t7001: avoid using cd outside of subshells
Avoid using cd outside of subshells since, if the test fails, there is no guarantee that the current working directory is the expected one, which may cause subsequent tests to run in the wrong directory.
While at it, make some other tests more concise by replacing simple subshells with git -C.
In fact, fixing the cases in which cd is used outside of a subshell is much more important than the mere mechanical conversion made to the other tests by replacing a subshell with git -C. As such, I'm tempted to suggest splitting this patch into two: one which fixes the cases of cd outside of subshell, and another which converts the simple subshell cases to use git -C.
Quoted 4 lines
Signed-off-by shubham verma <[email protected]>---
t/t7001-mv.sh test_expect_success 'prepare reference tree' ' · line 17
Quoted 10 lines
t/t7001-mv.sh +2
-3@@ -11,12 +11,11 @@ test_expect_success 'prepare reference tree' ' test_expect_success 'moving the file out of subdirectory' ' - cd path0 && git mv COPYING ../path1/COPYING + git -C path0 mv COPYING ../path1/COPYING ' -# in path0 currently test_expect_success 'commiting the change' ' - cd .. && git commit -m move-out -a + git commit -m move-out -a '
This transformation looks fine, as do the following two tests which get the same transformation.
I do have a very slight hesitation, though, that these changes go against the grain of the tests. In particular, at the top of this script, we see:
test_description='git mv in subdirs'
which suggests that the tests really want to test the bare git mv command while actually running in a subdirectory. This would imply that these test should be rewritten as:
test_expect_success 'title' '
(
cd path0 &&
...
)
'However, it's such a minor misgiving that it's probably not worth considering.
t/t7001-mv.sh test_expect_success 'git mv moves a submodule with gitfile' ' · line 356
Quoted 6 lines
t/t7001-mv.sh +1
-4@@ -364,16 +356,10 @@ test_expect_success 'git mv moves a submodule with gitfile' ' - ( - cd mod && - git mv ../sub/ . - ) && + git -C mod mv ../sub/ . &&
Okay. At first glance one might expect you to strip the ../ from the argument, but indeed ../sub/ is correct since -C mod really does change to the new directory, so the argument is interpreted relative to mod.
PATCH 7/11 t7001: use ': >' rather than 'touch'
In reply to shubham vermaFrom: Shubham Verma <[email protected]>
Use > rather than touch to create an empty file when the timestamp isn't relevant to the test.
--- t/t7001-mv.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
t/t7001-mv.sh +5 -5
@@ -47,14 +47,14 @@ test_expect_success 'checking -k on non-existing file' ' ' test_expect_success 'checking -k on untracked file' ' - touch untracked1 && + : > untracked1 && git mv -k untracked1 path0 && test -f untracked1 && test ! -f path0/untracked1 ' test_expect_success 'checking -k on multiple untracked files' ' - touch untracked2 && + : > untracked2 && git mv -k untracked1 untracked2 path0 && test -f untracked1 && test -f untracked2 &&
@@ -63,7 +63,7 @@ test_expect_success 'checking -k on multiple untracked files' ' ' test_expect_success 'checking -f on untracked file with existing target' ' - touch path0/untracked1 && + : > path0/untracked1 && test_must_fail git mv -f untracked1 path0 && test ! -f .git/index.lock && test -f untracked1 &&
@@ -482,7 +482,7 @@ test_expect_success 'moving nested submodules' ' mkdir sub_nested_nested && ( cd sub_nested_nested && - touch nested_level2 && + : > nested_level2 && git init && git add . && git commit -m "nested level 2"
@@ -490,7 +490,7 @@ test_expect_success 'moving nested submodules' ' mkdir sub_nested && ( cd sub_nested && - touch nested_level1 && + : > nested_level1 && git init && git add . && git commit -m "nested level 1" &&
Signature · 1 line
2.25.1
Re: [PATCH 07/11] t7001: use ': >' rather than 'touch'
Quoted 4 lines · shubham verma
t7001: use ': >' rather than 'touch'
Use
>rather thantouchto create an empty file when the timestamp isn't relevant to the test.
There is an inconsistency here. In the subject you say ": >" but in the body just ">".
A couple more comments below...
t/t7001-mv.sh test_expect_success 'checking -k on non-existing file' ' · line 48
Quoted 7 lines
Signed-off-by shubham verma <[email protected]>---
t/t7001-mv.sh +1
-1@@ -47,14 +47,14 @@ test_expect_success 'checking -k on non-existing file' ' test_expect_success 'checking -k on untracked file' ' - touch untracked1 && + : > untracked1 &&
In patch [5/11] you dropped whitespace following the redirection operator, however, this patch introduces several new cases of unwanted whitespace.
Checking "master", I see that there are 209 instances of : > in tests, but 1023 instances of >, which suggests that we should stick with plain > rather than : > in this patch.
Re: [PATCH 07/11] t7001: use ': >' rather than 'touch'
Quoted 7 lines · Eric Sunshine
In patch [5/11] you dropped whitespace following the redirection operator, however, this patch introduces several new cases of unwanted whitespace.
Checking "master", I see that there are 209 instances of
: >in tests, but 1023 instances of>, which suggests that we should stick with plain>rather than: >in this patch.
Agreed on both points. Thanks for a careful review.
PATCH 8/11 t7001: put each command on a separate line
In reply to shubham vermaFrom: Shubham Verma <[email protected]>
Multiple commands on one line should be split across multiple lines.
--- t/t7001-mv.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
t/t7001-mv.sh +3 -1
@@ -143,7 +143,9 @@ test_expect_success 'checking the commit' ' ' test_expect_success 'do not move directory over existing directory' ' - mkdir path0 && mkdir path0/path2 && test_must_fail git mv path2 path0 + mkdir path0 && + mkdir path0/path2 && + test_must_fail git mv path2 path0 ' test_expect_success 'move into "."' '
Signature · 1 line
2.25.1
Re: [PATCH 08/11] t7001: put each command on a separate line
Quoted 1 line · shubham verma
Multiple commands on one line should be split across multiple lines.
Drop the extra whitespace between "line" and "should".
I might have written the commit message with a bit more explanation, perhaps like this:
Modern practice is to avoid multiple commands per line, and instead place each command on its own line.
The patch itself looks fine.
Quoted 1 line
Signed-off-by shubham verma <[email protected]>
PATCH 9/11 t7001: use here-docs instead of echo
In reply to shubham vermaFrom: Shubham Verma <[email protected]>
Change from old style to current style by taking advantage of here-docs instead of echo commands.
--- t/t7001-mv.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
t/t7001-mv.sh +4 -1
@@ -222,7 +222,10 @@ test_expect_success 'git mv to move multiple sources into a directory' ' git add dir/?.txt && git mv dir/a.txt dir/b.txt other && git ls-files >actual && - { echo other/a.txt; echo other/b.txt; } >expect && + cat >expect <<-\EOF && + other/a.txt + other/b.txt + EOF test_cmp expect actual '
Signature · 1 line
2.25.1
Re: [PATCH 09/11] t7001: use here-docs instead of echo
Quoted 15 lines · shubham verma
From: Shubham Verma <[email protected]>
Change from old style to current style by taking advantage of here-docs instead of echo commands.
Signed-off-by shubham verma <[email protected]>--- t/t7001-mv.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)t/t7001-mv.sh +0
-0
t/t7001-mv.sh test_expect_success 'git mv to move multiple sources into a directory' ' · line 228
Quoted 8 lines
t/t7001-mv.sh +4
-1@@ -222,7 +222,10 @@ test_expect_success 'git mv to move multiple sources into a directory' ' git add dir/?.txt && git mv dir/a.txt dir/b.txt other && git ls-files >actual && - { echo other/a.txt; echo other/b.txt; } >expect && + cat >expect <<-\EOF && + other/a.txt + other/b.txt + EOF
This could be written with test_write_lines but a here-doc would be a better option in this case, as we will see the expected output from the tested command in the exact form.
PATCH 10/11 t7001: use `test` rather than `[`
In reply to shubham vermaFrom: Shubham Verma <[email protected]>
According to Documentation/CodingGuidelines, we should use "test" rather than "[ ... ]" in shell scripts, so let's replace the "[ ... ]" with "test" in the t7001 test script.
--- t/t7001-mv.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
t/t7001-mv.sh +8 -8
@@ -236,10 +236,10 @@ test_expect_success 'git mv should not change sha1 of moved cache entry' ' git add dirty && entry="$(git ls-files --stage dirty | cut -f 1)" && git mv dirty dirty2 && - [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] && + test "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" && echo 2 >dirty2 && git mv dirty2 dirty && - [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ] + test "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ' rm -f dirty dirty2
@@ -326,7 +326,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and no .gitm mkdir mod && git mv sub mod/sub && ! test -e sub && - [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && + test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" && git -C mod/sub status && git update-index --refresh && git diff-files --quiet
@@ -346,7 +346,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and .gitmodu mkdir mod && git mv sub mod/sub && ! test -e sub && - [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && + test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" && git -C mod/sub status && echo mod/sub >expected && git config -f .gitmodules submodule.sub.path >actual &&
@@ -363,7 +363,7 @@ test_expect_success 'git mv moves a submodule with gitfile' ' mkdir mod && git -C mod mv ../sub/ . && ! test -e sub && - [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && + test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" && git -C mod/sub status && echo mod/sub >expected && git config -f .gitmodules submodule.sub.path >actual &&
@@ -382,7 +382,7 @@ test_expect_success 'mv does not complain when no .gitmodules file is found' ' git mv sub mod/sub 2>actual.err && test_must_be_empty actual.err && ! test -e sub && - [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && + test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" && git -C mod/sub status && git update-index --refresh && git diff-files --quiet
@@ -403,7 +403,7 @@ test_expect_success 'mv will error out on a modified .gitmodules file unless sta git mv sub mod/sub 2>actual.err && test_must_be_empty actual.err && ! test -e sub && - [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && + test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" && git -C mod/sub status && git update-index --refresh && git diff-files --quiet
@@ -421,7 +421,7 @@ test_expect_success 'mv issues a warning when section is not found in .gitmodule git mv sub mod/sub 2>actual.err && test_i18ncmp expect.err actual.err && ! test -e sub && - [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && + test "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" && git -C mod/sub status && git update-index --refresh && git diff-files --quiet
Signature · 1 line
2.25.1
PATCH 11/11 t7001: move cleanup code from outside the tests into them
In reply to shubham vermaFrom: Shubham Verma <[email protected]>
Let's use test_when_finished() to include cleanup code inside the tests, as it's cleaner and safer to not have any code outside the tests.
--- t/t7001-mv.sh | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)
t/t7001-mv.sh +11 -14
@@ -32,6 +32,7 @@ test_expect_success 'commiting the change' ' ' test_expect_success 'checking the commit' ' + test_when_finished "rmdir path1" && git diff-tree -r -M --name-status HEAD^ HEAD >actual && grep "^R100..*path1/COPYING..*path0/COPYING" actual '
@@ -43,6 +44,7 @@ test_expect_success 'mv --dry-run does not move file' ' ' test_expect_success 'checking -k on non-existing file' ' + test_when_finished "rm -f idontexist path0/idontexist" && git mv -k idontexist path0 '
@@ -55,6 +57,7 @@ test_expect_success 'checking -k on untracked file' ' test_expect_success 'checking -k on multiple untracked files' ' : > untracked2 && + test_when_finished "rm -f untracked2 path0/untracked2" && git mv -k untracked1 untracked2 path0 && test -f untracked1 && test -f untracked2 &&
@@ -64,18 +67,14 @@ test_expect_success 'checking -k on multiple untracked files' ' test_expect_success 'checking -f on untracked file with existing target' ' : > path0/untracked1 && + test_when_finished "rm -f untracked1 path0/untracked1" && + test_when_finished "rm -f .git/index.lock" && test_must_fail git mv -f untracked1 path0 && test ! -f .git/index.lock && test -f untracked1 && test -f path0/untracked1 ' -# clean up the mess in case bad things happen -rm -f idontexist untracked1 untracked2 \ - path0/idontexist path0/untracked1 path0/untracked2 \ - .git/index.lock -rmdir path1 - test_expect_success 'moving to absent target with trailing slash' ' test_must_fail git mv path0/COPYING no-such-dir/ && test_must_fail git mv path0/COPYING no-such-dir// &&
@@ -149,10 +148,12 @@ test_expect_success 'do not move directory over existing directory' ' ' test_expect_success 'move into "."' ' + test_when_finished "rm -fr path?" && git mv path1/path2/ . ' test_expect_success "Michael Cassar's test case" ' + test_when_finished "rm -fr papers partA" && rm -fr .git papers partA && git init && mkdir -p papers/unsorted papers/all-papers partA &&
@@ -168,8 +169,6 @@ test_expect_success "Michael Cassar's test case" ' git ls-tree -r $T | verbose grep partA/outline.txt ' -rm -fr papers partA path? - test_expect_success "Sergey Vlasov's test case" ' rm -fr .git && git init &&
@@ -230,6 +229,7 @@ test_expect_success 'git mv to move multiple sources into a directory' ' ' test_expect_success 'git mv should not change sha1 of moved cache entry' ' + test_when_finished "rm -f dirty dirty2" && rm -fr .git && git init && echo 1 >dirty &&
@@ -242,8 +242,6 @@ test_expect_success 'git mv should not change sha1 of moved cache entry' ' test "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ' -rm -f dirty dirty2 - # NB: This test is about the error message # as well as the failure. test_expect_success 'git mv error on conflicted file' '
@@ -262,6 +260,7 @@ test_expect_success 'git mv error on conflicted file' ' ' test_expect_success 'git mv should overwrite symlink to a file' ' + test_when_finished "rm -f moved symlink" && rm -fr .git && git init && echo 1 >moved &&
@@ -276,9 +275,8 @@ test_expect_success 'git mv should overwrite symlink to a file' ' git diff-files --quiet ' -rm -f moved symlink - test_expect_success 'git mv should overwrite file with a symlink' ' + test_when_finished "rm -f symlink" && rm -fr .git && git init && echo 1 >moved &&
@@ -292,11 +290,10 @@ test_expect_success 'git mv should overwrite file with a symlink' ' ' test_expect_success SYMLINKS 'check moved symlink' ' + test_when_finished "rm -f moved" && test -h moved ' -rm -f moved symlink - test_expect_success 'setup submodule' ' git commit -m initial && git reset --hard &&
Signature · 1 line
2.25.1
Re: [PATCH 11/11] t7001: move cleanup code from outside the tests into them
t/t7001-mv.sh test_expect_success 'commiting the change' ' · line 36
Quoted 12 lines · shubham verma
Let's use
test_when_finished()to include cleanup code inside the tests, as it's cleaner and safer to not have any code outside the tests.Signed-off-by shubham verma <[email protected]>---
t/t7001-mv.sh +1
-0@@ -32,6 +32,7 @@ test_expect_success 'commiting the change' ' test_expect_success 'checking the commit' ' + test_when_finished "rmdir path1" && git diff-tree -r -M --name-status HEAD^ HEAD >actual && grep "^R100..*path1/COPYING..*path0/COPYING" actual '
This one doesn't really pass the smell test. path1 was created by the "prepare reference tree" test; it is not created by this test, so it's not really this test's responsibility to clean it up. But it also can't be cleaned up by "prepare reference tree" since that is just a "setup" test, and path is used by subsequent tests.
Does anything actually fail if directory path1 is not removed? I ask because slightly below the point at which path1 is removed (outside of any tests) a different test goes ahead and re-creates path1. If it turns out that removal of path1 isn't actually necessary, then a better option might be simply to drop the global rmdir path1 altogether, along with the subsequent mkdir path1 which comes a bit later.
t/t7001-mv.sh test_expect_success 'mv --dry-run does not move file' ' · line 47
Quoted 5 lines
t/t7001-mv.sh +1
-0@@ -43,6 +44,7 @@ test_expect_success 'mv --dry-run does not move file' ' test_expect_success 'checking -k on non-existing file' ' + test_when_finished "rm -f idontexist path0/idontexist" && git mv -k idontexist path0 '
The paths being removed here shouldn't actually be created by this test, but if Git is somehow buggy and they do get created, then this is the appropriate place to clean them up. Good.
Quoted 8 lines
t/t7001-mv.sh +1
-0@@ -55,6 +57,7 @@ test_expect_success 'checking -k on untracked file' ' test_expect_success 'checking -k on multiple untracked files' ' : > untracked2 && + test_when_finished "rm -f untracked2 path0/untracked2" && git mv -k untracked1 untracked2 path0 && test -f untracked1 && test -f untracked2 &&
t/t7001-mv.sh test_expect_success 'checking -k on multiple untracked files' ' · line 75
Quoted 9 lines
t/t7001-mv.sh +2
-0@@ -64,18 +67,14 @@ test_expect_success 'checking -k on multiple untracked files' ' test_expect_success 'checking -f on untracked file with existing target' ' : > path0/untracked1 && + test_when_finished "rm -f untracked1 path0/untracked1" && + test_when_finished "rm -f .git/index.lock" && test_must_fail git mv -f untracked1 path0 && test ! -f .git/index.lock && test -f untracked1 && test -f path0/untracked1 '
This is a big ugly. untracked1 gets created by an earlier test but is then cleaned up by this subsequent test. That goes against the idea of test_when_finished(), which is that tests should clean up after themselves. Doing it this way also creates a smelly dependency between the tests. What I would recommend instead is having each test independently create and cleanup the "untracked" files it needs. This makes the tests a tiny bit more verbose but makes it much clearer to the reader that the tests are independent.
t/t7001-mv.sh test_expect_success 'do not move directory over existing directory' ' · line 151
Quoted 10 lines
t/t7001-mv.sh +1
-5-# clean up the mess in case bad things happen -rm -f idontexist untracked1 untracked2 \ - path0/idontexist path0/untracked1 path0/untracked2 \ - .git/index.lock -rmdir path1@@ -149,10 +148,12 @@ test_expect_success 'do not move directory over existing directory' ' test_expect_success 'move into "."' ' + test_when_finished "rm -fr path?" && git mv path1/path2/ . '
This is another of those cases which doesn't really pass the smell test. This may indeed be the final test in which the various path? subdirectories are used, but it isn't the test which created them, thus it isn't "cleaning up after itself".
If the test which might get tripped up by these path? directories is the "Sergey Vlasov's test case" test, then it probably would make more sense for _that_ test to do rm -fr path? as its very first step (not as a test_when_finished()) in order to prepare things the way it needs them (just as it already does rm -fr .git).
t/t7001-mv.sh test_expect_success 'do not move directory over existing directory' ' · line 159
Quoted 5 lines
t/t7001-mv.sh +1
-0test_expect_success "Michael Cassar's test case" ' + test_when_finished "rm -fr papers partA" && rm -fr .git papers partA && git init && mkdir -p papers/unsorted papers/all-papers partA &&
Cleaning these paths here makes sense since they are created and only used by this test.
t/t7001-mv.sh test_expect_success "Michael Cassar's test case" ' · line 171
Quoted 6 lines
t/t7001-mv.sh +0
-2@@ -168,8 +169,6 @@ test_expect_success "Michael Cassar's test case" ' -rm -fr papers partA path? - test_expect_success "Sergey Vlasov's test case" ' rm -fr .git && git init &&
So, given what I said above, the first line of this test might become:
rm -fr .git path? &&
t/t7001-mv.sh test_expect_success 'git mv should not change sha1 of moved cache entry' ' · line 245
Quoted 11 lines
t/t7001-mv.sh +1
-1@@ -230,6 +229,7 @@ test_expect_success 'git mv to move multiple sources into a directory' ' test_expect_success 'git mv should not change sha1 of moved cache entry' ' + test_when_finished "rm -f dirty dirty2" && rm -fr .git && git init && echo 1 >dirty &&@@ -242,8 +242,6 @@ test_expect_success 'git mv should not change sha1 of moved cache entry' ' test "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ' -rm -f dirty dirty2
Makes perfect sense.
t/t7001-mv.sh test_expect_success 'git mv should overwrite symlink to a file' ' · line 279
Quoted 11 lines
t/t7001-mv.sh +1
-1@@ -262,6 +260,7 @@ test_expect_success 'git mv error on conflicted file' ' test_expect_success 'git mv should overwrite symlink to a file' ' + test_when_finished "rm -f moved symlink" && rm -fr .git && git init && echo 1 >moved &&@@ -276,9 +275,8 @@ test_expect_success 'git mv should overwrite symlink to a file' ' git diff-files --quiet ' -rm -f moved symlink
Okay.
t/t7001-mv.sh test_expect_success 'git mv should overwrite symlink to a file' ' · line 282
Quoted 5 lines
t/t7001-mv.sh +1
-0test_expect_success 'git mv should overwrite file with a symlink' ' + test_when_finished "rm -f symlink" && rm -fr .git && git init && echo 1 >moved &&
This makes sense, but...
t/t7001-mv.sh test_expect_success 'git mv should overwrite file with a symlink' ' · line 293
Quoted 5 lines
t/t7001-mv.sh +1
-0@@ -292,11 +290,10 @@ test_expect_success 'git mv should overwrite file with a symlink' ' test_expect_success SYMLINKS 'check moved symlink' ' + test_when_finished "rm -f moved" && test -h moved '
... this test only gets run on platforms which support symlinks (see the SYMLINKS predicate in the test definition), so the moved file won't get cleaned up on platforms which don't support symlinks.
t/t7001-mv.sh test_expect_success 'git mv should overwrite file with a symlink' ' · line 295
Quoted 1 line
t/t7001-mv.sh +0
-1-rm -f moved symlink
If the moved file actually causes subsequent tests to fail, then this might be one of those rare instances in which you'd introduce a test merely to clean up state from earlier tests. Perhaps something like this:
test_expect_success 'cleanup symlink detritus' '
rm -r moved
'
However, if moved doesn't cause subsequent tests to fail, then it might also make sense instead just to leave it alone and not bother cleaning it up.
Re: [PATCH 11/11] t7001: move cleanup code from outside the tests into them
In reply to shubham vermaQuoted 15 lines · shubham verma
From: Shubham Verma <[email protected]>
Let's use
test_when_finished()to include cleanup code inside the tests, as it's cleaner and safer to not have any code outside the tests.Signed-off-by shubham verma <[email protected]>--- t/t7001-mv.sh | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)t/t7001-mv.sh +0
-0
t/t7001-mv.sh test_expect_success 'commiting the change' ' · line 38
Quoted 7 lines
t/t7001-mv.sh +1
-0@@ -32,6 +32,7 @@ test_expect_success 'commiting the change' ' ' test_expect_success 'checking the commit' ' + test_when_finished "rmdir path1" && git diff-tree -r -M --name-status HEAD^ HEAD >actual && grep "^R100..*path1/COPYING..*path0/COPYING" actual '
Sorry, but why in this test? It only runs diff-tree and runs grep, neither of which changes any state in the repository. Because the test does *not* create path1, and having or not having path1 on the filesystem would not affect the outcome of the test, I do not see how it makes sense to use test_when_finished in here.
If you are saying that path1 will no longer be used after this test finishes, test_when_finished should be done in the test before this one that used path1 the last, because this test does not care. It is probably the one that moves the file out of path1 back to path0 and records the result as a commit with title "move-in" (although if I were writing this test today, I would merge the "move and commit" into one step).
t/t7001-mv.sh test_expect_success 'mv --dry-run does not move file' ' · line 49
Quoted 7 lines
t/t7001-mv.sh +1
-0@@ -43,6 +44,7 @@ test_expect_success 'mv --dry-run does not move file' ' ' test_expect_success 'checking -k on non-existing file' ' + test_when_finished "rm -f idontexist path0/idontexist" && git mv -k idontexist path0 '
I do not see the point of "rm -f idontexist" in the post-test-cleanup at all. Some might see that path0/ideontexist is worth having there, in case the "mv" command gets so broken that it creates such a file by mistake, but Personally I'd prefer to use test_when_finished to clean up the side effects we _expect_ to cause. We cannot anticipate each and every breakage.
The other side of the coin is that this test DEPENDS ON the fact that idontexist does *NOT* exist before it runs "git mv -k idontexist path0", but nobody before us gives us any explicitly guarantee. This test also depends on the presence of path0 directory the same way. Instead of relying on others that came before us to have cleaned after themselves for us, we can more explicitly protect ourselves by making sure the pre-condition we depend on holds. I.e.
test_expect_success 'mv -k on non-exising file would not fail' '
mkdir -p path0 &&
rm -f idontexist path0/idontexist &&
git mv -k idontexist path0
'A broken "git mv" may or may not leave path0/idontexist behind, but as long as the tests that come after us protect themselves with the same principle of making sure the preconditions they care about do hold, we do not necessarily have to clean after ourselves. Since we expect we do not leave any side effect, I'd rather not to use test_when_finished here.
@@ -55,6 +57,7 @@ test_expect_success 'checking -k on untracked file' '
t/t7001-mv.sh test_expect_success 'checking -k on untracked file' ' · line 63
Quoted 7 lines
t/t7001-mv.sh +0
-0test_expect_success 'checking -k on multiple untracked files' 't/t7001-mv.sh +1
-0: > untracked2 && + test_when_finished "rm -f untracked2 path0/untracked2" && git mv -k untracked1 untracked2 path0 && test -f untracked1 && test -f untracked2 &&
An exercise to readers. Explain why
- we want to move test_when_finished _before_ ">untracked2" is created;
- "rm -f untrackd2" in test_when_finished is a good idea;
- "rm -f path0/untracked2" is not a good idea;
- we may want to do
>untracked1 && mkdir -p path0 &&
before "git mv -k ..." is tested.
t/t7001-mv.sh test_expect_success 'checking -k on multiple untracked files' ' · line 80
Quoted 9 lines
t/t7001-mv.sh +0
-6-# clean up the mess in case bad things happen -rm -f idontexist untracked1 untracked2 \ - path0/idontexist path0/untracked1 path0/untracked2 \ - .git/index.lock -rmdir path1 - test_expect_success 'moving to absent target with trailing slash' ' test_must_fail git mv path0/COPYING no-such-dir/ && test_must_fail git mv path0/COPYING no-such-dir// &&
It may be a better approach to move the above removals at the beginning of this test, just before the first test_must_fail line.
t/t7001-mv.sh test_expect_success "Michael Cassar's test case" ' · line 172
Quoted 3 lines
t/t7001-mv.sh +0
-2-rm -fr papers partA path? - test_expect_success "Sergey Vlasov's test case" '
Likewise.
Quoted 3 lines · shubham verma
In this patch series modernize the t7001 test script by changing the style of its tests from an old one to the modern one and by cleaning up the test script.
Thanks for tackling this task. I presume it was prompted by [1] or [2], as this series covers many of the items mentioned in [1]. Overall, the series looks good. I'll leave comments in a few of the individual patches.
[1]: https://lore.kernel.org/git/CAPig+cQpUu2UO-+jWn1nTaDykWnxwuEitzVB7PnW2SS_b7V8Hg@mail.gmail.com/
[2]: https://git.github.io/rev_news/2020/08/27/edition-66/
Quoted 6 lines · Eric Sunshine
Quoted 3 lines · shubham verma
In this patch series modernize the t7001 test script by changing the style of its tests from an old one to the modern one and by cleaning up the test script.
Quoted 7 lines
Thanks for tackling this task. I presume it was prompted by [1] or [2], as this series covers many of the items mentioned in [1]. Overall, the series looks good. I'll leave comments in a few of the individual patches.
[1]: https://lore.kernel.org/git/CAPig+cQpUu2UO-+jWn1nTaDykWnxwuEitzVB7PnW2SS_b7V8Hg@mail.gmail.com/
[2]: https://git.github.io/rev_news/2020/08/27/edition-66/
Eric, Actually I follow the Instruction that you pointed out in [1]. Okay, I improve the commits and make changes according to your comments.
Thank You!
Quoted 12 lines · Shubham Verma
Quoted 11 lines · Eric Sunshine
Quoted 3 lines · shubham verma
In this patch series modernize the t7001 test script by changing the style of its tests from an old one to the modern one and by cleaning up the test script.
Thanks for tackling this task. I presume it was prompted by [1] or [2], as this series covers many of the items mentioned in [1]. Overall, the series looks good. I'll leave comments in a few of the individual patches.
Quoted 7 lines
Quoted 2 lines
[1]: https://lore.kernel.org/git/CAPig+cQpUu2UO-+jWn1nTaDykWnxwuEitzVB7PnW2SS_b7V8Hg@mail.gmail.com/
[2]: https://git.github.io/rev_news/2020/08/27/edition-66/Eric, Actually I follow the Instruction that you pointed out in [1]. Okay, I improve the commits and make changes according to your comments.
Thank You!
This series has seen quite a many review comments, and as far as I remember, none of them was a suggestion that was hard to decipher.
It has been almost 3 months---has an update been posted that I missed?
Thanks.