git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] Modernizing the t7001 test script
@ 2020-09-25 17:02 shubham verma
  2020-09-25 17:02 ` [PATCH 01/11] t7001: convert tests from the old style to the current style shubham verma
                   ` (11 more replies)
  0 siblings, 12 replies; 27+ messages in thread
From: shubham verma @ 2020-09-25 17:02 UTC (permalink / raw)
  To: git

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(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 01/11] t7001: convert tests from the old style to the current style
  2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
@ 2020-09-25 17:02 ` shubham verma
  2020-09-25 17:40   ` Eric Sunshine
  2020-09-25 17:02 ` [PATCH 02/11] t7001: use TAB instead of spaces shubham verma
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 27+ messages in thread
From: shubham verma @ 2020-09-25 17:02 UTC (permalink / raw)
  To: git; +Cc: Shubham Verma

From: Shubham Verma <shubhunic@gmail.com>

To modernize the t7001 test script, let's change the style of
its tests from an old one to the modern one.

Signed-off-by: shubham verma <shubhunic@gmail.com>
---
 t/t7001-mv.sh | 192 +++++++++++++++++++++++++-------------------------
 1 file changed, 96 insertions(+), 96 deletions(-)

diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 63d5f41a12..4bbb51e578 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -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 &&
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 02/11] t7001: use TAB instead of spaces
  2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
  2020-09-25 17:02 ` [PATCH 01/11] t7001: convert tests from the old style to the current style shubham verma
@ 2020-09-25 17:02 ` shubham verma
  2020-09-25 17:44   ` Eric Sunshine
  2020-09-25 17:02 ` [PATCH 03/11] t7001: remove unnecessary blank lines shubham verma
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 27+ messages in thread
From: shubham verma @ 2020-09-25 17:02 UTC (permalink / raw)
  To: git; +Cc: Shubham Verma

From: Shubham Verma <shubhunic@gmail.com>

Change indentation style from spaces to TAB.

Signed-off-by: shubham verma <shubhunic@gmail.com>
---
 t/t7001-mv.sh | 120 +++++++++++++++++++++++++-------------------------
 1 file changed, 60 insertions(+), 60 deletions(-)

diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 4bbb51e578..7503233814 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -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" '
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 03/11] t7001: remove unnecessary blank lines
  2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
  2020-09-25 17:02 ` [PATCH 01/11] t7001: convert tests from the old style to the current style shubham verma
  2020-09-25 17:02 ` [PATCH 02/11] t7001: use TAB instead of spaces shubham verma
@ 2020-09-25 17:02 ` shubham verma
  2020-09-25 17:50   ` Eric Sunshine
  2020-09-25 17:02 ` [PATCH 04/11] t7001: change the style for cd according to subshell shubham verma
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 27+ messages in thread
From: shubham verma @ 2020-09-25 17:02 UTC (permalink / raw)
  To: git; +Cc: Shubham Verma

From: Shubham Verma <shubhunic@gmail.com>

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.

Signed-off-by: shubham verma <shubhunic@gmail.com>
---
 t/t7001-mv.sh | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 7503233814..f63802442b 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -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
 '
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 04/11] t7001: change the style for cd according to subshell
  2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
                   ` (2 preceding siblings ...)
  2020-09-25 17:02 ` [PATCH 03/11] t7001: remove unnecessary blank lines shubham verma
@ 2020-09-25 17:02 ` shubham verma
  2020-09-25 18:12   ` Eric Sunshine
  2020-09-25 17:02 ` [PATCH 05/11] t7001: remove whitespace after redirect operators shubham verma
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 27+ messages in thread
From: shubham verma @ 2020-09-25 17:02 UTC (permalink / raw)
  To: git; +Cc: Shubham Verma

From: Shubham Verma <shubhunic@gmail.com>

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.

Signed-off-by: shubham verma <shubhunic@gmail.com>
---
 t/t7001-mv.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index f63802442b..67585b7d94 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -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 . &&
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 05/11] t7001: remove whitespace after redirect operators
  2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
                   ` (3 preceding siblings ...)
  2020-09-25 17:02 ` [PATCH 04/11] t7001: change the style for cd according to subshell shubham verma
@ 2020-09-25 17:02 ` shubham verma
  2020-09-25 17:02 ` [PATCH 06/11] t7001: change (cd <path> && git foo) to (git -C <path> foo) shubham verma
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 27+ messages in thread
From: shubham verma @ 2020-09-25 17:02 UTC (permalink / raw)
  To: git; +Cc: Shubham Verma

From: Shubham Verma <shubhunic@gmail.com>

According to Documentation/CodingGuidelines, there should be no
whitespace after redirect operators. So, we should remove these
whitespaces after redirect operators.

Signed-off-by: shubham verma <shubhunic@gmail.com>
---
 t/t7001-mv.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 67585b7d94..7581e4b407 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -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) &&
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 06/11] t7001: change (cd <path> && git foo) to (git -C <path> foo)
  2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
                   ` (4 preceding siblings ...)
  2020-09-25 17:02 ` [PATCH 05/11] t7001: remove whitespace after redirect operators shubham verma
@ 2020-09-25 17:02 ` shubham verma
  2020-09-25 18:53   ` Eric Sunshine
  2020-09-25 17:02 ` [PATCH 07/11] t7001: use ': >' rather than 'touch' shubham verma
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 27+ messages in thread
From: shubham verma @ 2020-09-25 17:02 UTC (permalink / raw)
  To: git; +Cc: Shubham Verma

From: Shubham Verma <shubhunic@gmail.com>

Let's avoid the use of `cd` outside subshells by encapsulating them
inside subshells or by using `git -C <dir> ...`.

Signed-off-by: shubham verma <shubhunic@gmail.com>
---
 t/t7001-mv.sh | 45 +++++++++++----------------------------------
 1 file changed, 11 insertions(+), 34 deletions(-)

diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 7581e4b407..3a3ace6d73 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -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
 '
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 07/11] t7001: use ': >' rather than 'touch'
  2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
                   ` (5 preceding siblings ...)
  2020-09-25 17:02 ` [PATCH 06/11] t7001: change (cd <path> && git foo) to (git -C <path> foo) shubham verma
@ 2020-09-25 17:02 ` shubham verma
  2020-09-25 18:57   ` Eric Sunshine
  2020-09-25 17:02 ` [PATCH 08/11] t7001: put each command on a separate line shubham verma
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 27+ messages in thread
From: shubham verma @ 2020-09-25 17:02 UTC (permalink / raw)
  To: git; +Cc: Shubham Verma

From: Shubham Verma <shubhunic@gmail.com>

Use `>` rather than `touch` to create an empty file when the
timestamp isn't relevant to the test.

Signed-off-by: shubham verma <shubhunic@gmail.com>
---
 t/t7001-mv.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 3a3ace6d73..728a937eeb 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -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" &&
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 08/11] t7001: put each command on a separate line
  2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
                   ` (6 preceding siblings ...)
  2020-09-25 17:02 ` [PATCH 07/11] t7001: use ': >' rather than 'touch' shubham verma
@ 2020-09-25 17:02 ` shubham verma
  2020-09-25 19:01   ` Eric Sunshine
  2020-09-25 17:02 ` [PATCH 09/11] t7001: use here-docs instead of echo shubham verma
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 27+ messages in thread
From: shubham verma @ 2020-09-25 17:02 UTC (permalink / raw)
  To: git; +Cc: Shubham Verma

From: Shubham Verma <shubhunic@gmail.com>

Multiple commands on one line  should be split across multiple lines.

Signed-off-by: shubham verma <shubhunic@gmail.com>
---
 t/t7001-mv.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 728a937eeb..94c5b10f8a 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -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 "."' '
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 09/11] t7001: use here-docs instead of echo
  2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
                   ` (7 preceding siblings ...)
  2020-09-25 17:02 ` [PATCH 08/11] t7001: put each command on a separate line shubham verma
@ 2020-09-25 17:02 ` shubham verma
  2020-09-25 20:23   ` Junio C Hamano
  2020-09-25 17:02 ` [PATCH 10/11] t7001: use `test` rather than `[` shubham verma
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 27+ messages in thread
From: shubham verma @ 2020-09-25 17:02 UTC (permalink / raw)
  To: git; +Cc: Shubham Verma

From: Shubham Verma <shubhunic@gmail.com>

Change from old style to current style by taking advantage of
here-docs instead of echo commands.

Signed-off-by: shubham verma <shubhunic@gmail.com>
---
 t/t7001-mv.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 94c5b10f8a..30714a8200 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -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
 '
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 10/11] t7001: use `test` rather than `[`
  2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
                   ` (8 preceding siblings ...)
  2020-09-25 17:02 ` [PATCH 09/11] t7001: use here-docs instead of echo shubham verma
@ 2020-09-25 17:02 ` shubham verma
  2020-09-25 17:02 ` [PATCH 11/11] t7001: move cleanup code from outside the tests into them shubham verma
  2020-09-25 17:33 ` [PATCH 00/11] Modernizing the t7001 test script Eric Sunshine
  11 siblings, 0 replies; 27+ messages in thread
From: shubham verma @ 2020-09-25 17:02 UTC (permalink / raw)
  To: git; +Cc: Shubham Verma

From: Shubham Verma <shubhunic@gmail.com>

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.

Signed-off-by: shubham verma <shubhunic@gmail.com>
---
 t/t7001-mv.sh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 30714a8200..7bb4a7b759 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -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
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 11/11] t7001: move cleanup code from outside the tests into them
  2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
                   ` (9 preceding siblings ...)
  2020-09-25 17:02 ` [PATCH 10/11] t7001: use `test` rather than `[` shubham verma
@ 2020-09-25 17:02 ` shubham verma
  2020-09-25 19:36   ` Eric Sunshine
  2020-09-25 20:54   ` Junio C Hamano
  2020-09-25 17:33 ` [PATCH 00/11] Modernizing the t7001 test script Eric Sunshine
  11 siblings, 2 replies; 27+ messages in thread
From: shubham verma @ 2020-09-25 17:02 UTC (permalink / raw)
  To: git; +Cc: Shubham Verma

From: Shubham Verma <shubhunic@gmail.com>

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 <shubhunic@gmail.com>
---
 t/t7001-mv.sh | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 7bb4a7b759..b4d04ceaf8 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -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 &&
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH 00/11] Modernizing the t7001 test script
  2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
                   ` (10 preceding siblings ...)
  2020-09-25 17:02 ` [PATCH 11/11] t7001: move cleanup code from outside the tests into them shubham verma
@ 2020-09-25 17:33 ` Eric Sunshine
  2020-10-01  5:42   ` Shubham Verma
  11 siblings, 1 reply; 27+ messages in thread
From: Eric Sunshine @ 2020-09-25 17:33 UTC (permalink / raw)
  To: shubham verma; +Cc: Git List

On Fri, Sep 25, 2020 at 1:03 PM shubham verma <shubhunic@gmail.com> wrote:
> 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/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 01/11] t7001: convert tests from the old style to the current style
  2020-09-25 17:02 ` [PATCH 01/11] t7001: convert tests from the old style to the current style shubham verma
@ 2020-09-25 17:40   ` Eric Sunshine
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Sunshine @ 2020-09-25 17:40 UTC (permalink / raw)
  To: shubham verma; +Cc: Git List

On Fri, Sep 25, 2020 at 1:03 PM shubham verma <shubhunic@gmail.com> wrote:
> 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
        '

> Signed-off-by: shubham verma <shubhunic@gmail.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 02/11] t7001: use TAB instead of spaces
  2020-09-25 17:02 ` [PATCH 02/11] t7001: use TAB instead of spaces shubham verma
@ 2020-09-25 17:44   ` Eric Sunshine
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Sunshine @ 2020-09-25 17:44 UTC (permalink / raw)
  To: shubham verma; +Cc: Git List

On Fri, Sep 25, 2020 at 1:03 PM shubham verma <shubhunic@gmail.com> wrote:
> t7001: use TAB instead of spaces

Nit: "use" is a bit nebulous; I'd probably say:

    t7001: indent with TABs instead of spaces

> 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.

> Signed-off-by: shubham verma <shubhunic@gmail.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 03/11] t7001: remove unnecessary blank lines
  2020-09-25 17:02 ` [PATCH 03/11] t7001: remove unnecessary blank lines shubham verma
@ 2020-09-25 17:50   ` Eric Sunshine
  2020-09-25 20:19     ` Junio C Hamano
  0 siblings, 1 reply; 27+ messages in thread
From: Eric Sunshine @ 2020-09-25 17:50 UTC (permalink / raw)
  To: shubham verma; +Cc: Git List

On Fri, Sep 25, 2020 at 1:03 PM shubham verma <shubhunic@gmail.com> wrote:
> 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)...

> Signed-off-by: shubham verma <shubhunic@gmail.com>
> ---
> diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
> @@ -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].

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 04/11] t7001: change the style for cd according to subshell
  2020-09-25 17:02 ` [PATCH 04/11] t7001: change the style for cd according to subshell shubham verma
@ 2020-09-25 18:12   ` Eric Sunshine
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Sunshine @ 2020-09-25 18:12 UTC (permalink / raw)
  To: shubham verma; +Cc: Git List

On Fri, Sep 25, 2020 at 1:03 PM shubham verma <shubhunic@gmail.com> wrote:
> 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.

> Signed-off-by: shubham verma <shubhunic@gmail.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 06/11] t7001: change (cd <path> && git foo) to (git -C <path> foo)
  2020-09-25 17:02 ` [PATCH 06/11] t7001: change (cd <path> && git foo) to (git -C <path> foo) shubham verma
@ 2020-09-25 18:53   ` Eric Sunshine
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Sunshine @ 2020-09-25 18:53 UTC (permalink / raw)
  To: shubham verma; +Cc: Git List

On Fri, Sep 25, 2020 at 1:03 PM shubham verma <shubhunic@gmail.com> wrote:
> 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

> Let's avoid the use of `cd` outside subshells by encapsulating them
> inside subshells or by using `git -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`.

> Signed-off-by: shubham verma <shubhunic@gmail.com>
> ---
> diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
> @@ -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.

> @@ -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`.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 07/11] t7001: use ': >' rather than 'touch'
  2020-09-25 17:02 ` [PATCH 07/11] t7001: use ': >' rather than 'touch' shubham verma
@ 2020-09-25 18:57   ` Eric Sunshine
  2020-09-25 20:21     ` Junio C Hamano
  0 siblings, 1 reply; 27+ messages in thread
From: Eric Sunshine @ 2020-09-25 18:57 UTC (permalink / raw)
  To: shubham verma; +Cc: Git List

On Fri, Sep 25, 2020 at 1:03 PM shubham verma <shubhunic@gmail.com> wrote:
> t7001: use ': >' rather than 'touch'
>
> Use `>` rather than `touch` to 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...

> Signed-off-by: shubham verma <shubhunic@gmail.com>
> ---
> diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
> @@ -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.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 08/11] t7001: put each command on a separate line
  2020-09-25 17:02 ` [PATCH 08/11] t7001: put each command on a separate line shubham verma
@ 2020-09-25 19:01   ` Eric Sunshine
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Sunshine @ 2020-09-25 19:01 UTC (permalink / raw)
  To: shubham verma; +Cc: Git List

On Fri, Sep 25, 2020 at 1:03 PM shubham verma <shubhunic@gmail.com> wrote:
> 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.

> Signed-off-by: shubham verma <shubhunic@gmail.com>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 11/11] t7001: move cleanup code from outside the tests into them
  2020-09-25 17:02 ` [PATCH 11/11] t7001: move cleanup code from outside the tests into them shubham verma
@ 2020-09-25 19:36   ` Eric Sunshine
  2020-09-25 20:54   ` Junio C Hamano
  1 sibling, 0 replies; 27+ messages in thread
From: Eric Sunshine @ 2020-09-25 19:36 UTC (permalink / raw)
  To: shubham verma; +Cc: Git List

On Fri, Sep 25, 2020 at 1:03 PM shubham verma <shubhunic@gmail.com> wrote:
> 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 <shubhunic@gmail.com>
> ---
> diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
> @@ -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.

> @@ -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.

> @@ -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
>  '

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.

> -# 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`).

>  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 &&

Cleaning these paths here makes sense since they are created and only
used by this test.

> @@ -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? &&

> @@ -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.

> @@ -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.

>  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 &&

This makes sense, but...

> @@ -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.

> -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.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 03/11] t7001: remove unnecessary blank lines
  2020-09-25 17:50   ` Eric Sunshine
@ 2020-09-25 20:19     ` Junio C Hamano
  0 siblings, 0 replies; 27+ messages in thread
From: Junio C Hamano @ 2020-09-25 20:19 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: shubham verma, Git List

Eric Sunshine <sunshine@sunshineco.com> writes:

> 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].

I agree that adding that to 01/11 might be too noisy, but 04/11 may
be a good match.

Thanks.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 07/11] t7001: use ': >' rather than 'touch'
  2020-09-25 18:57   ` Eric Sunshine
@ 2020-09-25 20:21     ` Junio C Hamano
  0 siblings, 0 replies; 27+ messages in thread
From: Junio C Hamano @ 2020-09-25 20:21 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: shubham verma, Git List

Eric Sunshine <sunshine@sunshineco.com> writes:

> 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.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 09/11] t7001: use here-docs instead of echo
  2020-09-25 17:02 ` [PATCH 09/11] t7001: use here-docs instead of echo shubham verma
@ 2020-09-25 20:23   ` Junio C Hamano
  0 siblings, 0 replies; 27+ messages in thread
From: Junio C Hamano @ 2020-09-25 20:23 UTC (permalink / raw)
  To: shubham verma; +Cc: git

shubham verma <shubhunic@gmail.com> writes:

> From: Shubham Verma <shubhunic@gmail.com>
>
> Change from old style to current style by taking advantage of
> here-docs instead of echo commands.
>
> Signed-off-by: shubham verma <shubhunic@gmail.com>
> ---
>  t/t7001-mv.sh | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
> index 94c5b10f8a..30714a8200 100755
> --- a/t/t7001-mv.sh
> +++ b/t/t7001-mv.sh
> @@ -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.


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 11/11] t7001: move cleanup code from outside the tests into them
  2020-09-25 17:02 ` [PATCH 11/11] t7001: move cleanup code from outside the tests into them shubham verma
  2020-09-25 19:36   ` Eric Sunshine
@ 2020-09-25 20:54   ` Junio C Hamano
  1 sibling, 0 replies; 27+ messages in thread
From: Junio C Hamano @ 2020-09-25 20:54 UTC (permalink / raw)
  To: shubham verma; +Cc: git

shubham verma <shubhunic@gmail.com> writes:

> From: Shubham Verma <shubhunic@gmail.com>
>
> 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 <shubhunic@gmail.com>
> ---
>  t/t7001-mv.sh | 25 +++++++++++--------------
>  1 file changed, 11 insertions(+), 14 deletions(-)
>
> diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
> index 7bb4a7b759..b4d04ceaf8 100755
> --- a/t/t7001-mv.sh
> +++ b/t/t7001-mv.sh
> @@ -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).

> @@ -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' '
>  
>  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 &&

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.

> -# 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.

> -rm -fr papers partA path?
> -
>  test_expect_success "Sergey Vlasov's test case" '

Likewise.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 00/11] Modernizing the t7001 test script
  2020-09-25 17:33 ` [PATCH 00/11] Modernizing the t7001 test script Eric Sunshine
@ 2020-10-01  5:42   ` Shubham Verma
  2020-12-22 19:22     ` Junio C Hamano
  0 siblings, 1 reply; 27+ messages in thread
From: Shubham Verma @ 2020-10-01  5:42 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List

On Fri, Sep 25, 2020 at 11:03 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
>
> On Fri, Sep 25, 2020 at 1:03 PM shubham verma <shubhunic@gmail.com> wrote:
> > 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/

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!

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 00/11] Modernizing the t7001 test script
  2020-10-01  5:42   ` Shubham Verma
@ 2020-12-22 19:22     ` Junio C Hamano
  0 siblings, 0 replies; 27+ messages in thread
From: Junio C Hamano @ 2020-12-22 19:22 UTC (permalink / raw)
  To: Shubham Verma; +Cc: Eric Sunshine, Git List

Shubham Verma <shubhunic@gmail.com> writes:

> On Fri, Sep 25, 2020 at 11:03 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
>>
>> On Fri, Sep 25, 2020 at 1:03 PM shubham verma <shubhunic@gmail.com> wrote:
>> > 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/
>
> 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.

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2020-12-22 19:23 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-25 17:02 [PATCH 00/11] Modernizing the t7001 test script shubham verma
2020-09-25 17:02 ` [PATCH 01/11] t7001: convert tests from the old style to the current style shubham verma
2020-09-25 17:40   ` Eric Sunshine
2020-09-25 17:02 ` [PATCH 02/11] t7001: use TAB instead of spaces shubham verma
2020-09-25 17:44   ` Eric Sunshine
2020-09-25 17:02 ` [PATCH 03/11] t7001: remove unnecessary blank lines shubham verma
2020-09-25 17:50   ` Eric Sunshine
2020-09-25 20:19     ` Junio C Hamano
2020-09-25 17:02 ` [PATCH 04/11] t7001: change the style for cd according to subshell shubham verma
2020-09-25 18:12   ` Eric Sunshine
2020-09-25 17:02 ` [PATCH 05/11] t7001: remove whitespace after redirect operators shubham verma
2020-09-25 17:02 ` [PATCH 06/11] t7001: change (cd <path> && git foo) to (git -C <path> foo) shubham verma
2020-09-25 18:53   ` Eric Sunshine
2020-09-25 17:02 ` [PATCH 07/11] t7001: use ': >' rather than 'touch' shubham verma
2020-09-25 18:57   ` Eric Sunshine
2020-09-25 20:21     ` Junio C Hamano
2020-09-25 17:02 ` [PATCH 08/11] t7001: put each command on a separate line shubham verma
2020-09-25 19:01   ` Eric Sunshine
2020-09-25 17:02 ` [PATCH 09/11] t7001: use here-docs instead of echo shubham verma
2020-09-25 20:23   ` Junio C Hamano
2020-09-25 17:02 ` [PATCH 10/11] t7001: use `test` rather than `[` shubham verma
2020-09-25 17:02 ` [PATCH 11/11] t7001: move cleanup code from outside the tests into them shubham verma
2020-09-25 19:36   ` Eric Sunshine
2020-09-25 20:54   ` Junio C Hamano
2020-09-25 17:33 ` [PATCH 00/11] Modernizing the t7001 test script Eric Sunshine
2020-10-01  5:42   ` Shubham Verma
2020-12-22 19:22     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).