git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/12] t5520: various test cleanup
@ 2019-10-17 23:16 Denton Liu
  2019-10-17 23:16 ` [PATCH 01/12] t5520: improve test style Denton Liu
                   ` (12 more replies)
  0 siblings, 13 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:16 UTC (permalink / raw)
  To: Git Mailing List

Like earlier patchsets, I want to implement a feature that involves
modifications to the test suite. Since that feature will probably take a
while to polish up, however, let's clean up the test suite in a separate
patchset first so it's not blocked by the feature work.

Denton Liu (12):
  t5520: improve test style
  t5520: use sq for test case names
  t5520: let sed open its own input
  t5520: replace test -f with test_path_is_file
  t5520: remove spaces after redirect operator
  t5520: use test_line_count where possible
  t5520: replace test -{n,z} with test-lib functions
  t5520: use test_cmp_rev where possible
  t5520: test single-line files by git with test_cmp
  t5520: don't put git in upstream of pipe
  t5520: replace subshell cat comparison with test_cmp
  t5520: replace `! git` with `test_must_fail git`

 t/t5520-pull.sh | 351 +++++++++++++++++++++++++++++-------------------
 1 file changed, 213 insertions(+), 138 deletions(-)

-- 
2.23.0.897.g0a19638b1e


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

* [PATCH 01/12] t5520: improve test style
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
@ 2019-10-17 23:16 ` Denton Liu
  2019-10-17 23:16 ` [PATCH 02/12] t5520: use sq for test case names Denton Liu
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:16 UTC (permalink / raw)
  To: Git Mailing List

Improve the test style by removing leading and trailing empty lines
within test cases. Also, reformat multi-line subshells to conform to the
existing style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 88 +++++++++++++++++++++++++------------------------
 1 file changed, 45 insertions(+), 43 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index cf4cc32fd0..51d6ce8aec 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -538,7 +538,6 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 '
 
 test_expect_success '--rebase with rebased upstream' '
-
 	git remote add -f me . &&
 	git checkout copy &&
 	git tag copy-orig &&
@@ -552,7 +551,6 @@ test_expect_success '--rebase with rebased upstream' '
 	git pull --rebase me copy &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = "$(cat file2)"
-
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
@@ -564,14 +562,12 @@ test_expect_success '--rebase -f with rebased upstream' '
 '
 
 test_expect_success '--rebase with rebased default upstream' '
-
 	git update-ref refs/remotes/me/copy copy-orig &&
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = "$(cat file2)"
-
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -588,7 +584,6 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 '
 
 test_expect_success 'pull --rebase dies early with dirty working directory' '
-
 	git checkout to-rebase &&
 	git update-ref refs/remotes/me/copy copy^ &&
 	COPY="$(git rev-parse --verify me/copy)" &&
@@ -603,16 +598,16 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	git checkout HEAD -- file &&
 	git pull &&
 	test "$COPY" != "$(git rev-parse --verify me/copy)"
-
 '
 
 test_expect_success 'pull --rebase works on branch yet to be born' '
 	git rev-parse master >expect &&
 	mkdir empty_repo &&
-	(cd empty_repo &&
-	 git init &&
-	 git pull --rebase .. master &&
-	 git rev-parse HEAD >../actual
+	(
+		cd empty_repo &&
+		git init &&
+		git pull --rebase .. master &&
+		git rev-parse HEAD >../actual
 	) &&
 	test_cmp expect actual
 '
@@ -646,58 +641,65 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 
 test_expect_success 'setup for detecting upstreamed changes' '
 	mkdir src &&
-	(cd src &&
-	 git init &&
-	 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
-	 git add stuff &&
-	 git commit -m "Initial revision"
+	(
+		cd src &&
+		git init &&
+		printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
+		git add stuff &&
+		git commit -m "Initial revision"
 	) &&
 	git clone src dst &&
-	(cd src &&
-	 modify s/5/43/ stuff &&
-	 git commit -a -m "5->43" &&
-	 modify s/6/42/ stuff &&
-	 git commit -a -m "Make it bigger"
+	(
+		cd src &&
+		modify s/5/43/ stuff &&
+		git commit -a -m "5->43" &&
+		modify s/6/42/ stuff &&
+		git commit -a -m "Make it bigger"
 	) &&
-	(cd dst &&
-	 modify s/5/43/ stuff &&
-	 git commit -a -m "Independent discovery of 5->43"
+	(
+		cd dst &&
+		modify s/5/43/ stuff &&
+		git commit -a -m "Independent discovery of 5->43"
 	)
 '
 
 test_expect_success 'git pull --rebase detects upstreamed changes' '
-	(cd dst &&
-	 git pull --rebase &&
-	 test -z "$(git ls-files -u)"
+	(
+		cd dst &&
+		git pull --rebase &&
+		test -z "$(git ls-files -u)"
 	)
 '
 
 test_expect_success 'setup for avoiding reapplying old patches' '
-	(cd dst &&
-	 test_might_fail git rebase --abort &&
-	 git reset --hard origin/master
+	(
+		cd dst &&
+		test_might_fail git rebase --abort &&
+		git reset --hard origin/master
 	) &&
 	git clone --bare src src-replace.git &&
 	rm -rf src &&
 	mv src-replace.git src &&
-	(cd dst &&
-	 modify s/2/22/ stuff &&
-	 git commit -a -m "Change 2" &&
-	 modify s/3/33/ stuff &&
-	 git commit -a -m "Change 3" &&
-	 modify s/4/44/ stuff &&
-	 git commit -a -m "Change 4" &&
-	 git push &&
-
-	 modify s/44/55/ stuff &&
-	 git commit --amend -a -m "Modified Change 4"
+	(
+		cd dst &&
+		modify s/2/22/ stuff &&
+		git commit -a -m "Change 2" &&
+		modify s/3/33/ stuff &&
+		git commit -a -m "Change 3" &&
+		modify s/4/44/ stuff &&
+		git commit -a -m "Change 4" &&
+		git push &&
+
+		modify s/44/55/ stuff &&
+		git commit --amend -a -m "Modified Change 4"
 	)
 '
 
 test_expect_success 'git pull --rebase does not reapply old patches' '
-	(cd dst &&
-	 test_must_fail git pull --rebase &&
-	 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+	(
+		cd dst &&
+		test_must_fail git pull --rebase &&
+		test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
 	)
 '
 
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH 02/12] t5520: use sq for test case names
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
  2019-10-17 23:16 ` [PATCH 01/12] t5520: improve test style Denton Liu
@ 2019-10-17 23:16 ` Denton Liu
  2019-10-17 23:17 ` [PATCH 03/12] t5520: let sed open its own input Denton Liu
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:16 UTC (permalink / raw)
  To: Git Mailing List

The usual convention is for test case names to be written between
single-quotes. Change all double-quoted test case names to single-quotes
except for two test case names that use variables within.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 51d6ce8aec..a3de2e19b6 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -408,7 +408,7 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test new = "$(git show HEAD:file2)"
 '
 
-test_expect_success "pull --rebase warns on --verify-signatures" '
+test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
 	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
@@ -416,7 +416,7 @@ test_expect_success "pull --rebase warns on --verify-signatures" '
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
 
-test_expect_success "pull --rebase does not warn on --no-verify-signatures" '
+test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
 	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH 03/12] t5520: let sed open its own input
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
  2019-10-17 23:16 ` [PATCH 01/12] t5520: improve test style Denton Liu
  2019-10-17 23:16 ` [PATCH 02/12] t5520: use sq for test case names Denton Liu
@ 2019-10-17 23:17 ` Denton Liu
  2019-10-17 23:17 ` [PATCH 04/12] t5520: replace test -f with test_path_is_file Denton Liu
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:17 UTC (permalink / raw)
  To: Git Mailing List

We were using a redirection operator to feed input into sed. However,
since sed is capable of opening its own files, make sed open its own
files instead of redirecting input into it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a3de2e19b6..55560ce3cd 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -5,7 +5,7 @@ test_description='pulling into void'
 . ./test-lib.sh
 
 modify () {
-	sed -e "$1" <"$2" >"$2.x" &&
+	sed -e "$1" "$2" >"$2.x" &&
 	mv "$2.x" "$2"
 }
 
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH 04/12] t5520: replace test -f with test_path_is_file
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
                   ` (2 preceding siblings ...)
  2019-10-17 23:17 ` [PATCH 03/12] t5520: let sed open its own input Denton Liu
@ 2019-10-17 23:17 ` Denton Liu
  2019-10-17 23:26   ` Eric Sunshine
  2019-10-17 23:35   ` [PATCH 4.5/12] t5520: replace test -f with test-lib functions Denton Liu
  2019-10-17 23:17 ` [PATCH 05/12] t5520: remove spaces after redirect operator Denton Liu
                   ` (8 subsequent siblings)
  12 siblings, 2 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:17 UTC (permalink / raw)
  To: Git Mailing List

Although `test -f` has the same functionality as test_path_is_file(), in
the case where test_path_is_file() fails, we get much better debugging
information. Replace `test -f` with test_path_is_file so that future
developers will have a better experience debugging these test cases.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 55560ce3cd..5ab5ec508a 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -39,8 +39,8 @@ test_expect_success 'pulling into void' '
 		cd cloned &&
 		git pull ..
 	) &&
-	test -f file &&
-	test -f cloned/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned/file &&
 	test_cmp file cloned/file
 '
 
@@ -50,8 +50,8 @@ test_expect_success 'pulling into void using master:master' '
 		cd cloned-uho &&
 		git pull .. master:master
 	) &&
-	test -f file &&
-	test -f cloned-uho/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned-uho/file &&
 	test_cmp file cloned-uho/file
 '
 
@@ -99,7 +99,7 @@ test_expect_success 'pulling into void must not create an octopus' '
 	(
 		cd cloned-octopus &&
 		test_must_fail git pull .. master master &&
-		! test -f file
+		test_must_fail test_path_is_file file
 	)
 '
 
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH 05/12] t5520: remove spaces after redirect operator
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
                   ` (3 preceding siblings ...)
  2019-10-17 23:17 ` [PATCH 04/12] t5520: replace test -f with test_path_is_file Denton Liu
@ 2019-10-17 23:17 ` Denton Liu
  2019-10-17 23:17 ` [PATCH 06/12] t5520: use test_line_count where possible Denton Liu
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:17 UTC (permalink / raw)
  To: Git Mailing List

The style for tests in Git is to have the redirect operator attached to
the filename with no spaces. Fix test cases where this is not the case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 5ab5ec508a..68b8822db2 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -243,10 +243,10 @@ test_expect_success 'fast-forward fails with conflicting work tree' '
 
 test_expect_success '--rebase' '
 	git branch to-rebase &&
-	echo modified again > file &&
+	echo modified again >file &&
 	git commit -m file file &&
 	git checkout to-rebase &&
-	echo new > file2 &&
+	echo new >file2 &&
 	git add file2 &&
 	git commit -m "new file" &&
 	git tag before-rebase &&
@@ -542,10 +542,10 @@ test_expect_success '--rebase with rebased upstream' '
 	git checkout copy &&
 	git tag copy-orig &&
 	git reset --hard HEAD^ &&
-	echo conflicting modification > file &&
+	echo conflicting modification >file &&
 	git commit -m conflict file &&
 	git checkout to-rebase &&
-	echo file > file2 &&
+	echo file >file2 &&
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
@@ -591,7 +591,7 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	test_config branch.to-rebase.remote me &&
 	test_config branch.to-rebase.merge refs/heads/copy &&
 	test_config branch.to-rebase.rebase true &&
-	echo dirty >> file &&
+	echo dirty >>file &&
 	git add file &&
 	test_must_fail git pull &&
 	test "$COPY" = "$(git rev-parse --verify me/copy)" &&
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH 06/12] t5520: use test_line_count where possible
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
                   ` (4 preceding siblings ...)
  2019-10-17 23:17 ` [PATCH 05/12] t5520: remove spaces after redirect operator Denton Liu
@ 2019-10-17 23:17 ` Denton Liu
  2019-10-17 23:17 ` [PATCH 07/12] t5520: replace test -{n,z} with test-lib functions Denton Liu
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:17 UTC (permalink / raw)
  To: Git Mailing List

Instead of rolling our own functionality to test the number of lines a
command outputs, use test_line_count() which provides better debugging
information in the case of a failure.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 68b8822db2..9452779f40 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -699,7 +699,8 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 	(
 		cd dst &&
 		test_must_fail git pull --rebase &&
-		test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+		find .git/rebase-apply -name "000*" >patches &&
+		test_line_count = 1 patches
 	)
 '
 
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH 07/12] t5520: replace test -{n,z} with test-lib functions
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
                   ` (5 preceding siblings ...)
  2019-10-17 23:17 ` [PATCH 06/12] t5520: use test_line_count where possible Denton Liu
@ 2019-10-17 23:17 ` Denton Liu
  2019-10-17 23:31   ` Eric Sunshine
  2019-10-17 23:17 ` [PATCH 08/12] t5520: use test_cmp_rev where possible Denton Liu
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:17 UTC (permalink / raw)
  To: Git Mailing List

Instead of using `test -n` or `test -z`, replace them respectively with
invocations of test_file_not_empty() and test_must_be_empty().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 9452779f40..c7797b13e6 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -206,15 +206,18 @@ test_expect_success 'fail if the index has unresolved entries' '
 	test_when_finished "git checkout -f copy && git branch -D third" &&
 	test "$(cat file)" = file &&
 	test_commit modified2 file &&
-	test -z "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_must_be_empty unmerged &&
 	test_must_fail git pull . second &&
-	test -n "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_file_not_empty unmerged &&
 	cp file expected &&
 	test_must_fail git pull . second 2>err &&
 	test_i18ngrep "Pulling is not possible because you have unmerged files." err &&
 	test_cmp expected file &&
 	git add file &&
-	test -z "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_must_be_empty unmerged &&
 	test_must_fail git pull . second 2>err &&
 	test_i18ngrep "You have not concluded your merge" err &&
 	test_cmp expected file
@@ -667,7 +670,8 @@ test_expect_success 'git pull --rebase detects upstreamed changes' '
 	(
 		cd dst &&
 		git pull --rebase &&
-		test -z "$(git ls-files -u)"
+		git ls-files -u >untracked &&
+		test_must_be_empty untracked
 	)
 '
 
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH 08/12] t5520: use test_cmp_rev where possible
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
                   ` (6 preceding siblings ...)
  2019-10-17 23:17 ` [PATCH 07/12] t5520: replace test -{n,z} with test-lib functions Denton Liu
@ 2019-10-17 23:17 ` Denton Liu
  2019-10-17 23:41   ` Eric Sunshine
  2019-10-17 23:17 ` [PATCH 09/12] t5520: test single-line files by git with test_cmp Denton Liu
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:17 UTC (permalink / raw)
  To: Git Mailing List

In case an invocation of `git rev-list` fails within the subshell, the
failure will be masked. Remove the subshell and use test_cmp_rev() so
that failures can be discovered.

This change was done with the following sed expressions:

	s/test "$(git rev-parse.* \([^)]*\))" = "$(git rev-parse \([^)]*\))"/test_cmp_rev \1 \2/
	s/test \([^ ]*\) = "$(git rev-parse.* \([^)]*\))"/test_cmp_rev \1 \2/
	s/test "$(git rev-parse.* \([^)]*\))" != "$(git rev-parse.* \([^)]*\))"/test_must_fail test_cmp_rev \1 \2/
	s/test \([^ ]*\) != "$(git rev-parse.* \([^)]*\))"/test_must_fail test_cmp_rev \1 \2/

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 50 ++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index c7797b13e6..f11fadc075 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -230,7 +230,7 @@ test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
 	test "$(cat file)" = modified &&
-	test "$(git rev-parse third)" = "$(git rev-parse second)"
+	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
@@ -241,7 +241,7 @@ test_expect_success 'fast-forward fails with conflicting work tree' '
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
 	test "$(cat file)" = conflict &&
-	test "$(git rev-parse third)" = "$(git rev-parse second)"
+	test_cmp_rev third second
 '
 
 test_expect_success '--rebase' '
@@ -254,7 +254,7 @@ test_expect_success '--rebase' '
 	git commit -m "new file" &&
 	git tag before-rebase &&
 	git pull --rebase . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -266,7 +266,7 @@ test_expect_success '--rebase fast forward' '
 
 	git checkout to-rebase &&
 	git pull --rebase . ff &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse ff)" &&
+	test_cmp_rev HEAD ff &&
 
 	# The above only validates the result.  Did we actually bypass rebase?
 	git reflog -1 >reflog.actual &&
@@ -290,7 +290,7 @@ test_expect_success '--rebase --autostash fast forward' '
 	git checkout behind &&
 	echo dirty >file &&
 	git pull --rebase --autostash . to-rebase-ff &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse to-rebase-ff)"
+	test_cmp_rev HEAD to-rebase-ff
 '
 
 test_expect_success '--rebase with conflicts shows advice' '
@@ -328,7 +328,7 @@ test_expect_success 'failed --rebase shows advice' '
 test_expect_success '--rebase fails with multiple branches' '
 	git reset --hard before-rebase &&
 	test_must_fail git pull --rebase . copy master 2>err &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse before-rebase)" &&
+	test_cmp_rev HEAD before-rebase &&
 	test_i18ngrep "Cannot rebase onto multiple branches" err &&
 	test modified = "$(git show HEAD:file)"
 '
@@ -380,7 +380,7 @@ test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -398,7 +398,7 @@ test_expect_success 'branch.to-rebase.rebase' '
 	git reset --hard before-rebase &&
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -407,14 +407,14 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_config pull.rebase true &&
 	test_config branch.to-rebase.rebase false &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
+	test_must_fail test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)" &&
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
@@ -422,7 +422,7 @@ test_expect_success 'pull --rebase warns on --verify-signatures' '
 test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)" &&
 	test_i18ngrep ! "verify-signatures" err
 '
@@ -443,8 +443,8 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase false &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^1 before-preserve-rebase &&
+	test_cmp_rev HEAD^2 copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -452,7 +452,7 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -460,7 +460,7 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase 1 &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -469,8 +469,8 @@ test_expect_success REBASE_P \
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
+	test_cmp_rev HEAD^^ copy &&
+	test_cmp_rev HEAD^2 keep-merge
 '
 
 test_expect_success 'pull.rebase=interactive' '
@@ -505,8 +505,8 @@ test_expect_success '--rebase=false create a new merge commit' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull --rebase=false . copy &&
-	test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^1 before-preserve-rebase &&
+	test_cmp_rev HEAD^2 copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -514,7 +514,7 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull --rebase=true . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -523,8 +523,8 @@ test_expect_success REBASE_P \
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull --rebase=preserve . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
+	test_cmp_rev HEAD^^ copy &&
+	test_cmp_rev HEAD^2 keep-merge
 '
 
 test_expect_success '--rebase=invalid fails' '
@@ -536,7 +536,7 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull --rebase . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -597,10 +597,10 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	echo dirty >>file &&
 	git add file &&
 	test_must_fail git pull &&
-	test "$COPY" = "$(git rev-parse --verify me/copy)" &&
+	test_cmp_rev "$COPY" me/copy &&
 	git checkout HEAD -- file &&
 	git pull &&
-	test "$COPY" != "$(git rev-parse --verify me/copy)"
+	test_must_fail test_cmp_rev "$COPY" me/copy
 '
 
 test_expect_success 'pull --rebase works on branch yet to be born' '
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH 09/12] t5520: test single-line files by git with test_cmp
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
                   ` (7 preceding siblings ...)
  2019-10-17 23:17 ` [PATCH 08/12] t5520: use test_cmp_rev where possible Denton Liu
@ 2019-10-17 23:17 ` Denton Liu
  2019-10-17 23:49   ` Eric Sunshine
  2019-10-17 23:17 ` [PATCH 10/12] t5520: don't put git in upstream of pipe Denton Liu
                   ` (3 subsequent siblings)
  12 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:17 UTC (permalink / raw)
  To: Git Mailing List

In case an invocation of a Git command fails within the subshell, the
failure will be masked. Replace the subshell with a file-redirection and
a call to test_cmp.

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^ ]*\) = "$(\(git [^)]*\))"/\1echo \2 >expect \&\&\n\1\3 >actual \&\&\n\1test_cmp expect actual/
	s/\(\s*\)test "$(\(git [^)]*\))" = \([^ ]*\)/\1echo \3 >expect \&\&\n\1\2 >actual \&\&\n\1test_cmp expect actual/

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 64 ++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 16 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index f11fadc075..0eebab7d86 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -255,7 +255,9 @@ test_expect_success '--rebase' '
 	git tag before-rebase &&
 	git pull --rebase . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase fast forward' '
@@ -330,7 +332,9 @@ test_expect_success '--rebase fails with multiple branches' '
 	test_must_fail git pull --rebase . copy master 2>err &&
 	test_cmp_rev HEAD before-rebase &&
 	test_i18ngrep "Cannot rebase onto multiple branches" err &&
-	test modified = "$(git show HEAD:file)"
+	echo modified >expect &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
@@ -381,7 +385,9 @@ test_expect_success 'pull.rebase' '
 	test_config pull.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --autostash & pull.rebase=true' '
@@ -399,7 +405,9 @@ test_expect_success 'branch.to-rebase.rebase' '
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
@@ -408,14 +416,18 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_config branch.to-rebase.rebase false &&
 	git pull . copy &&
 	test_must_fail test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)" &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual &&
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
 
@@ -423,7 +435,9 @@ test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)" &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual &&
 	test_i18ngrep ! "verify-signatures" err
 '
 
@@ -445,7 +459,9 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	git pull . copy &&
 	test_cmp_rev HEAD^1 before-preserve-rebase &&
 	test_cmp_rev HEAD^2 copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull.rebase=true flattens keep-merge' '
@@ -453,7 +469,9 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
 	test_config pull.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
@@ -461,7 +479,9 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	test_config pull.rebase 1 &&
 	git pull . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success REBASE_P \
@@ -507,7 +527,9 @@ test_expect_success '--rebase=false create a new merge commit' '
 	git pull --rebase=false . copy &&
 	test_cmp_rev HEAD^1 before-preserve-rebase &&
 	test_cmp_rev HEAD^2 copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase=true rebases and flattens keep-merge' '
@@ -515,7 +537,9 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
 	test_config pull.rebase preserve &&
 	git pull --rebase=true . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success REBASE_P \
@@ -537,7 +561,9 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 	test_config pull.rebase preserve &&
 	git pull --rebase . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase with rebased upstream' '
@@ -622,10 +648,16 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
 		cd empty_repo2 &&
 		echo staged-file >staged-file &&
 		git add staged-file &&
-		test "$(git ls-files)" = staged-file &&
+		echo staged-file >expect &&
+		git ls-files >actual &&
+		test_cmp expect actual &&
 		test_must_fail git pull --rebase .. master 2>err &&
-		test "$(git ls-files)" = staged-file &&
-		test "$(git show :staged-file)" = staged-file &&
+		echo staged-file >expect &&
+		git ls-files >actual &&
+		test_cmp expect actual &&
+		echo staged-file >expect &&
+		git show :staged-file >actual &&
+		test_cmp expect actual &&
 		test_i18ngrep "unborn branch with changes added to the index" err
 	)
 '
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH 10/12] t5520: don't put git in upstream of pipe
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
                   ` (8 preceding siblings ...)
  2019-10-17 23:17 ` [PATCH 09/12] t5520: test single-line files by git with test_cmp Denton Liu
@ 2019-10-17 23:17 ` Denton Liu
  2019-10-17 23:17 ` [PATCH 11/12] t5520: replace subshell cat comparison with test_cmp Denton Liu
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:17 UTC (permalink / raw)
  To: Git Mailing List

Before, if the invocation of git failed, it would be masked by the pipe
since only the return code of the last element of a pipe is used.
Rewrite the test to put the Git command on its own line so its return
code is not masked.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 0eebab7d86..e611d414c8 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -668,7 +668,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 	(
 		cd corrupt &&
 		test_commit one &&
-		obj=$(git rev-parse --verify HEAD | sed "s#^..#&/#") &&
+		git rev-parse --verify HEAD >head &&
+		obj=$(sed "s#^..#&/#" head) &&
 		rm -f .git/objects/$obj &&
 		test_must_fail git pull --rebase
 	)
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH 11/12] t5520: replace subshell cat comparison with test_cmp
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
                   ` (9 preceding siblings ...)
  2019-10-17 23:17 ` [PATCH 10/12] t5520: don't put git in upstream of pipe Denton Liu
@ 2019-10-17 23:17 ` Denton Liu
  2019-10-17 23:17 ` [PATCH 12/12] t5520: replace `! git` with `test_must_fail git` Denton Liu
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
  12 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:17 UTC (permalink / raw)
  To: Git Mailing List

We currently have many instances of `test <line> = $(cat <file>)` and
`test $(cat <file>) = <line>`.  In the case where this fails, it will be
difficult for a developer to debug since the output will be masked.
Replace these instances with invocations of test_cmp().

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^=]*\)= "$(cat \([^)]*\))"/\1echo \2>expect \&\&\n\1test_cmp expect \3/
	s/\(\s*\)test "$(cat \([^)]*\))" = \([^&]*\)\( &&\)\?$/\1echo \3 >expect \&\&\n\1test_cmp expect \2\4/

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 105 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 70 insertions(+), 35 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index e611d414c8..c6425d20ab 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -15,8 +15,10 @@ test_pull_autostash () {
 	git add new_file &&
 	git pull "$@" . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test "$(cat new_file)" = dirty &&
-	test "$(cat file)" = "modified again"
+	echo dirty >expect &&
+	test_cmp expect new_file &&
+	echo "modified again" >expect &&
+	test_cmp expect file
 }
 
 test_pull_autostash_fail () {
@@ -110,9 +112,11 @@ test_expect_success 'test . as a remote' '
 	echo updated >file &&
 	git commit -a -m updated &&
 	git checkout copy &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull &&
-	test "$(cat file)" = updated &&
+	echo updated >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
@@ -125,9 +129,11 @@ test_expect_success 'the default remote . should not break explicit pull' '
 	git commit -a -m modified &&
 	git checkout copy &&
 	git reset --hard HEAD^ &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
@@ -137,10 +143,12 @@ test_expect_success 'the default remote . should not break explicit pull' '
 test_expect_success 'fail if wildcard spec does not match any refs' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 	test_i18ngrep "no candidates for merging" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no branches specified with non-default remote' '
@@ -148,11 +156,13 @@ test_expect_success 'fail if no branches specified with non-default remote' '
 	test_when_finished "git remote remove test_remote" &&
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_config branch.test.remote origin &&
 	test_must_fail git pull test_remote 2>err &&
 	test_i18ngrep "specify a branch on the command line" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if not on a branch' '
@@ -160,10 +170,12 @@ test_expect_success 'fail if not on a branch' '
 	test_when_finished "git remote remove origin" &&
 	git checkout HEAD^ &&
 	test_when_finished "git checkout -f copy" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "not currently on a branch" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no configuration for current branch' '
@@ -172,10 +184,12 @@ test_expect_success 'fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'pull --all: fail if no configuration for current branch' '
@@ -184,10 +198,12 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull --all 2>err &&
 	test_i18ngrep "There is no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if upstream branch does not exist' '
@@ -195,16 +211,19 @@ test_expect_success 'fail if upstream branch does not exist' '
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote . &&
 	test_config branch.test.merge refs/heads/nonexisting &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no such ref was fetched" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if the index has unresolved entries' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_commit modified2 file &&
 	git ls-files -u >unmerged &&
 	test_must_be_empty unmerged &&
@@ -226,21 +245,25 @@ test_expect_success 'fail if the index has unresolved entries' '
 test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	echo conflict >file &&
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
-	test "$(cat file)" = conflict &&
+	echo conflict >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
@@ -501,7 +524,8 @@ test_expect_success 'pull.rebase=interactive' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=interactive . copy &&
-	test "I was here" = "$(cat fake.out)"
+	echo "I was here" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull --rebase=i' '
@@ -512,7 +536,8 @@ test_expect_success 'pull --rebase=i' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=i . copy &&
-	test "I was here, too" = "$(cat fake.out)"
+	echo "I was here, too" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull.rebase=invalid fails' '
@@ -578,16 +603,20 @@ test_expect_success '--rebase with rebased upstream' '
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
 	test_when_finished "test_might_fail git rebase --abort" &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase -f me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase with rebased default upstream' '
@@ -595,8 +624,10 @@ test_expect_success '--rebase with rebased default upstream' '
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -607,8 +638,10 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 	git reset --hard to-rebase-orig &&
 	git fetch &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 
 '
 
@@ -744,8 +777,10 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 test_expect_success 'git pull --rebase against local branch' '
 	git checkout -b copy2 to-rebase-orig &&
 	git pull --rebase . to-rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_done
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH 12/12] t5520: replace `! git` with `test_must_fail git`
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
                   ` (10 preceding siblings ...)
  2019-10-17 23:17 ` [PATCH 11/12] t5520: replace subshell cat comparison with test_cmp Denton Liu
@ 2019-10-17 23:17 ` Denton Liu
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
  12 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:17 UTC (permalink / raw)
  To: Git Mailing List

Currently, if a Git command fails in an unexpected way, such as a
segfault, it will be masked and ignored. Replace the ! with
test_must_fail so that only expected failures pass.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index c6425d20ab..0c187b025b 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -543,7 +543,7 @@ test_expect_success 'pull --rebase=i' '
 test_expect_success 'pull.rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase invalid &&
-	! git pull . copy
+	test_must_fail git pull . copy
 '
 
 test_expect_success '--rebase=false create a new merge commit' '
@@ -578,7 +578,7 @@ test_expect_success REBASE_P \
 
 test_expect_success '--rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
-	! git pull --rebase=invalid . copy
+	test_must_fail git pull --rebase=invalid . copy
 '
 
 test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
-- 
2.23.0.897.g0a19638b1e


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

* Re: [PATCH 04/12] t5520: replace test -f with test_path_is_file
  2019-10-17 23:17 ` [PATCH 04/12] t5520: replace test -f with test_path_is_file Denton Liu
@ 2019-10-17 23:26   ` Eric Sunshine
  2019-10-17 23:35   ` [PATCH 4.5/12] t5520: replace test -f with test-lib functions Denton Liu
  1 sibling, 0 replies; 116+ messages in thread
From: Eric Sunshine @ 2019-10-17 23:26 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

On Thu, Oct 17, 2019 at 7:17 PM Denton Liu <liu.denton@gmail.com> wrote:
> Although `test -f` has the same functionality as test_path_is_file(), in
> the case where test_path_is_file() fails, we get much better debugging
> information. Replace `test -f` with test_path_is_file so that future
> developers will have a better experience debugging these test cases.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
> @@ -99,7 +99,7 @@ test_expect_success 'pulling into void must not create an octopus' '
>         (
>                 cd cloned-octopus &&
>                 test_must_fail git pull .. master master &&
> -               ! test -f file
> +               test_must_fail test_path_is_file file
>         )

According to t/README, this is not a valid use of test_must_fail(),
which is reserved for detecting failure of Git commands. Either use
'!' as the original code did, or perhaps use test_path_is_missing().

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

* Re: [PATCH 07/12] t5520: replace test -{n,z} with test-lib functions
  2019-10-17 23:17 ` [PATCH 07/12] t5520: replace test -{n,z} with test-lib functions Denton Liu
@ 2019-10-17 23:31   ` Eric Sunshine
  0 siblings, 0 replies; 116+ messages in thread
From: Eric Sunshine @ 2019-10-17 23:31 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

On Thu, Oct 17, 2019 at 7:17 PM Denton Liu <liu.denton@gmail.com> wrote:
> Instead of using `test -n` or `test -z`, replace them respectively with
> invocations of test_file_not_empty() and test_must_be_empty().
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
> @@ -206,15 +206,18 @@ test_expect_success 'fail if the index has unresolved entries' '
> -       test -z "$(git ls-files -u)" &&
> +       git ls-files -u >unmerged &&
> +       test_must_be_empty unmerged &&

A better justification for these change (and all others in this patch)
is that the original threw away the exit code of the "git ls-files -u"
invocation, whereas the new code takes the exit code into account. The
commit message perhaps instead ought to focus on that benefit.

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

* [PATCH 4.5/12] t5520: replace test -f with test-lib functions
  2019-10-17 23:17 ` [PATCH 04/12] t5520: replace test -f with test_path_is_file Denton Liu
  2019-10-17 23:26   ` Eric Sunshine
@ 2019-10-17 23:35   ` Denton Liu
  2019-10-18  0:11     ` Eric Sunshine
  1 sibling, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-10-17 23:35 UTC (permalink / raw)
  To: Git Mailing List

Although `test -f` has the same functionality as test_path_is_file(), in
the case where test_path_is_file() fails, we get much better debugging
information.

Replace `test -f` with test_path_is_file() so that future developers
will have a better experience debugging these test cases. Also, in the
case of `! test -f`, replace it with test_path_is_missing().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
I just realised that test_path_is_missing() is a much better replacement
than `test_must_fail test_path_is_file`. Please use this patch instead
of 04/12.

 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 55560ce3cd..004d5884cd 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -39,8 +39,8 @@ test_expect_success 'pulling into void' '
 		cd cloned &&
 		git pull ..
 	) &&
-	test -f file &&
-	test -f cloned/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned/file &&
 	test_cmp file cloned/file
 '
 
@@ -50,8 +50,8 @@ test_expect_success 'pulling into void using master:master' '
 		cd cloned-uho &&
 		git pull .. master:master
 	) &&
-	test -f file &&
-	test -f cloned-uho/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned-uho/file &&
 	test_cmp file cloned-uho/file
 '
 
@@ -99,7 +99,7 @@ test_expect_success 'pulling into void must not create an octopus' '
 	(
 		cd cloned-octopus &&
 		test_must_fail git pull .. master master &&
-		! test -f file
+		test_path_is_missing file
 	)
 '
 
-- 
2.23.0.897.g0a19638b1e


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

* Re: [PATCH 08/12] t5520: use test_cmp_rev where possible
  2019-10-17 23:17 ` [PATCH 08/12] t5520: use test_cmp_rev where possible Denton Liu
@ 2019-10-17 23:41   ` Eric Sunshine
  2019-10-18 18:52     ` Denton Liu
  0 siblings, 1 reply; 116+ messages in thread
From: Eric Sunshine @ 2019-10-17 23:41 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

On Thu, Oct 17, 2019 at 7:17 PM Denton Liu <liu.denton@gmail.com> wrote:
> In case an invocation of `git rev-list` fails within the subshell, the
> failure will be masked. Remove the subshell and use test_cmp_rev() so
> that failures can be discovered.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
> @@ -597,10 +597,10 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
>         test_must_fail git pull &&
> -       test "$COPY" = "$(git rev-parse --verify me/copy)" &&
> +       test_cmp_rev "$COPY" me/copy &&

This transformation doesn't look correct. COPY already holds the
result of a git-rev-parse invocation:

    COPY="$(git rev-parse --verify me/copy)" &&

so passing it to test_cmp_rev() -- which applies its own git-rev-parse
invocation -- doesn't make sense.

>         git checkout HEAD -- file &&
>         git pull &&
> -       test "$COPY" != "$(git rev-parse --verify me/copy)"
> +       test_must_fail test_cmp_rev "$COPY" me/copy

As mentioned in my review of the other patch, this is not a valid use
of test_must_fail().

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

* Re: [PATCH 09/12] t5520: test single-line files by git with test_cmp
  2019-10-17 23:17 ` [PATCH 09/12] t5520: test single-line files by git with test_cmp Denton Liu
@ 2019-10-17 23:49   ` Eric Sunshine
  0 siblings, 0 replies; 116+ messages in thread
From: Eric Sunshine @ 2019-10-17 23:49 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

On Thu, Oct 17, 2019 at 7:17 PM Denton Liu <liu.denton@gmail.com> wrote:
> In case an invocation of a Git command fails within the subshell, the
> failure will be masked. Replace the subshell with a file-redirection and
> a call to test_cmp.
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
> @@ -622,10 +648,16 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
>                 git add staged-file &&
> -               test "$(git ls-files)" = staged-file &&
> +               echo staged-file >expect &&
> +               git ls-files >actual &&
> +               test_cmp expect actual &&
>                 test_must_fail git pull --rebase .. master 2>err &&
> -               test "$(git ls-files)" = staged-file &&
> -               test "$(git show :staged-file)" = staged-file &&
> +               echo staged-file >expect &&
> +               git ls-files >actual &&
> +               test_cmp expect actual &&
> +               echo staged-file >expect &&
> +               git show :staged-file >actual &&
> +               test_cmp expect actual &&

Nit: I'm not convinced that it makes sense to re-create the "expect"
file with the exact same content repeatedly in this one test. There is
some value in creating the file once and then _using_ it repeatedly
since that shows intent that the the result of these various commands
is not expected to change.

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

* Re: [PATCH 4.5/12] t5520: replace test -f with test-lib functions
  2019-10-17 23:35   ` [PATCH 4.5/12] t5520: replace test -f with test-lib functions Denton Liu
@ 2019-10-18  0:11     ` Eric Sunshine
  0 siblings, 0 replies; 116+ messages in thread
From: Eric Sunshine @ 2019-10-18  0:11 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

On Thu, Oct 17, 2019 at 7:35 PM Denton Liu <liu.denton@gmail.com> wrote:
> Although `test -f` has the same functionality as test_path_is_file(), in
> the case where test_path_is_file() fails, we get much better debugging
> information.
>
> Replace `test -f` with test_path_is_file() so that future developers
> will have a better experience debugging these test cases. Also, in the
> case of `! test -f`, replace it with test_path_is_missing().
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> I just realised that test_path_is_missing() is a much better replacement
> than `test_must_fail test_path_is_file`.

That depends upon context...

> diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
> @@ -99,7 +99,7 @@ test_expect_success 'pulling into void must not create an octopus' '
> -               ! test -f file
> +               test_path_is_missing file

There is a semantic difference between checking that "file" is not a
_file_ versus checking that the a path itself (which may be a
directory or a "special file") does not exist. In this particular
test, the difference doesn't matter, so the conversion is sensible
enough, but it would save reviewers time if you, as author of the
patch, state that you carefully considered the distinction before
making each change.

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

* Re: [PATCH 08/12] t5520: use test_cmp_rev where possible
  2019-10-17 23:41   ` Eric Sunshine
@ 2019-10-18 18:52     ` Denton Liu
  2019-10-23 13:53       ` Eric Sunshine
  0 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-10-18 18:52 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git Mailing List

Hi Eric,

Thanks for the reviews. I have no idea how you always get to my patches
so quickly but I appreciate the prompt reviews whenever I send a
test-related patchset in.

I've fixed up the other concerns you had and I'll send a v2 later but I
wanted to address this one.

On Thu, Oct 17, 2019 at 07:41:44PM -0400, Eric Sunshine wrote:
> On Thu, Oct 17, 2019 at 7:17 PM Denton Liu <liu.denton@gmail.com> wrote:
> > In case an invocation of `git rev-list` fails within the subshell, the
> > failure will be masked. Remove the subshell and use test_cmp_rev() so
> > that failures can be discovered.
> >
> > Signed-off-by: Denton Liu <liu.denton@gmail.com>
> > ---
> > diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
> > @@ -597,10 +597,10 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
> >         test_must_fail git pull &&
> > -       test "$COPY" = "$(git rev-parse --verify me/copy)" &&
> > +       test_cmp_rev "$COPY" me/copy &&
> 
> This transformation doesn't look correct. COPY already holds the
> result of a git-rev-parse invocation:
> 
>     COPY="$(git rev-parse --verify me/copy)" &&
> 
> so passing it to test_cmp_rev() -- which applies its own git-rev-parse
> invocation -- doesn't make sense.

I'll annotate the entire test case with my comments:

	# so we'll be testing that pull --rebase dies early
	test_expect_success 'pull --rebase dies early with dirty working directory' '
		git checkout to-rebase &&
		git update-ref refs/remotes/me/copy copy^ &&
		COPY="$(git rev-parse --verify me/copy)" &&
		git rebase --onto $COPY copy &&

		# according to git log --graph, we have this currently:
		#
		# $ git log --pretty=oneline --graph to-rebase copy me/copy
		# * 9366795adb50ef6eb482b610b37cb1fb6edbd3d0 (HEAD -> to-rebase) to-rebase
		# * b3dcf50eea47c4ad85faabb0fb74eded71cc829f file3
		# * faf459539411b4557cf735232a3746be073177a9 new file
		# | * f340b1b8932f7b1e016c06867cbdc3f637eeea2d (copy) conflict
		# |/  
		# * 5e86d50a28977ebee5ea378f81591ea558149272 (me/second, me/copy, second) modified
		# * d25cf184567afad1dc1e018b2b7d793bc1bd2dc1 original

		test_config branch.to-rebase.remote me &&
		test_config branch.to-rebase.merge refs/heads/copy &&
		test_config branch.to-rebase.rebase true &&

		# we make the tree dirty here
		echo dirty >>file &&
		git add file &&

		# and over here, the pull should fail
		test_must_fail git pull &&

		# but since we're testing that it dies early, we want to
		# make sure that the remote ref doesn't change, which is
		# why it should still be equal
		test_cmp_rev "$COPY" me/copy &&

		git checkout HEAD -- file &&

		# but over here, the pull succeeds...
		git pull &&

		# so as a result, the remote ref should now be updated
		test_cmp_rev ! "$COPY" me/copy
	'

So after grokking the test case, it seems like the the transformation is
indeed correct. Maybe we can replace the last line with

	test_cmp_rev copy me/copy

but I think I'll leave it unless you have any strong opinions.

Thanks,

Denton

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

* [PATCH v2 01/15] t7408: replace `test_must_fail test_path_is_file`
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
@ 2019-10-18 22:04   ` Denton Liu
  2019-10-19 11:58     ` Johannes Sixt
  2019-10-18 22:04   ` [PATCH v2 09/15] t5520: replace test -{n,z} with test-lib functions Denton Liu
                     ` (15 subsequent siblings)
  16 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:04 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

According to t/README, test_must_fail() should only be used to test for
failure in git commands. Replace the only invocation of
`test_must_fail test_path_is_file` with `test_path_is_missing` since in
this test case, the path should not exist at all.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t7408-submodule-reference.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh
index 34ac28c056..9e62d43cac 100755
--- a/t/t7408-submodule-reference.sh
+++ b/t/t7408-submodule-reference.sh
@@ -123,7 +123,7 @@ test_expect_success 'missing submodule alternate fails clone and submodule updat
 		test_must_fail git submodule update --init &&
 		# and we have no alternates:
 		test_must_fail test_alternate_is_used .git/modules/sub/objects/info/alternates sub &&
-		test_must_fail test_path_is_file sub/file1
+		test_path_is_missing sub/file1
 	)
 '
 
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 09/15] t5520: replace test -{n,z} with test-lib functions
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
  2019-10-18 22:04   ` [PATCH v2 01/15] t7408: replace `test_must_fail test_path_is_file` Denton Liu
@ 2019-10-18 22:04   ` Denton Liu
  2019-10-18 22:04   ` [PATCH v2 11/15] t5520: test single-line files by git with test_cmp Denton Liu
                     ` (14 subsequent siblings)
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:04 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

When wrapping a Git command in a subshell within another command, we
throw away the Git command's exit code. In case the Git command fails,
we would like to know about it rather than the failure being silent.
Extract Git commands so that their exit codes are not lost.

Instead of using `test -n` or `test -z`, replace them respectively with
invocations of test_file_not_empty() and test_must_be_empty() so that we
get better debugging information in the case of a failure.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 0ca4867e96..18225d8430 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -206,15 +206,18 @@ test_expect_success 'fail if the index has unresolved entries' '
 	test_when_finished "git checkout -f copy && git branch -D third" &&
 	test "$(cat file)" = file &&
 	test_commit modified2 file &&
-	test -z "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_must_be_empty unmerged &&
 	test_must_fail git pull . second &&
-	test -n "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_file_not_empty unmerged &&
 	cp file expected &&
 	test_must_fail git pull . second 2>err &&
 	test_i18ngrep "Pulling is not possible because you have unmerged files." err &&
 	test_cmp expected file &&
 	git add file &&
-	test -z "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_must_be_empty unmerged &&
 	test_must_fail git pull . second 2>err &&
 	test_i18ngrep "You have not concluded your merge" err &&
 	test_cmp expected file
@@ -667,7 +670,8 @@ test_expect_success 'git pull --rebase detects upstreamed changes' '
 	(
 		cd dst &&
 		git pull --rebase &&
-		test -z "$(git ls-files -u)"
+		git ls-files -u >untracked &&
+		test_must_be_empty untracked
 	)
 '
 
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 11/15] t5520: test single-line files by git with test_cmp
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
  2019-10-18 22:04   ` [PATCH v2 01/15] t7408: replace `test_must_fail test_path_is_file` Denton Liu
  2019-10-18 22:04   ` [PATCH v2 09/15] t5520: replace test -{n,z} with test-lib functions Denton Liu
@ 2019-10-18 22:04   ` Denton Liu
  2019-10-18 22:10   ` [PATCH v2 02/15] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
                     ` (13 subsequent siblings)
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:04 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

In case an invocation of a Git command fails within the subshell, the
failure will be masked. Replace the subshell with a file-redirection and
a call to test_cmp.

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^ ]*\) = "$(\(git [^)]*\))"/\1echo \2 >expect \&\&\n\1\3 >actual \&\&\n\1test_cmp expect actual/
	s/\(\s*\)test "$(\(git [^)]*\))" = \([^ ]*\)/\1echo \3 >expect \&\&\n\1\2 >actual \&\&\n\1test_cmp expect actual/

A future patch will clean up situations where we have multiple duplicate
statements within a test case. This is done to keep this patch purely
mechanical.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 64 ++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 16 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 1af6ea06ee..8b7e7ae55d 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -255,7 +255,9 @@ test_expect_success '--rebase' '
 	git tag before-rebase &&
 	git pull --rebase . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase fast forward' '
@@ -330,7 +332,9 @@ test_expect_success '--rebase fails with multiple branches' '
 	test_must_fail git pull --rebase . copy master 2>err &&
 	test_cmp_rev HEAD before-rebase &&
 	test_i18ngrep "Cannot rebase onto multiple branches" err &&
-	test modified = "$(git show HEAD:file)"
+	echo modified >expect &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
@@ -381,7 +385,9 @@ test_expect_success 'pull.rebase' '
 	test_config pull.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --autostash & pull.rebase=true' '
@@ -399,7 +405,9 @@ test_expect_success 'branch.to-rebase.rebase' '
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
@@ -408,14 +416,18 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_config branch.to-rebase.rebase false &&
 	git pull . copy &&
 	test_cmp_rev ! HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)" &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual &&
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
 
@@ -423,7 +435,9 @@ test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)" &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual &&
 	test_i18ngrep ! "verify-signatures" err
 '
 
@@ -445,7 +459,9 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	git pull . copy &&
 	test_cmp_rev HEAD^1 before-preserve-rebase &&
 	test_cmp_rev HEAD^2 copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull.rebase=true flattens keep-merge' '
@@ -453,7 +469,9 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
 	test_config pull.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
@@ -461,7 +479,9 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	test_config pull.rebase 1 &&
 	git pull . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success REBASE_P \
@@ -507,7 +527,9 @@ test_expect_success '--rebase=false create a new merge commit' '
 	git pull --rebase=false . copy &&
 	test_cmp_rev HEAD^1 before-preserve-rebase &&
 	test_cmp_rev HEAD^2 copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase=true rebases and flattens keep-merge' '
@@ -515,7 +537,9 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
 	test_config pull.rebase preserve &&
 	git pull --rebase=true . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success REBASE_P \
@@ -537,7 +561,9 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 	test_config pull.rebase preserve &&
 	git pull --rebase . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase with rebased upstream' '
@@ -622,10 +648,16 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
 		cd empty_repo2 &&
 		echo staged-file >staged-file &&
 		git add staged-file &&
-		test "$(git ls-files)" = staged-file &&
+		echo staged-file >expect &&
+		git ls-files >actual &&
+		test_cmp expect actual &&
 		test_must_fail git pull --rebase .. master 2>err &&
-		test "$(git ls-files)" = staged-file &&
-		test "$(git show :staged-file)" = staged-file &&
+		echo staged-file >expect &&
+		git ls-files >actual &&
+		test_cmp expect actual &&
+		echo staged-file >expect &&
+		git show :staged-file >actual &&
+		test_cmp expect actual &&
 		test_i18ngrep "unborn branch with changes added to the index" err
 	)
 '
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 00/15] t5520: various test cleanup
  2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
                   ` (11 preceding siblings ...)
  2019-10-17 23:17 ` [PATCH 12/12] t5520: replace `! git` with `test_must_fail git` Denton Liu
@ 2019-10-18 22:10 ` Denton Liu
  2019-10-18 22:04   ` [PATCH v2 01/15] t7408: replace `test_must_fail test_path_is_file` Denton Liu
                     ` (16 more replies)
  12 siblings, 17 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

Like earlier patchsets, I want to implement a feature that involves
modifications to the test suite. Since that feature will probably take a
while to polish up, however, let's clean up the test suite in a separate
patchset first so it's not blocked by the feature work.

1/15 is a cleanup to an unrelated test that I found while addressing
some of Eric's comments.

2/15 is a general improvement to test_rev_cmp() that will be used later
in the series.

Changes since v1:

* Incorporate Eric's feedback

Denton Liu (15):
  t7408: replace `test_must_fail test_path_is_file`
  t: teach test_cmp_rev to accept ! for not-equals
  t5520: improve test style
  t5520: use sq for test case names
  t5520: let sed open its own input
  t5520: replace test -f with test-lib functions
  t5520: remove spaces after redirect operator
  t5520: use test_line_count where possible
  t5520: replace test -{n,z} with test-lib functions
  t5520: use test_cmp_rev where possible
  t5520: test single-line files by git with test_cmp
  t5520: don't put git in upstream of pipe
  t5520: replace subshell cat comparison with test_cmp
  t5520: remove redundant lines in test cases
  t5520: replace `! git` with `test_must_fail git`

 t/t2400-worktree-add.sh             |   4 +-
 t/t3400-rebase.sh                   |   2 +-
 t/t3421-rebase-topology-linear.sh   |   6 +-
 t/t3430-rebase-merges.sh            |   2 +-
 t/t3432-rebase-fast-forward.sh      |   2 +-
 t/t3501-revert-cherry-pick.sh       |   2 +-
 t/t3508-cherry-pick-many-commits.sh |   2 +-
 t/t5520-pull.sh                     | 343 +++++++++++++++++-----------
 t/t7408-submodule-reference.sh      |   2 +-
 t/test-lib-functions.sh             |  13 +-
 10 files changed, 227 insertions(+), 151 deletions(-)

Range-diff against v1:
 -:  ---------- >  1:  987fee4652 t7408: replace `test_must_fail test_path_is_file`
 -:  ---------- >  2:  417e808466 t: teach test_cmp_rev to accept ! for not-equals
 1:  0bc54dd330 =  3:  0a56980857 t5520: improve test style
 2:  a5dee82ecc =  4:  dfa89ba1cb t5520: use sq for test case names
 3:  58cc2fcda3 =  5:  9fac3dff83 t5520: let sed open its own input
 4:  d2946208d3 !  6:  c6ca45eb17 t5520: replace test -f with test_path_is_file
    @@ Metadata
     Author: Denton Liu <liu.denton@gmail.com>
     
      ## Commit message ##
    -    t5520: replace test -f with test_path_is_file
    +    t5520: replace test -f with test-lib functions
     
         Although `test -f` has the same functionality as test_path_is_file(), in
         the case where test_path_is_file() fails, we get much better debugging
    -    information. Replace `test -f` with test_path_is_file so that future
    -    developers will have a better experience debugging these test cases.
    +    information.
    +
    +    Replace `test -f` with test_path_is_file() so that future developers
    +    will have a better experience debugging these test cases.
    +
    +    Also, in the case of `! test -f`, not only should that path not be a
    +    file, it shouldn't exist at all so replace it with
    +    test_path_is_missing().
     
         Signed-off-by: Denton Liu <liu.denton@gmail.com>
     
    @@ t/t5520-pull.sh: test_expect_success 'pulling into void must not create an octop
      		cd cloned-octopus &&
      		test_must_fail git pull .. master master &&
     -		! test -f file
    -+		test_must_fail test_path_is_file file
    ++		test_path_is_missing file
      	)
      '
      
 5:  5b4c1dd291 =  7:  830a8212ae t5520: remove spaces after redirect operator
 6:  26fea15950 =  8:  3d982230be t5520: use test_line_count where possible
 7:  3fc0354c9c !  9:  2bca4f046d t5520: replace test -{n,z} with test-lib functions
    @@ Metadata
      ## Commit message ##
         t5520: replace test -{n,z} with test-lib functions
     
    +    When wrapping a Git command in a subshell within another command, we
    +    throw away the Git command's exit code. In case the Git command fails,
    +    we would like to know about it rather than the failure being silent.
    +    Extract Git commands so that their exit codes are not lost.
    +
         Instead of using `test -n` or `test -z`, replace them respectively with
    -    invocations of test_file_not_empty() and test_must_be_empty().
    +    invocations of test_file_not_empty() and test_must_be_empty() so that we
    +    get better debugging information in the case of a failure.
     
         Signed-off-by: Denton Liu <liu.denton@gmail.com>
     
 8:  f4eb80c9ac ! 10:  1a54db1d5c t5520: use test_cmp_rev where possible
    @@ Commit message
     
                 s/test "$(git rev-parse.* \([^)]*\))" = "$(git rev-parse \([^)]*\))"/test_cmp_rev \1 \2/
                 s/test \([^ ]*\) = "$(git rev-parse.* \([^)]*\))"/test_cmp_rev \1 \2/
    -            s/test "$(git rev-parse.* \([^)]*\))" != "$(git rev-parse.* \([^)]*\))"/test_must_fail test_cmp_rev \1 \2/
    -            s/test \([^ ]*\) != "$(git rev-parse.* \([^)]*\))"/test_must_fail test_cmp_rev \1 \2/
    +            s/test "$(git rev-parse.* \([^)]*\))" != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/
    +            s/test \([^ ]*\) != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/
     
         Signed-off-by: Denton Liu <liu.denton@gmail.com>
     
    @@ t/t5520-pull.sh: test_expect_success 'branch.to-rebase.rebase should override pu
      	test_config branch.to-rebase.rebase false &&
      	git pull . copy &&
     -	test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
    -+	test_must_fail test_cmp_rev HEAD^ copy &&
    ++	test_cmp_rev ! HEAD^ copy &&
      	test new = "$(git show HEAD:file2)"
      '
      
    @@ t/t5520-pull.sh: test_expect_success 'pull --rebase dies early with dirty workin
      	git checkout HEAD -- file &&
      	git pull &&
     -	test "$COPY" != "$(git rev-parse --verify me/copy)"
    -+	test_must_fail test_cmp_rev "$COPY" me/copy
    ++	test_cmp_rev ! "$COPY" me/copy
      '
      
      test_expect_success 'pull --rebase works on branch yet to be born' '
 9:  bd3ec4239c ! 11:  52cf4f0d0f t5520: test single-line files by git with test_cmp
    @@ Commit message
                 s/\(\s*\)test \([^ ]*\) = "$(\(git [^)]*\))"/\1echo \2 >expect \&\&\n\1\3 >actual \&\&\n\1test_cmp expect actual/
                 s/\(\s*\)test "$(\(git [^)]*\))" = \([^ ]*\)/\1echo \3 >expect \&\&\n\1\2 >actual \&\&\n\1test_cmp expect actual/
     
    +    A future patch will clean up situations where we have multiple duplicate
    +    statements within a test case. This is done to keep this patch purely
    +    mechanical.
    +
         Signed-off-by: Denton Liu <liu.denton@gmail.com>
     
      ## t/t5520-pull.sh ##
    @@ t/t5520-pull.sh: test_expect_success 'branch.to-rebase.rebase' '
     @@ t/t5520-pull.sh: test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
      	test_config branch.to-rebase.rebase false &&
      	git pull . copy &&
    - 	test_must_fail test_cmp_rev HEAD^ copy &&
    + 	test_cmp_rev ! HEAD^ copy &&
     -	test new = "$(git show HEAD:file2)"
     +	echo new >expect &&
     +	git show HEAD:file2 >actual &&
10:  61b4df0f7c = 12:  0cfabb201c t5520: don't put git in upstream of pipe
11:  f3429bbb57 ! 13:  b2d0ce21c8 t5520: replace subshell cat comparison with test_cmp
    @@ Commit message
                 s/\(\s*\)test \([^=]*\)= "$(cat \([^)]*\))"/\1echo \2>expect \&\&\n\1test_cmp expect \3/
                 s/\(\s*\)test "$(cat \([^)]*\))" = \([^&]*\)\( &&\)\?$/\1echo \3 >expect \&\&\n\1test_cmp expect \2\4/
     
    +    A future patch will clean up situations where we have multiple duplicate
    +    statements within a test case. This is done to keep this patch purely
    +    mechanical.
    +
         Signed-off-by: Denton Liu <liu.denton@gmail.com>
     
      ## t/t5520-pull.sh ##
 -:  ---------- > 14:  5aac40a029 t5520: remove redundant lines in test cases
12:  3e6c591b2b = 15:  2c0d3ac416 t5520: replace `! git` with `test_must_fail git`
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 02/15] t: teach test_cmp_rev to accept ! for not-equals
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (2 preceding siblings ...)
  2019-10-18 22:04   ` [PATCH v2 11/15] t5520: test single-line files by git with test_cmp Denton Liu
@ 2019-10-18 22:10   ` Denton Liu
  2019-10-18 22:45     ` SZEDER Gábor
  2019-10-18 22:10   ` [PATCH v2 03/15] t5520: improve test style Denton Liu
                     ` (12 subsequent siblings)
  16 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

Currently, in the case where we are using test_cmp_rev() to report
not-equals, we write `! test_cmp_rev`. However, since test_cmp_rev()
contains

	r1=$(git rev-parse --verify "$1") &&
	r2=$(git rev-parse --verify "$2") &&

In the case where `git rev-parse` segfaults and dies unexpectedly, the
failure will be ignored.

Rewrite test_cmp_rev() to optionally accept "!" as the first argument to
do a not-equals comparison. Rewrite `! test_cmp_rev` to `test_cmp_rev !`
in all tests to take advantage of this new functionality.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t2400-worktree-add.sh             |  4 ++--
 t/t3400-rebase.sh                   |  2 +-
 t/t3421-rebase-topology-linear.sh   |  6 +++---
 t/t3430-rebase-merges.sh            |  2 +-
 t/t3432-rebase-fast-forward.sh      |  2 +-
 t/t3501-revert-cherry-pick.sh       |  2 +-
 t/t3508-cherry-pick-many-commits.sh |  2 +-
 t/test-lib-functions.sh             | 13 +++++++++++--
 8 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index e819ba741e..52d476979b 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -438,7 +438,7 @@ test_expect_success 'git worktree add does not match remote' '
 		cd foo &&
 		test_must_fail git config "branch.foo.remote" &&
 		test_must_fail git config "branch.foo.merge" &&
-		! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
+		test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
 	)
 '
 
@@ -483,7 +483,7 @@ test_expect_success 'git worktree --no-guess-remote option overrides config' '
 		cd foo &&
 		test_must_fail git config "branch.foo.remote" &&
 		test_must_fail git config "branch.foo.merge" &&
-		! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
+		test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
 	)
 '
 
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index ab18ac5f28..f267f6cd54 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -64,7 +64,7 @@ test_expect_success 'rebase sets ORIG_HEAD to pre-rebase state' '
 	pre="$(git rev-parse --verify HEAD)" &&
 	git rebase master &&
 	test_cmp_rev "$pre" ORIG_HEAD &&
-	! test_cmp_rev "$pre" HEAD
+	test_cmp_rev ! "$pre" HEAD
 '
 
 test_expect_success 'rebase, with <onto> and <upstream> specified as :/quuxery' '
diff --git a/t/t3421-rebase-topology-linear.sh b/t/t3421-rebase-topology-linear.sh
index b847064f91..325072b0a3 100755
--- a/t/t3421-rebase-topology-linear.sh
+++ b/t/t3421-rebase-topology-linear.sh
@@ -61,7 +61,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" "
 		reset_rebase &&
 		git rebase $* -f b e &&
-		! test_cmp_rev e HEAD &&
+		test_cmp_rev ! e HEAD &&
 		test_cmp_rev b HEAD~2 &&
 		test_linear_range 'd e' b..
 	"
@@ -78,7 +78,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
 		reset_rebase &&
 		git rebase $* -f branch-b branch-e &&
-		! test_cmp_rev branch-e origin/branch-e &&
+		test_cmp_rev ! branch-e origin/branch-e &&
 		test_cmp_rev branch-b HEAD~2 &&
 		test_linear_range 'd e' branch-b..
 	"
@@ -368,7 +368,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f --root on linear history causes re-write" "
 		reset_rebase &&
 		git rebase $* -f --root c &&
-		! test_cmp_rev a HEAD~2 &&
+		test_cmp_rev ! a HEAD~2 &&
 		test_linear_range 'a b c' HEAD
 	"
 }
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index 9efcf4808a..abbdc26b1b 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -346,7 +346,7 @@ test_expect_success 'A root commit can be a cousin, treat it that way' '
 	git merge --allow-unrelated-histories khnum &&
 	test_tick &&
 	git rebase -f -r HEAD^ &&
-	! test_cmp_rev HEAD^2 khnum &&
+	test_cmp_rev ! HEAD^2 khnum &&
 	test_cmp_graph HEAD^.. <<-\EOF &&
 	*   Merge branch '\''khnum'\'' into asherah
 	|\
diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh
index 034ffc7e76..92f95b57da 100755
--- a/t/t3432-rebase-fast-forward.sh
+++ b/t/t3432-rebase-fast-forward.sh
@@ -64,7 +64,7 @@ test_rebase_same_head_ () {
 			test_cmp_rev \$oldhead \$newhead
 		elif test $cmp = diff
 		then
-			! test_cmp_rev \$oldhead \$newhead
+			test_cmp_rev ! \$oldhead \$newhead
 		fi
 	"
 }
diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh
index d1c68af8c5..1c51a9131d 100755
--- a/t/t3501-revert-cherry-pick.sh
+++ b/t/t3501-revert-cherry-pick.sh
@@ -106,7 +106,7 @@ test_expect_success 'cherry-pick on unborn branch' '
 	rm -rf * &&
 	git cherry-pick initial &&
 	git diff --quiet initial &&
-	! test_cmp_rev initial HEAD
+	test_cmp_rev ! initial HEAD
 '
 
 test_expect_success 'cherry-pick "-" to pick from previous branch' '
diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh
index b457333e18..23070a7b73 100755
--- a/t/t3508-cherry-pick-many-commits.sh
+++ b/t/t3508-cherry-pick-many-commits.sh
@@ -5,7 +5,7 @@ test_description='test cherry-picking many commits'
 . ./test-lib.sh
 
 check_head_differs_from() {
-	! test_cmp_rev HEAD "$1"
+	test_cmp_rev ! HEAD "$1"
 }
 
 check_head_equals() {
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b299ecc326..76dce5f8ee 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1012,8 +1012,17 @@ test_must_be_empty () {
 	fi
 }
 
-# Tests that its two parameters refer to the same revision
+# Tests that its two parameters refer to the same revision, or if '!' is
+# provided first, that its other two parameters refer to different
+# revisions.
 test_cmp_rev () {
+	local inverted_op
+	inverted_op='!='
+	if test $# -ge 1 && test "x$1" = 'x!'
+	then
+	    inverted_op='='
+	    shift
+	fi
 	if test $# != 2
 	then
 		error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
@@ -1021,7 +1030,7 @@ test_cmp_rev () {
 		local r1 r2
 		r1=$(git rev-parse --verify "$1") &&
 		r2=$(git rev-parse --verify "$2") &&
-		if test "$r1" != "$r2"
+		if test "$r1" "$inverted_op" "$r2"
 		then
 			cat >&4 <<-EOF
 			error: two revisions point to different objects:
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 03/15] t5520: improve test style
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (3 preceding siblings ...)
  2019-10-18 22:10   ` [PATCH v2 02/15] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
@ 2019-10-18 22:10   ` Denton Liu
  2019-10-18 22:10   ` [PATCH v2 04/15] t5520: use sq for test case names Denton Liu
                     ` (11 subsequent siblings)
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

Improve the test style by removing leading and trailing empty lines
within test cases. Also, reformat multi-line subshells to conform to the
existing style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 88 +++++++++++++++++++++++++------------------------
 1 file changed, 45 insertions(+), 43 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index cf4cc32fd0..51d6ce8aec 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -538,7 +538,6 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 '
 
 test_expect_success '--rebase with rebased upstream' '
-
 	git remote add -f me . &&
 	git checkout copy &&
 	git tag copy-orig &&
@@ -552,7 +551,6 @@ test_expect_success '--rebase with rebased upstream' '
 	git pull --rebase me copy &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = "$(cat file2)"
-
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
@@ -564,14 +562,12 @@ test_expect_success '--rebase -f with rebased upstream' '
 '
 
 test_expect_success '--rebase with rebased default upstream' '
-
 	git update-ref refs/remotes/me/copy copy-orig &&
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = "$(cat file2)"
-
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -588,7 +584,6 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 '
 
 test_expect_success 'pull --rebase dies early with dirty working directory' '
-
 	git checkout to-rebase &&
 	git update-ref refs/remotes/me/copy copy^ &&
 	COPY="$(git rev-parse --verify me/copy)" &&
@@ -603,16 +598,16 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	git checkout HEAD -- file &&
 	git pull &&
 	test "$COPY" != "$(git rev-parse --verify me/copy)"
-
 '
 
 test_expect_success 'pull --rebase works on branch yet to be born' '
 	git rev-parse master >expect &&
 	mkdir empty_repo &&
-	(cd empty_repo &&
-	 git init &&
-	 git pull --rebase .. master &&
-	 git rev-parse HEAD >../actual
+	(
+		cd empty_repo &&
+		git init &&
+		git pull --rebase .. master &&
+		git rev-parse HEAD >../actual
 	) &&
 	test_cmp expect actual
 '
@@ -646,58 +641,65 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 
 test_expect_success 'setup for detecting upstreamed changes' '
 	mkdir src &&
-	(cd src &&
-	 git init &&
-	 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
-	 git add stuff &&
-	 git commit -m "Initial revision"
+	(
+		cd src &&
+		git init &&
+		printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
+		git add stuff &&
+		git commit -m "Initial revision"
 	) &&
 	git clone src dst &&
-	(cd src &&
-	 modify s/5/43/ stuff &&
-	 git commit -a -m "5->43" &&
-	 modify s/6/42/ stuff &&
-	 git commit -a -m "Make it bigger"
+	(
+		cd src &&
+		modify s/5/43/ stuff &&
+		git commit -a -m "5->43" &&
+		modify s/6/42/ stuff &&
+		git commit -a -m "Make it bigger"
 	) &&
-	(cd dst &&
-	 modify s/5/43/ stuff &&
-	 git commit -a -m "Independent discovery of 5->43"
+	(
+		cd dst &&
+		modify s/5/43/ stuff &&
+		git commit -a -m "Independent discovery of 5->43"
 	)
 '
 
 test_expect_success 'git pull --rebase detects upstreamed changes' '
-	(cd dst &&
-	 git pull --rebase &&
-	 test -z "$(git ls-files -u)"
+	(
+		cd dst &&
+		git pull --rebase &&
+		test -z "$(git ls-files -u)"
 	)
 '
 
 test_expect_success 'setup for avoiding reapplying old patches' '
-	(cd dst &&
-	 test_might_fail git rebase --abort &&
-	 git reset --hard origin/master
+	(
+		cd dst &&
+		test_might_fail git rebase --abort &&
+		git reset --hard origin/master
 	) &&
 	git clone --bare src src-replace.git &&
 	rm -rf src &&
 	mv src-replace.git src &&
-	(cd dst &&
-	 modify s/2/22/ stuff &&
-	 git commit -a -m "Change 2" &&
-	 modify s/3/33/ stuff &&
-	 git commit -a -m "Change 3" &&
-	 modify s/4/44/ stuff &&
-	 git commit -a -m "Change 4" &&
-	 git push &&
-
-	 modify s/44/55/ stuff &&
-	 git commit --amend -a -m "Modified Change 4"
+	(
+		cd dst &&
+		modify s/2/22/ stuff &&
+		git commit -a -m "Change 2" &&
+		modify s/3/33/ stuff &&
+		git commit -a -m "Change 3" &&
+		modify s/4/44/ stuff &&
+		git commit -a -m "Change 4" &&
+		git push &&
+
+		modify s/44/55/ stuff &&
+		git commit --amend -a -m "Modified Change 4"
 	)
 '
 
 test_expect_success 'git pull --rebase does not reapply old patches' '
-	(cd dst &&
-	 test_must_fail git pull --rebase &&
-	 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+	(
+		cd dst &&
+		test_must_fail git pull --rebase &&
+		test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
 	)
 '
 
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 04/15] t5520: use sq for test case names
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (4 preceding siblings ...)
  2019-10-18 22:10   ` [PATCH v2 03/15] t5520: improve test style Denton Liu
@ 2019-10-18 22:10   ` Denton Liu
  2019-10-18 22:10   ` [PATCH v2 05/15] t5520: let sed open its own input Denton Liu
                     ` (10 subsequent siblings)
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

The usual convention is for test case names to be written between
single-quotes. Change all double-quoted test case names to single-quotes
except for two test case names that use variables within.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 51d6ce8aec..a3de2e19b6 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -408,7 +408,7 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test new = "$(git show HEAD:file2)"
 '
 
-test_expect_success "pull --rebase warns on --verify-signatures" '
+test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
 	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
@@ -416,7 +416,7 @@ test_expect_success "pull --rebase warns on --verify-signatures" '
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
 
-test_expect_success "pull --rebase does not warn on --no-verify-signatures" '
+test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
 	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 05/15] t5520: let sed open its own input
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (5 preceding siblings ...)
  2019-10-18 22:10   ` [PATCH v2 04/15] t5520: use sq for test case names Denton Liu
@ 2019-10-18 22:10   ` Denton Liu
  2019-10-18 22:10   ` [PATCH v2 06/15] t5520: replace test -f with test-lib functions Denton Liu
                     ` (9 subsequent siblings)
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

We were using a redirection operator to feed input into sed. However,
since sed is capable of opening its own files, make sed open its own
files instead of redirecting input into it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a3de2e19b6..55560ce3cd 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -5,7 +5,7 @@ test_description='pulling into void'
 . ./test-lib.sh
 
 modify () {
-	sed -e "$1" <"$2" >"$2.x" &&
+	sed -e "$1" "$2" >"$2.x" &&
 	mv "$2.x" "$2"
 }
 
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 06/15] t5520: replace test -f with test-lib functions
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (6 preceding siblings ...)
  2019-10-18 22:10   ` [PATCH v2 05/15] t5520: let sed open its own input Denton Liu
@ 2019-10-18 22:10   ` Denton Liu
  2019-10-18 22:10   ` [PATCH v2 07/15] t5520: remove spaces after redirect operator Denton Liu
                     ` (8 subsequent siblings)
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

Although `test -f` has the same functionality as test_path_is_file(), in
the case where test_path_is_file() fails, we get much better debugging
information.

Replace `test -f` with test_path_is_file() so that future developers
will have a better experience debugging these test cases.

Also, in the case of `! test -f`, not only should that path not be a
file, it shouldn't exist at all so replace it with
test_path_is_missing().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 55560ce3cd..004d5884cd 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -39,8 +39,8 @@ test_expect_success 'pulling into void' '
 		cd cloned &&
 		git pull ..
 	) &&
-	test -f file &&
-	test -f cloned/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned/file &&
 	test_cmp file cloned/file
 '
 
@@ -50,8 +50,8 @@ test_expect_success 'pulling into void using master:master' '
 		cd cloned-uho &&
 		git pull .. master:master
 	) &&
-	test -f file &&
-	test -f cloned-uho/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned-uho/file &&
 	test_cmp file cloned-uho/file
 '
 
@@ -99,7 +99,7 @@ test_expect_success 'pulling into void must not create an octopus' '
 	(
 		cd cloned-octopus &&
 		test_must_fail git pull .. master master &&
-		! test -f file
+		test_path_is_missing file
 	)
 '
 
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 07/15] t5520: remove spaces after redirect operator
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (7 preceding siblings ...)
  2019-10-18 22:10   ` [PATCH v2 06/15] t5520: replace test -f with test-lib functions Denton Liu
@ 2019-10-18 22:10   ` Denton Liu
  2019-10-18 22:10   ` [PATCH v2 08/15] t5520: use test_line_count where possible Denton Liu
                     ` (7 subsequent siblings)
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

The style for tests in Git is to have the redirect operator attached to
the filename with no spaces. Fix test cases where this is not the case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 004d5884cd..7bb9031140 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -243,10 +243,10 @@ test_expect_success 'fast-forward fails with conflicting work tree' '
 
 test_expect_success '--rebase' '
 	git branch to-rebase &&
-	echo modified again > file &&
+	echo modified again >file &&
 	git commit -m file file &&
 	git checkout to-rebase &&
-	echo new > file2 &&
+	echo new >file2 &&
 	git add file2 &&
 	git commit -m "new file" &&
 	git tag before-rebase &&
@@ -542,10 +542,10 @@ test_expect_success '--rebase with rebased upstream' '
 	git checkout copy &&
 	git tag copy-orig &&
 	git reset --hard HEAD^ &&
-	echo conflicting modification > file &&
+	echo conflicting modification >file &&
 	git commit -m conflict file &&
 	git checkout to-rebase &&
-	echo file > file2 &&
+	echo file >file2 &&
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
@@ -591,7 +591,7 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	test_config branch.to-rebase.remote me &&
 	test_config branch.to-rebase.merge refs/heads/copy &&
 	test_config branch.to-rebase.rebase true &&
-	echo dirty >> file &&
+	echo dirty >>file &&
 	git add file &&
 	test_must_fail git pull &&
 	test "$COPY" = "$(git rev-parse --verify me/copy)" &&
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 08/15] t5520: use test_line_count where possible
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (8 preceding siblings ...)
  2019-10-18 22:10   ` [PATCH v2 07/15] t5520: remove spaces after redirect operator Denton Liu
@ 2019-10-18 22:10   ` Denton Liu
  2019-10-18 22:10   ` [PATCH v2 10/15] t5520: use test_cmp_rev " Denton Liu
                     ` (6 subsequent siblings)
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

Instead of rolling our own functionality to test the number of lines a
command outputs, use test_line_count() which provides better debugging
information in the case of a failure.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 7bb9031140..0ca4867e96 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -699,7 +699,8 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 	(
 		cd dst &&
 		test_must_fail git pull --rebase &&
-		test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+		find .git/rebase-apply -name "000*" >patches &&
+		test_line_count = 1 patches
 	)
 '
 
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 10/15] t5520: use test_cmp_rev where possible
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (9 preceding siblings ...)
  2019-10-18 22:10   ` [PATCH v2 08/15] t5520: use test_line_count where possible Denton Liu
@ 2019-10-18 22:10   ` Denton Liu
  2019-10-18 22:10   ` [PATCH v2 12/15] t5520: don't put git in upstream of pipe Denton Liu
                     ` (5 subsequent siblings)
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

In case an invocation of `git rev-list` fails within the subshell, the
failure will be masked. Remove the subshell and use test_cmp_rev() so
that failures can be discovered.

This change was done with the following sed expressions:

	s/test "$(git rev-parse.* \([^)]*\))" = "$(git rev-parse \([^)]*\))"/test_cmp_rev \1 \2/
	s/test \([^ ]*\) = "$(git rev-parse.* \([^)]*\))"/test_cmp_rev \1 \2/
	s/test "$(git rev-parse.* \([^)]*\))" != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/
	s/test \([^ ]*\) != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 50 ++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 18225d8430..1af6ea06ee 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -230,7 +230,7 @@ test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
 	test "$(cat file)" = modified &&
-	test "$(git rev-parse third)" = "$(git rev-parse second)"
+	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
@@ -241,7 +241,7 @@ test_expect_success 'fast-forward fails with conflicting work tree' '
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
 	test "$(cat file)" = conflict &&
-	test "$(git rev-parse third)" = "$(git rev-parse second)"
+	test_cmp_rev third second
 '
 
 test_expect_success '--rebase' '
@@ -254,7 +254,7 @@ test_expect_success '--rebase' '
 	git commit -m "new file" &&
 	git tag before-rebase &&
 	git pull --rebase . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -266,7 +266,7 @@ test_expect_success '--rebase fast forward' '
 
 	git checkout to-rebase &&
 	git pull --rebase . ff &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse ff)" &&
+	test_cmp_rev HEAD ff &&
 
 	# The above only validates the result.  Did we actually bypass rebase?
 	git reflog -1 >reflog.actual &&
@@ -290,7 +290,7 @@ test_expect_success '--rebase --autostash fast forward' '
 	git checkout behind &&
 	echo dirty >file &&
 	git pull --rebase --autostash . to-rebase-ff &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse to-rebase-ff)"
+	test_cmp_rev HEAD to-rebase-ff
 '
 
 test_expect_success '--rebase with conflicts shows advice' '
@@ -328,7 +328,7 @@ test_expect_success 'failed --rebase shows advice' '
 test_expect_success '--rebase fails with multiple branches' '
 	git reset --hard before-rebase &&
 	test_must_fail git pull --rebase . copy master 2>err &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse before-rebase)" &&
+	test_cmp_rev HEAD before-rebase &&
 	test_i18ngrep "Cannot rebase onto multiple branches" err &&
 	test modified = "$(git show HEAD:file)"
 '
@@ -380,7 +380,7 @@ test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -398,7 +398,7 @@ test_expect_success 'branch.to-rebase.rebase' '
 	git reset --hard before-rebase &&
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -407,14 +407,14 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_config pull.rebase true &&
 	test_config branch.to-rebase.rebase false &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
+	test_cmp_rev ! HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)" &&
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
@@ -422,7 +422,7 @@ test_expect_success 'pull --rebase warns on --verify-signatures' '
 test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)" &&
 	test_i18ngrep ! "verify-signatures" err
 '
@@ -443,8 +443,8 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase false &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^1 before-preserve-rebase &&
+	test_cmp_rev HEAD^2 copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -452,7 +452,7 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -460,7 +460,7 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase 1 &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -469,8 +469,8 @@ test_expect_success REBASE_P \
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
+	test_cmp_rev HEAD^^ copy &&
+	test_cmp_rev HEAD^2 keep-merge
 '
 
 test_expect_success 'pull.rebase=interactive' '
@@ -505,8 +505,8 @@ test_expect_success '--rebase=false create a new merge commit' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull --rebase=false . copy &&
-	test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^1 before-preserve-rebase &&
+	test_cmp_rev HEAD^2 copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -514,7 +514,7 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull --rebase=true . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -523,8 +523,8 @@ test_expect_success REBASE_P \
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull --rebase=preserve . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
+	test_cmp_rev HEAD^^ copy &&
+	test_cmp_rev HEAD^2 keep-merge
 '
 
 test_expect_success '--rebase=invalid fails' '
@@ -536,7 +536,7 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull --rebase . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -597,10 +597,10 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	echo dirty >>file &&
 	git add file &&
 	test_must_fail git pull &&
-	test "$COPY" = "$(git rev-parse --verify me/copy)" &&
+	test_cmp_rev "$COPY" me/copy &&
 	git checkout HEAD -- file &&
 	git pull &&
-	test "$COPY" != "$(git rev-parse --verify me/copy)"
+	test_cmp_rev ! "$COPY" me/copy
 '
 
 test_expect_success 'pull --rebase works on branch yet to be born' '
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 12/15] t5520: don't put git in upstream of pipe
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (10 preceding siblings ...)
  2019-10-18 22:10   ` [PATCH v2 10/15] t5520: use test_cmp_rev " Denton Liu
@ 2019-10-18 22:10   ` Denton Liu
  2019-10-18 22:10   ` [PATCH v2 13/15] t5520: replace subshell cat comparison with test_cmp Denton Liu
                     ` (4 subsequent siblings)
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

Before, if the invocation of git failed, it would be masked by the pipe
since only the return code of the last element of a pipe is used.
Rewrite the test to put the Git command on its own line so its return
code is not masked.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 8b7e7ae55d..8ddf89e550 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -668,7 +668,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 	(
 		cd corrupt &&
 		test_commit one &&
-		obj=$(git rev-parse --verify HEAD | sed "s#^..#&/#") &&
+		git rev-parse --verify HEAD >head &&
+		obj=$(sed "s#^..#&/#" head) &&
 		rm -f .git/objects/$obj &&
 		test_must_fail git pull --rebase
 	)
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 13/15] t5520: replace subshell cat comparison with test_cmp
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (11 preceding siblings ...)
  2019-10-18 22:10   ` [PATCH v2 12/15] t5520: don't put git in upstream of pipe Denton Liu
@ 2019-10-18 22:10   ` Denton Liu
  2019-10-18 22:10   ` [PATCH v2 14/15] t5520: remove redundant lines in test cases Denton Liu
                     ` (3 subsequent siblings)
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

We currently have many instances of `test <line> = $(cat <file>)` and
`test $(cat <file>) = <line>`.  In the case where this fails, it will be
difficult for a developer to debug since the output will be masked.
Replace these instances with invocations of test_cmp().

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^=]*\)= "$(cat \([^)]*\))"/\1echo \2>expect \&\&\n\1test_cmp expect \3/
	s/\(\s*\)test "$(cat \([^)]*\))" = \([^&]*\)\( &&\)\?$/\1echo \3 >expect \&\&\n\1test_cmp expect \2\4/

A future patch will clean up situations where we have multiple duplicate
statements within a test case. This is done to keep this patch purely
mechanical.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 105 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 70 insertions(+), 35 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 8ddf89e550..c9e4eec004 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -15,8 +15,10 @@ test_pull_autostash () {
 	git add new_file &&
 	git pull "$@" . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test "$(cat new_file)" = dirty &&
-	test "$(cat file)" = "modified again"
+	echo dirty >expect &&
+	test_cmp expect new_file &&
+	echo "modified again" >expect &&
+	test_cmp expect file
 }
 
 test_pull_autostash_fail () {
@@ -110,9 +112,11 @@ test_expect_success 'test . as a remote' '
 	echo updated >file &&
 	git commit -a -m updated &&
 	git checkout copy &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull &&
-	test "$(cat file)" = updated &&
+	echo updated >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
@@ -125,9 +129,11 @@ test_expect_success 'the default remote . should not break explicit pull' '
 	git commit -a -m modified &&
 	git checkout copy &&
 	git reset --hard HEAD^ &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
@@ -137,10 +143,12 @@ test_expect_success 'the default remote . should not break explicit pull' '
 test_expect_success 'fail if wildcard spec does not match any refs' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 	test_i18ngrep "no candidates for merging" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no branches specified with non-default remote' '
@@ -148,11 +156,13 @@ test_expect_success 'fail if no branches specified with non-default remote' '
 	test_when_finished "git remote remove test_remote" &&
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_config branch.test.remote origin &&
 	test_must_fail git pull test_remote 2>err &&
 	test_i18ngrep "specify a branch on the command line" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if not on a branch' '
@@ -160,10 +170,12 @@ test_expect_success 'fail if not on a branch' '
 	test_when_finished "git remote remove origin" &&
 	git checkout HEAD^ &&
 	test_when_finished "git checkout -f copy" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "not currently on a branch" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no configuration for current branch' '
@@ -172,10 +184,12 @@ test_expect_success 'fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'pull --all: fail if no configuration for current branch' '
@@ -184,10 +198,12 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull --all 2>err &&
 	test_i18ngrep "There is no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if upstream branch does not exist' '
@@ -195,16 +211,19 @@ test_expect_success 'fail if upstream branch does not exist' '
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote . &&
 	test_config branch.test.merge refs/heads/nonexisting &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no such ref was fetched" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if the index has unresolved entries' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_commit modified2 file &&
 	git ls-files -u >unmerged &&
 	test_must_be_empty unmerged &&
@@ -226,21 +245,25 @@ test_expect_success 'fail if the index has unresolved entries' '
 test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	echo conflict >file &&
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
-	test "$(cat file)" = conflict &&
+	echo conflict >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
@@ -501,7 +524,8 @@ test_expect_success 'pull.rebase=interactive' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=interactive . copy &&
-	test "I was here" = "$(cat fake.out)"
+	echo "I was here" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull --rebase=i' '
@@ -512,7 +536,8 @@ test_expect_success 'pull --rebase=i' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=i . copy &&
-	test "I was here, too" = "$(cat fake.out)"
+	echo "I was here, too" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull.rebase=invalid fails' '
@@ -578,16 +603,20 @@ test_expect_success '--rebase with rebased upstream' '
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
 	test_when_finished "test_might_fail git rebase --abort" &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase -f me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase with rebased default upstream' '
@@ -595,8 +624,10 @@ test_expect_success '--rebase with rebased default upstream' '
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -607,8 +638,10 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 	git reset --hard to-rebase-orig &&
 	git fetch &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 
 '
 
@@ -744,8 +777,10 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 test_expect_success 'git pull --rebase against local branch' '
 	git checkout -b copy2 to-rebase-orig &&
 	git pull --rebase . to-rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_done
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 14/15] t5520: remove redundant lines in test cases
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (12 preceding siblings ...)
  2019-10-18 22:10   ` [PATCH v2 13/15] t5520: replace subshell cat comparison with test_cmp Denton Liu
@ 2019-10-18 22:10   ` Denton Liu
  2019-10-18 22:10   ` [PATCH v2 15/15] t5520: replace `! git` with `test_must_fail git` Denton Liu
                     ` (2 subsequent siblings)
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

In the previous patches, the mechanical application of changes left some
duplicate statements in the test case which were not strictly incorrect
but were redundant and possibly misleading. Remove these duplicate
statements so that it is clear that the intent behind the tests are that
the content of the file stays the same throughout the whole test case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index c9e4eec004..ef3dbc201a 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -147,7 +147,6 @@ test_expect_success 'fail if wildcard spec does not match any refs' '
 	test_cmp expect file &&
 	test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 	test_i18ngrep "no candidates for merging" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -161,7 +160,6 @@ test_expect_success 'fail if no branches specified with non-default remote' '
 	test_config branch.test.remote origin &&
 	test_must_fail git pull test_remote 2>err &&
 	test_i18ngrep "specify a branch on the command line" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -174,7 +172,6 @@ test_expect_success 'fail if not on a branch' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "not currently on a branch" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -188,7 +185,6 @@ test_expect_success 'fail if no configuration for current branch' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no tracking information" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -202,7 +198,6 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
 	test_cmp expect file &&
 	test_must_fail git pull --all 2>err &&
 	test_i18ngrep "There is no tracking information" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -215,7 +210,6 @@ test_expect_success 'fail if upstream branch does not exist' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no such ref was fetched" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -685,10 +679,8 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
 		git ls-files >actual &&
 		test_cmp expect actual &&
 		test_must_fail git pull --rebase .. master 2>err &&
-		echo staged-file >expect &&
 		git ls-files >actual &&
 		test_cmp expect actual &&
-		echo staged-file >expect &&
 		git show :staged-file >actual &&
 		test_cmp expect actual &&
 		test_i18ngrep "unborn branch with changes added to the index" err
-- 
2.23.0.897.g0a19638b1e


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

* [PATCH v2 15/15] t5520: replace `! git` with `test_must_fail git`
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (13 preceding siblings ...)
  2019-10-18 22:10   ` [PATCH v2 14/15] t5520: remove redundant lines in test cases Denton Liu
@ 2019-10-18 22:10   ` Denton Liu
  2019-10-18 22:14   ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:10 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

Currently, if a Git command fails in an unexpected way, such as a
segfault, it will be masked and ignored. Replace the ! with
test_must_fail so that only expected failures pass.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index ef3dbc201a..602d996a33 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -537,7 +537,7 @@ test_expect_success 'pull --rebase=i' '
 test_expect_success 'pull.rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase invalid &&
-	! git pull . copy
+	test_must_fail git pull . copy
 '
 
 test_expect_success '--rebase=false create a new merge commit' '
@@ -572,7 +572,7 @@ test_expect_success REBASE_P \
 
 test_expect_success '--rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
-	! git pull --rebase=invalid . copy
+	test_must_fail git pull --rebase=invalid . copy
 '
 
 test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
-- 
2.23.0.897.g0a19638b1e


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

* Re: [PATCH v2 00/15] t5520: various test cleanup
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (14 preceding siblings ...)
  2019-10-18 22:10   ` [PATCH v2 15/15] t5520: replace `! git` with `test_must_fail git` Denton Liu
@ 2019-10-18 22:14   ` Denton Liu
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
  16 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-18 22:14 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine

Sorry for the double-send. public-inbox and MARC both showed that
only 3 messages got through the in the first send so I sent it again.
Seems to have gotten through find the second time around.

On Fri, Oct 18, 2019 at 03:04:03PM -0700, Denton Liu wrote:
> Like earlier patchsets, I want to implement a feature that involves
> modifications to the test suite. Since that feature will probably take a
> while to polish up, however, let's clean up the test suite in a separate
> patchset first so it's not blocked by the feature work.
> 
> 1/15 is a cleanup to an unrelated test that I found while addressing
> some of Eric's comments.
> 
> 2/15 is a general improvement to test_rev_cmp() that will be used later
> in the series.
> 
> Changes since v1:
> 
> * Incorporate Eric's feedback
> 
> Denton Liu (15):
>   t7408: replace `test_must_fail test_path_is_file`
>   t: teach test_cmp_rev to accept ! for not-equals
>   t5520: improve test style
>   t5520: use sq for test case names
>   t5520: let sed open its own input
>   t5520: replace test -f with test-lib functions
>   t5520: remove spaces after redirect operator
>   t5520: use test_line_count where possible
>   t5520: replace test -{n,z} with test-lib functions
>   t5520: use test_cmp_rev where possible
>   t5520: test single-line files by git with test_cmp
>   t5520: don't put git in upstream of pipe
>   t5520: replace subshell cat comparison with test_cmp
>   t5520: remove redundant lines in test cases
>   t5520: replace `! git` with `test_must_fail git`
> 
>  t/t2400-worktree-add.sh             |   4 +-
>  t/t3400-rebase.sh                   |   2 +-
>  t/t3421-rebase-topology-linear.sh   |   6 +-
>  t/t3430-rebase-merges.sh            |   2 +-
>  t/t3432-rebase-fast-forward.sh      |   2 +-
>  t/t3501-revert-cherry-pick.sh       |   2 +-
>  t/t3508-cherry-pick-many-commits.sh |   2 +-
>  t/t5520-pull.sh                     | 343 +++++++++++++++++-----------
>  t/t7408-submodule-reference.sh      |   2 +-
>  t/test-lib-functions.sh             |  13 +-
>  10 files changed, 227 insertions(+), 151 deletions(-)
> 
> Range-diff against v1:
>  -:  ---------- >  1:  987fee4652 t7408: replace `test_must_fail test_path_is_file`
>  -:  ---------- >  2:  417e808466 t: teach test_cmp_rev to accept ! for not-equals
>  1:  0bc54dd330 =  3:  0a56980857 t5520: improve test style
>  2:  a5dee82ecc =  4:  dfa89ba1cb t5520: use sq for test case names
>  3:  58cc2fcda3 =  5:  9fac3dff83 t5520: let sed open its own input
>  4:  d2946208d3 !  6:  c6ca45eb17 t5520: replace test -f with test_path_is_file
>     @@ Metadata
>      Author: Denton Liu <liu.denton@gmail.com>
>      
>       ## Commit message ##
>     -    t5520: replace test -f with test_path_is_file
>     +    t5520: replace test -f with test-lib functions
>      
>          Although `test -f` has the same functionality as test_path_is_file(), in
>          the case where test_path_is_file() fails, we get much better debugging
>     -    information. Replace `test -f` with test_path_is_file so that future
>     -    developers will have a better experience debugging these test cases.
>     +    information.
>     +
>     +    Replace `test -f` with test_path_is_file() so that future developers
>     +    will have a better experience debugging these test cases.
>     +
>     +    Also, in the case of `! test -f`, not only should that path not be a
>     +    file, it shouldn't exist at all so replace it with
>     +    test_path_is_missing().
>      
>          Signed-off-by: Denton Liu <liu.denton@gmail.com>
>      
>     @@ t/t5520-pull.sh: test_expect_success 'pulling into void must not create an octop
>       		cd cloned-octopus &&
>       		test_must_fail git pull .. master master &&
>      -		! test -f file
>     -+		test_must_fail test_path_is_file file
>     ++		test_path_is_missing file
>       	)
>       '
>       
>  5:  5b4c1dd291 =  7:  830a8212ae t5520: remove spaces after redirect operator
>  6:  26fea15950 =  8:  3d982230be t5520: use test_line_count where possible
>  7:  3fc0354c9c !  9:  2bca4f046d t5520: replace test -{n,z} with test-lib functions
>     @@ Metadata
>       ## Commit message ##
>          t5520: replace test -{n,z} with test-lib functions
>      
>     +    When wrapping a Git command in a subshell within another command, we
>     +    throw away the Git command's exit code. In case the Git command fails,
>     +    we would like to know about it rather than the failure being silent.
>     +    Extract Git commands so that their exit codes are not lost.
>     +
>          Instead of using `test -n` or `test -z`, replace them respectively with
>     -    invocations of test_file_not_empty() and test_must_be_empty().
>     +    invocations of test_file_not_empty() and test_must_be_empty() so that we
>     +    get better debugging information in the case of a failure.
>      
>          Signed-off-by: Denton Liu <liu.denton@gmail.com>
>      
>  8:  f4eb80c9ac ! 10:  1a54db1d5c t5520: use test_cmp_rev where possible
>     @@ Commit message
>      
>                  s/test "$(git rev-parse.* \([^)]*\))" = "$(git rev-parse \([^)]*\))"/test_cmp_rev \1 \2/
>                  s/test \([^ ]*\) = "$(git rev-parse.* \([^)]*\))"/test_cmp_rev \1 \2/
>     -            s/test "$(git rev-parse.* \([^)]*\))" != "$(git rev-parse.* \([^)]*\))"/test_must_fail test_cmp_rev \1 \2/
>     -            s/test \([^ ]*\) != "$(git rev-parse.* \([^)]*\))"/test_must_fail test_cmp_rev \1 \2/
>     +            s/test "$(git rev-parse.* \([^)]*\))" != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/
>     +            s/test \([^ ]*\) != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/
>      
>          Signed-off-by: Denton Liu <liu.denton@gmail.com>
>      
>     @@ t/t5520-pull.sh: test_expect_success 'branch.to-rebase.rebase should override pu
>       	test_config branch.to-rebase.rebase false &&
>       	git pull . copy &&
>      -	test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
>     -+	test_must_fail test_cmp_rev HEAD^ copy &&
>     ++	test_cmp_rev ! HEAD^ copy &&
>       	test new = "$(git show HEAD:file2)"
>       '
>       
>     @@ t/t5520-pull.sh: test_expect_success 'pull --rebase dies early with dirty workin
>       	git checkout HEAD -- file &&
>       	git pull &&
>      -	test "$COPY" != "$(git rev-parse --verify me/copy)"
>     -+	test_must_fail test_cmp_rev "$COPY" me/copy
>     ++	test_cmp_rev ! "$COPY" me/copy
>       '
>       
>       test_expect_success 'pull --rebase works on branch yet to be born' '
>  9:  bd3ec4239c ! 11:  52cf4f0d0f t5520: test single-line files by git with test_cmp
>     @@ Commit message
>                  s/\(\s*\)test \([^ ]*\) = "$(\(git [^)]*\))"/\1echo \2 >expect \&\&\n\1\3 >actual \&\&\n\1test_cmp expect actual/
>                  s/\(\s*\)test "$(\(git [^)]*\))" = \([^ ]*\)/\1echo \3 >expect \&\&\n\1\2 >actual \&\&\n\1test_cmp expect actual/
>      
>     +    A future patch will clean up situations where we have multiple duplicate
>     +    statements within a test case. This is done to keep this patch purely
>     +    mechanical.
>     +
>          Signed-off-by: Denton Liu <liu.denton@gmail.com>
>      
>       ## t/t5520-pull.sh ##
>     @@ t/t5520-pull.sh: test_expect_success 'branch.to-rebase.rebase' '
>      @@ t/t5520-pull.sh: test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
>       	test_config branch.to-rebase.rebase false &&
>       	git pull . copy &&
>     - 	test_must_fail test_cmp_rev HEAD^ copy &&
>     + 	test_cmp_rev ! HEAD^ copy &&
>      -	test new = "$(git show HEAD:file2)"
>      +	echo new >expect &&
>      +	git show HEAD:file2 >actual &&
> 10:  61b4df0f7c = 12:  0cfabb201c t5520: don't put git in upstream of pipe
> 11:  f3429bbb57 ! 13:  b2d0ce21c8 t5520: replace subshell cat comparison with test_cmp
>     @@ Commit message
>                  s/\(\s*\)test \([^=]*\)= "$(cat \([^)]*\))"/\1echo \2>expect \&\&\n\1test_cmp expect \3/
>                  s/\(\s*\)test "$(cat \([^)]*\))" = \([^&]*\)\( &&\)\?$/\1echo \3 >expect \&\&\n\1test_cmp expect \2\4/
>      
>     +    A future patch will clean up situations where we have multiple duplicate
>     +    statements within a test case. This is done to keep this patch purely
>     +    mechanical.
>     +
>          Signed-off-by: Denton Liu <liu.denton@gmail.com>
>      
>       ## t/t5520-pull.sh ##
>  -:  ---------- > 14:  5aac40a029 t5520: remove redundant lines in test cases
> 12:  3e6c591b2b = 15:  2c0d3ac416 t5520: replace `! git` with `test_must_fail git`
> -- 
> 2.23.0.897.g0a19638b1e
> 

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

* Re: [PATCH v2 02/15] t: teach test_cmp_rev to accept ! for not-equals
  2019-10-18 22:10   ` [PATCH v2 02/15] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
@ 2019-10-18 22:45     ` SZEDER Gábor
  0 siblings, 0 replies; 116+ messages in thread
From: SZEDER Gábor @ 2019-10-18 22:45 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine

On Fri, Oct 18, 2019 at 03:10:21PM -0700, Denton Liu wrote:
> Currently, in the case where we are using test_cmp_rev() to report
> not-equals, we write `! test_cmp_rev`. However, since test_cmp_rev()
> contains
> 
> 	r1=$(git rev-parse --verify "$1") &&
> 	r2=$(git rev-parse --verify "$2") &&
> 
> In the case where `git rev-parse` segfaults and dies unexpectedly, the
> failure will be ignored.
> 
> Rewrite test_cmp_rev() to optionally accept "!" as the first argument to
> do a not-equals comparison. Rewrite `! test_cmp_rev` to `test_cmp_rev !`
> in all tests to take advantage of this new functionality.
> 
> Signed-off-by: Denton Liu <liu.denton@gmail.com>


> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index b299ecc326..76dce5f8ee 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -1012,8 +1012,17 @@ test_must_be_empty () {
>  	fi
>  }
>  
> -# Tests that its two parameters refer to the same revision
> +# Tests that its two parameters refer to the same revision, or if '!' is
> +# provided first, that its other two parameters refer to different
> +# revisions.
>  test_cmp_rev () {
> +	local inverted_op
> +	inverted_op='!='
> +	if test $# -ge 1 && test "x$1" = 'x!'
> +	then
> +	    inverted_op='='
> +	    shift
> +	fi
>  	if test $# != 2
>  	then
>  		error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
> @@ -1021,7 +1030,7 @@ test_cmp_rev () {
>  		local r1 r2
>  		r1=$(git rev-parse --verify "$1") &&
>  		r2=$(git rev-parse --verify "$2") &&
> -		if test "$r1" != "$r2"
> +		if test "$r1" "$inverted_op" "$r2"
>  		then
>  			cat >&4 <<-EOF
>  			error: two revisions point to different objects:

A semi-rhetorical question: how will the output of 'test_cmp_rev ! HEAD
HEAD' look like? :)


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

* Re: [PATCH v2 01/15] t7408: replace `test_must_fail test_path_is_file`
  2019-10-18 22:04   ` [PATCH v2 01/15] t7408: replace `test_must_fail test_path_is_file` Denton Liu
@ 2019-10-19 11:58     ` Johannes Sixt
  0 siblings, 0 replies; 116+ messages in thread
From: Johannes Sixt @ 2019-10-19 11:58 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine

Am 19.10.19 um 00:04 schrieb Denton Liu:
> diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh
> index 34ac28c056..9e62d43cac 100755
> --- a/t/t7408-submodule-reference.sh
> +++ b/t/t7408-submodule-reference.sh
> @@ -123,7 +123,7 @@ test_expect_success 'missing submodule alternate fails clone and submodule updat
>  		test_must_fail git submodule update --init &&
>  		# and we have no alternates:
>  		test_must_fail test_alternate_is_used .git/modules/sub/objects/info/alternates sub &&

Here's another incorrect use of test_must_fail (not the only instance in
this file). Looks like we would need a "test_alternate_is_not_used" helper.

> -		test_must_fail test_path_is_file sub/file1
> +		test_path_is_missing sub/file1
>  	)
>  '

I suggest to drop this patch; it doesn't fit the theme of this series,
and if you attempt to do it right, you'll quickly find a deep rabbit hole.

-- Hannes

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

* [PATCH v3 00/14] t5520: various test cleanup
  2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
                     ` (15 preceding siblings ...)
  2019-10-18 22:14   ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
@ 2019-10-22 10:19   ` Denton Liu
  2019-10-22 10:19     ` [PATCH v3 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
                       ` (15 more replies)
  16 siblings, 16 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:19 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

Like earlier patchsets, I want to implement a feature that involves
modifications to the test suite. Since that feature will probably take a
while to polish up, however, let's clean up the test suite in a separate
patchset first so it's not blocked by the feature work.

1/15 is a general improvement to test_rev_cmp() that will be used later
in the series.

Changes since v2:

* Drop 't7408: replace `test_must_fail test_path_is_file`' since it's
  not a rabbit hole we want to go into right now

* Fix the output of `test_cmp_rev !` when revs are actually equal

* Rebase against the latest master since this topic hasn't been picked
  up yet

Changes since v1:

* Incorporate Eric's feedback

Denton Liu (14):
  t: teach test_cmp_rev to accept ! for not-equals
  t5520: improve test style
  t5520: use sq for test case names
  t5520: let sed open its own input
  t5520: replace test -f with test-lib functions
  t5520: remove spaces after redirect operator
  t5520: use test_line_count where possible
  t5520: replace test -{n,z} with test-lib functions
  t5520: use test_cmp_rev where possible
  t5520: test single-line files by git with test_cmp
  t5520: don't put git in upstream of pipe
  t5520: replace subshell cat comparison with test_cmp
  t5520: remove redundant lines in test cases
  t5520: replace `! git` with `test_must_fail git`

 t/t2400-worktree-add.sh             |   4 +-
 t/t3400-rebase.sh                   |   2 +-
 t/t3421-rebase-topology-linear.sh   |   6 +-
 t/t3430-rebase-merges.sh            |   2 +-
 t/t3432-rebase-fast-forward.sh      |   2 +-
 t/t3501-revert-cherry-pick.sh       |   2 +-
 t/t3508-cherry-pick-many-commits.sh |   2 +-
 t/t5520-pull.sh                     | 343 +++++++++++++++++-----------
 t/test-lib-functions.sh             |  22 +-
 9 files changed, 234 insertions(+), 151 deletions(-)

Range-diff against v2:
 1:  987fee4652 <  -:  ---------- t7408: replace `test_must_fail test_path_is_file`
 2:  417e808466 !  1:  9a96f113e7 t: teach test_cmp_rev to accept ! for not-equals
    @@ t/test-lib-functions.sh: test_cmp_rev () {
     -		if test "$r1" != "$r2"
     +		if test "$r1" "$inverted_op" "$r2"
      		then
    ++			local comp_out
    ++			if "x$inverted_op" = 'x='
    ++			then
    ++				comp_out='the same'
    ++			else
    ++				comp_out='different'
    ++			fi
      			cat >&4 <<-EOF
    - 			error: two revisions point to different objects:
    +-			error: two revisions point to different objects:
    ++			error: two revisions point to $comp_out objects:
    + 			  '$1': $r1
    + 			  '$2': $r2
    + 			EOF
 3:  0a56980857 =  2:  dfc86a8d9b t5520: improve test style
 4:  dfa89ba1cb =  3:  a1071038f5 t5520: use sq for test case names
 5:  9fac3dff83 =  4:  0af3f5027b t5520: let sed open its own input
 6:  c6ca45eb17 =  5:  b696ff0a67 t5520: replace test -f with test-lib functions
 7:  830a8212ae =  6:  d2e49fd990 t5520: remove spaces after redirect operator
 8:  3d982230be =  7:  fcfc3226f8 t5520: use test_line_count where possible
 9:  2bca4f046d =  8:  86dafc7b54 t5520: replace test -{n,z} with test-lib functions
10:  1a54db1d5c =  9:  bf9b5023a3 t5520: use test_cmp_rev where possible
11:  52cf4f0d0f = 10:  bfabf8ceff t5520: test single-line files by git with test_cmp
12:  0cfabb201c = 11:  56bcbf3047 t5520: don't put git in upstream of pipe
13:  b2d0ce21c8 = 12:  e9d50b8bb0 t5520: replace subshell cat comparison with test_cmp
14:  5aac40a029 = 13:  9db0fc2156 t5520: remove redundant lines in test cases
15:  2c0d3ac416 = 14:  a721d5f119 t5520: replace `! git` with `test_must_fail git`
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 01/14] t: teach test_cmp_rev to accept ! for not-equals
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
@ 2019-10-22 10:19     ` Denton Liu
  2019-10-22 10:19     ` [PATCH v3 02/14] t5520: improve test style Denton Liu
                       ` (14 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:19 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

Currently, in the case where we are using test_cmp_rev() to report
not-equals, we write `! test_cmp_rev`. However, since test_cmp_rev()
contains

	r1=$(git rev-parse --verify "$1") &&
	r2=$(git rev-parse --verify "$2") &&

In the case where `git rev-parse` segfaults and dies unexpectedly, the
failure will be ignored.

Rewrite test_cmp_rev() to optionally accept "!" as the first argument to
do a not-equals comparison. Rewrite `! test_cmp_rev` to `test_cmp_rev !`
in all tests to take advantage of this new functionality.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t2400-worktree-add.sh             |  4 ++--
 t/t3400-rebase.sh                   |  2 +-
 t/t3421-rebase-topology-linear.sh   |  6 +++---
 t/t3430-rebase-merges.sh            |  2 +-
 t/t3432-rebase-fast-forward.sh      |  2 +-
 t/t3501-revert-cherry-pick.sh       |  2 +-
 t/t3508-cherry-pick-many-commits.sh |  2 +-
 t/test-lib-functions.sh             | 22 +++++++++++++++++++---
 8 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index e819ba741e..52d476979b 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -438,7 +438,7 @@ test_expect_success 'git worktree add does not match remote' '
 		cd foo &&
 		test_must_fail git config "branch.foo.remote" &&
 		test_must_fail git config "branch.foo.merge" &&
-		! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
+		test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
 	)
 '
 
@@ -483,7 +483,7 @@ test_expect_success 'git worktree --no-guess-remote option overrides config' '
 		cd foo &&
 		test_must_fail git config "branch.foo.remote" &&
 		test_must_fail git config "branch.foo.merge" &&
-		! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
+		test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
 	)
 '
 
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index ab18ac5f28..f267f6cd54 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -64,7 +64,7 @@ test_expect_success 'rebase sets ORIG_HEAD to pre-rebase state' '
 	pre="$(git rev-parse --verify HEAD)" &&
 	git rebase master &&
 	test_cmp_rev "$pre" ORIG_HEAD &&
-	! test_cmp_rev "$pre" HEAD
+	test_cmp_rev ! "$pre" HEAD
 '
 
 test_expect_success 'rebase, with <onto> and <upstream> specified as :/quuxery' '
diff --git a/t/t3421-rebase-topology-linear.sh b/t/t3421-rebase-topology-linear.sh
index b847064f91..325072b0a3 100755
--- a/t/t3421-rebase-topology-linear.sh
+++ b/t/t3421-rebase-topology-linear.sh
@@ -61,7 +61,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" "
 		reset_rebase &&
 		git rebase $* -f b e &&
-		! test_cmp_rev e HEAD &&
+		test_cmp_rev ! e HEAD &&
 		test_cmp_rev b HEAD~2 &&
 		test_linear_range 'd e' b..
 	"
@@ -78,7 +78,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
 		reset_rebase &&
 		git rebase $* -f branch-b branch-e &&
-		! test_cmp_rev branch-e origin/branch-e &&
+		test_cmp_rev ! branch-e origin/branch-e &&
 		test_cmp_rev branch-b HEAD~2 &&
 		test_linear_range 'd e' branch-b..
 	"
@@ -368,7 +368,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f --root on linear history causes re-write" "
 		reset_rebase &&
 		git rebase $* -f --root c &&
-		! test_cmp_rev a HEAD~2 &&
+		test_cmp_rev ! a HEAD~2 &&
 		test_linear_range 'a b c' HEAD
 	"
 }
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index 9efcf4808a..abbdc26b1b 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -346,7 +346,7 @@ test_expect_success 'A root commit can be a cousin, treat it that way' '
 	git merge --allow-unrelated-histories khnum &&
 	test_tick &&
 	git rebase -f -r HEAD^ &&
-	! test_cmp_rev HEAD^2 khnum &&
+	test_cmp_rev ! HEAD^2 khnum &&
 	test_cmp_graph HEAD^.. <<-\EOF &&
 	*   Merge branch '\''khnum'\'' into asherah
 	|\
diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh
index 034ffc7e76..92f95b57da 100755
--- a/t/t3432-rebase-fast-forward.sh
+++ b/t/t3432-rebase-fast-forward.sh
@@ -64,7 +64,7 @@ test_rebase_same_head_ () {
 			test_cmp_rev \$oldhead \$newhead
 		elif test $cmp = diff
 		then
-			! test_cmp_rev \$oldhead \$newhead
+			test_cmp_rev ! \$oldhead \$newhead
 		fi
 	"
 }
diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh
index d1c68af8c5..1c51a9131d 100755
--- a/t/t3501-revert-cherry-pick.sh
+++ b/t/t3501-revert-cherry-pick.sh
@@ -106,7 +106,7 @@ test_expect_success 'cherry-pick on unborn branch' '
 	rm -rf * &&
 	git cherry-pick initial &&
 	git diff --quiet initial &&
-	! test_cmp_rev initial HEAD
+	test_cmp_rev ! initial HEAD
 '
 
 test_expect_success 'cherry-pick "-" to pick from previous branch' '
diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh
index b457333e18..23070a7b73 100755
--- a/t/t3508-cherry-pick-many-commits.sh
+++ b/t/t3508-cherry-pick-many-commits.sh
@@ -5,7 +5,7 @@ test_description='test cherry-picking many commits'
 . ./test-lib.sh
 
 check_head_differs_from() {
-	! test_cmp_rev HEAD "$1"
+	test_cmp_rev ! HEAD "$1"
 }
 
 check_head_equals() {
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b299ecc326..064131ac39 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1012,8 +1012,17 @@ test_must_be_empty () {
 	fi
 }
 
-# Tests that its two parameters refer to the same revision
+# Tests that its two parameters refer to the same revision, or if '!' is
+# provided first, that its other two parameters refer to different
+# revisions.
 test_cmp_rev () {
+	local inverted_op
+	inverted_op='!='
+	if test $# -ge 1 && test "x$1" = 'x!'
+	then
+	    inverted_op='='
+	    shift
+	fi
 	if test $# != 2
 	then
 		error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
@@ -1021,10 +1030,17 @@ test_cmp_rev () {
 		local r1 r2
 		r1=$(git rev-parse --verify "$1") &&
 		r2=$(git rev-parse --verify "$2") &&
-		if test "$r1" != "$r2"
+		if test "$r1" "$inverted_op" "$r2"
 		then
+			local comp_out
+			if "x$inverted_op" = 'x='
+			then
+				comp_out='the same'
+			else
+				comp_out='different'
+			fi
 			cat >&4 <<-EOF
-			error: two revisions point to different objects:
+			error: two revisions point to $comp_out objects:
 			  '$1': $r1
 			  '$2': $r2
 			EOF
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 02/14] t5520: improve test style
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
  2019-10-22 10:19     ` [PATCH v3 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
@ 2019-10-22 10:19     ` Denton Liu
  2019-10-22 10:19     ` [PATCH v3 03/14] t5520: use sq for test case names Denton Liu
                       ` (13 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:19 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

Improve the test style by removing leading and trailing empty lines
within test cases. Also, reformat multi-line subshells to conform to the
existing style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 88 +++++++++++++++++++++++++------------------------
 1 file changed, 45 insertions(+), 43 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index cf4cc32fd0..51d6ce8aec 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -538,7 +538,6 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 '
 
 test_expect_success '--rebase with rebased upstream' '
-
 	git remote add -f me . &&
 	git checkout copy &&
 	git tag copy-orig &&
@@ -552,7 +551,6 @@ test_expect_success '--rebase with rebased upstream' '
 	git pull --rebase me copy &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = "$(cat file2)"
-
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
@@ -564,14 +562,12 @@ test_expect_success '--rebase -f with rebased upstream' '
 '
 
 test_expect_success '--rebase with rebased default upstream' '
-
 	git update-ref refs/remotes/me/copy copy-orig &&
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = "$(cat file2)"
-
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -588,7 +584,6 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 '
 
 test_expect_success 'pull --rebase dies early with dirty working directory' '
-
 	git checkout to-rebase &&
 	git update-ref refs/remotes/me/copy copy^ &&
 	COPY="$(git rev-parse --verify me/copy)" &&
@@ -603,16 +598,16 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	git checkout HEAD -- file &&
 	git pull &&
 	test "$COPY" != "$(git rev-parse --verify me/copy)"
-
 '
 
 test_expect_success 'pull --rebase works on branch yet to be born' '
 	git rev-parse master >expect &&
 	mkdir empty_repo &&
-	(cd empty_repo &&
-	 git init &&
-	 git pull --rebase .. master &&
-	 git rev-parse HEAD >../actual
+	(
+		cd empty_repo &&
+		git init &&
+		git pull --rebase .. master &&
+		git rev-parse HEAD >../actual
 	) &&
 	test_cmp expect actual
 '
@@ -646,58 +641,65 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 
 test_expect_success 'setup for detecting upstreamed changes' '
 	mkdir src &&
-	(cd src &&
-	 git init &&
-	 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
-	 git add stuff &&
-	 git commit -m "Initial revision"
+	(
+		cd src &&
+		git init &&
+		printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
+		git add stuff &&
+		git commit -m "Initial revision"
 	) &&
 	git clone src dst &&
-	(cd src &&
-	 modify s/5/43/ stuff &&
-	 git commit -a -m "5->43" &&
-	 modify s/6/42/ stuff &&
-	 git commit -a -m "Make it bigger"
+	(
+		cd src &&
+		modify s/5/43/ stuff &&
+		git commit -a -m "5->43" &&
+		modify s/6/42/ stuff &&
+		git commit -a -m "Make it bigger"
 	) &&
-	(cd dst &&
-	 modify s/5/43/ stuff &&
-	 git commit -a -m "Independent discovery of 5->43"
+	(
+		cd dst &&
+		modify s/5/43/ stuff &&
+		git commit -a -m "Independent discovery of 5->43"
 	)
 '
 
 test_expect_success 'git pull --rebase detects upstreamed changes' '
-	(cd dst &&
-	 git pull --rebase &&
-	 test -z "$(git ls-files -u)"
+	(
+		cd dst &&
+		git pull --rebase &&
+		test -z "$(git ls-files -u)"
 	)
 '
 
 test_expect_success 'setup for avoiding reapplying old patches' '
-	(cd dst &&
-	 test_might_fail git rebase --abort &&
-	 git reset --hard origin/master
+	(
+		cd dst &&
+		test_might_fail git rebase --abort &&
+		git reset --hard origin/master
 	) &&
 	git clone --bare src src-replace.git &&
 	rm -rf src &&
 	mv src-replace.git src &&
-	(cd dst &&
-	 modify s/2/22/ stuff &&
-	 git commit -a -m "Change 2" &&
-	 modify s/3/33/ stuff &&
-	 git commit -a -m "Change 3" &&
-	 modify s/4/44/ stuff &&
-	 git commit -a -m "Change 4" &&
-	 git push &&
-
-	 modify s/44/55/ stuff &&
-	 git commit --amend -a -m "Modified Change 4"
+	(
+		cd dst &&
+		modify s/2/22/ stuff &&
+		git commit -a -m "Change 2" &&
+		modify s/3/33/ stuff &&
+		git commit -a -m "Change 3" &&
+		modify s/4/44/ stuff &&
+		git commit -a -m "Change 4" &&
+		git push &&
+
+		modify s/44/55/ stuff &&
+		git commit --amend -a -m "Modified Change 4"
 	)
 '
 
 test_expect_success 'git pull --rebase does not reapply old patches' '
-	(cd dst &&
-	 test_must_fail git pull --rebase &&
-	 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+	(
+		cd dst &&
+		test_must_fail git pull --rebase &&
+		test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
 	)
 '
 
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 03/14] t5520: use sq for test case names
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
  2019-10-22 10:19     ` [PATCH v3 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
  2019-10-22 10:19     ` [PATCH v3 02/14] t5520: improve test style Denton Liu
@ 2019-10-22 10:19     ` Denton Liu
  2019-10-22 10:20     ` [PATCH v3 04/14] t5520: let sed open its own input Denton Liu
                       ` (12 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:19 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

The usual convention is for test case names to be written between
single-quotes. Change all double-quoted test case names to single-quotes
except for two test case names that use variables within.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 51d6ce8aec..a3de2e19b6 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -408,7 +408,7 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test new = "$(git show HEAD:file2)"
 '
 
-test_expect_success "pull --rebase warns on --verify-signatures" '
+test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
 	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
@@ -416,7 +416,7 @@ test_expect_success "pull --rebase warns on --verify-signatures" '
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
 
-test_expect_success "pull --rebase does not warn on --no-verify-signatures" '
+test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
 	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 04/14] t5520: let sed open its own input
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (2 preceding siblings ...)
  2019-10-22 10:19     ` [PATCH v3 03/14] t5520: use sq for test case names Denton Liu
@ 2019-10-22 10:20     ` Denton Liu
  2019-10-22 10:20     ` [PATCH v3 05/14] t5520: replace test -f with test-lib functions Denton Liu
                       ` (11 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:20 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

We were using a redirection operator to feed input into sed. However,
since sed is capable of opening its own files, make sed open its own
files instead of redirecting input into it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a3de2e19b6..55560ce3cd 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -5,7 +5,7 @@ test_description='pulling into void'
 . ./test-lib.sh
 
 modify () {
-	sed -e "$1" <"$2" >"$2.x" &&
+	sed -e "$1" "$2" >"$2.x" &&
 	mv "$2.x" "$2"
 }
 
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 05/14] t5520: replace test -f with test-lib functions
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (3 preceding siblings ...)
  2019-10-22 10:20     ` [PATCH v3 04/14] t5520: let sed open its own input Denton Liu
@ 2019-10-22 10:20     ` Denton Liu
  2019-10-22 10:20     ` [PATCH v3 06/14] t5520: remove spaces after redirect operator Denton Liu
                       ` (10 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:20 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

Although `test -f` has the same functionality as test_path_is_file(), in
the case where test_path_is_file() fails, we get much better debugging
information.

Replace `test -f` with test_path_is_file() so that future developers
will have a better experience debugging these test cases.

Also, in the case of `! test -f`, not only should that path not be a
file, it shouldn't exist at all so replace it with
test_path_is_missing().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 55560ce3cd..004d5884cd 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -39,8 +39,8 @@ test_expect_success 'pulling into void' '
 		cd cloned &&
 		git pull ..
 	) &&
-	test -f file &&
-	test -f cloned/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned/file &&
 	test_cmp file cloned/file
 '
 
@@ -50,8 +50,8 @@ test_expect_success 'pulling into void using master:master' '
 		cd cloned-uho &&
 		git pull .. master:master
 	) &&
-	test -f file &&
-	test -f cloned-uho/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned-uho/file &&
 	test_cmp file cloned-uho/file
 '
 
@@ -99,7 +99,7 @@ test_expect_success 'pulling into void must not create an octopus' '
 	(
 		cd cloned-octopus &&
 		test_must_fail git pull .. master master &&
-		! test -f file
+		test_path_is_missing file
 	)
 '
 
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 06/14] t5520: remove spaces after redirect operator
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (4 preceding siblings ...)
  2019-10-22 10:20     ` [PATCH v3 05/14] t5520: replace test -f with test-lib functions Denton Liu
@ 2019-10-22 10:20     ` Denton Liu
  2019-10-22 10:20     ` [PATCH v3 07/14] t5520: use test_line_count where possible Denton Liu
                       ` (9 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:20 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

The style for tests in Git is to have the redirect operator attached to
the filename with no spaces. Fix test cases where this is not the case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 004d5884cd..7bb9031140 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -243,10 +243,10 @@ test_expect_success 'fast-forward fails with conflicting work tree' '
 
 test_expect_success '--rebase' '
 	git branch to-rebase &&
-	echo modified again > file &&
+	echo modified again >file &&
 	git commit -m file file &&
 	git checkout to-rebase &&
-	echo new > file2 &&
+	echo new >file2 &&
 	git add file2 &&
 	git commit -m "new file" &&
 	git tag before-rebase &&
@@ -542,10 +542,10 @@ test_expect_success '--rebase with rebased upstream' '
 	git checkout copy &&
 	git tag copy-orig &&
 	git reset --hard HEAD^ &&
-	echo conflicting modification > file &&
+	echo conflicting modification >file &&
 	git commit -m conflict file &&
 	git checkout to-rebase &&
-	echo file > file2 &&
+	echo file >file2 &&
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
@@ -591,7 +591,7 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	test_config branch.to-rebase.remote me &&
 	test_config branch.to-rebase.merge refs/heads/copy &&
 	test_config branch.to-rebase.rebase true &&
-	echo dirty >> file &&
+	echo dirty >>file &&
 	git add file &&
 	test_must_fail git pull &&
 	test "$COPY" = "$(git rev-parse --verify me/copy)" &&
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 07/14] t5520: use test_line_count where possible
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (5 preceding siblings ...)
  2019-10-22 10:20     ` [PATCH v3 06/14] t5520: remove spaces after redirect operator Denton Liu
@ 2019-10-22 10:20     ` Denton Liu
  2019-10-22 10:20     ` [PATCH v3 08/14] t5520: replace test -{n,z} with test-lib functions Denton Liu
                       ` (8 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:20 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

Instead of rolling our own functionality to test the number of lines a
command outputs, use test_line_count() which provides better debugging
information in the case of a failure.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 7bb9031140..0ca4867e96 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -699,7 +699,8 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 	(
 		cd dst &&
 		test_must_fail git pull --rebase &&
-		test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+		find .git/rebase-apply -name "000*" >patches &&
+		test_line_count = 1 patches
 	)
 '
 
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 08/14] t5520: replace test -{n,z} with test-lib functions
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (6 preceding siblings ...)
  2019-10-22 10:20     ` [PATCH v3 07/14] t5520: use test_line_count where possible Denton Liu
@ 2019-10-22 10:20     ` Denton Liu
  2019-10-22 10:20     ` [PATCH v3 09/14] t5520: use test_cmp_rev where possible Denton Liu
                       ` (7 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:20 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

When wrapping a Git command in a subshell within another command, we
throw away the Git command's exit code. In case the Git command fails,
we would like to know about it rather than the failure being silent.
Extract Git commands so that their exit codes are not lost.

Instead of using `test -n` or `test -z`, replace them respectively with
invocations of test_file_not_empty() and test_must_be_empty() so that we
get better debugging information in the case of a failure.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 0ca4867e96..18225d8430 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -206,15 +206,18 @@ test_expect_success 'fail if the index has unresolved entries' '
 	test_when_finished "git checkout -f copy && git branch -D third" &&
 	test "$(cat file)" = file &&
 	test_commit modified2 file &&
-	test -z "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_must_be_empty unmerged &&
 	test_must_fail git pull . second &&
-	test -n "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_file_not_empty unmerged &&
 	cp file expected &&
 	test_must_fail git pull . second 2>err &&
 	test_i18ngrep "Pulling is not possible because you have unmerged files." err &&
 	test_cmp expected file &&
 	git add file &&
-	test -z "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_must_be_empty unmerged &&
 	test_must_fail git pull . second 2>err &&
 	test_i18ngrep "You have not concluded your merge" err &&
 	test_cmp expected file
@@ -667,7 +670,8 @@ test_expect_success 'git pull --rebase detects upstreamed changes' '
 	(
 		cd dst &&
 		git pull --rebase &&
-		test -z "$(git ls-files -u)"
+		git ls-files -u >untracked &&
+		test_must_be_empty untracked
 	)
 '
 
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 09/14] t5520: use test_cmp_rev where possible
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (7 preceding siblings ...)
  2019-10-22 10:20     ` [PATCH v3 08/14] t5520: replace test -{n,z} with test-lib functions Denton Liu
@ 2019-10-22 10:20     ` Denton Liu
  2019-10-22 10:20     ` [PATCH v3 10/14] t5520: test single-line files by git with test_cmp Denton Liu
                       ` (6 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:20 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

In case an invocation of `git rev-list` fails within the subshell, the
failure will be masked. Remove the subshell and use test_cmp_rev() so
that failures can be discovered.

This change was done with the following sed expressions:

	s/test "$(git rev-parse.* \([^)]*\))" = "$(git rev-parse \([^)]*\))"/test_cmp_rev \1 \2/
	s/test \([^ ]*\) = "$(git rev-parse.* \([^)]*\))"/test_cmp_rev \1 \2/
	s/test "$(git rev-parse.* \([^)]*\))" != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/
	s/test \([^ ]*\) != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 50 ++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 18225d8430..1af6ea06ee 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -230,7 +230,7 @@ test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
 	test "$(cat file)" = modified &&
-	test "$(git rev-parse third)" = "$(git rev-parse second)"
+	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
@@ -241,7 +241,7 @@ test_expect_success 'fast-forward fails with conflicting work tree' '
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
 	test "$(cat file)" = conflict &&
-	test "$(git rev-parse third)" = "$(git rev-parse second)"
+	test_cmp_rev third second
 '
 
 test_expect_success '--rebase' '
@@ -254,7 +254,7 @@ test_expect_success '--rebase' '
 	git commit -m "new file" &&
 	git tag before-rebase &&
 	git pull --rebase . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -266,7 +266,7 @@ test_expect_success '--rebase fast forward' '
 
 	git checkout to-rebase &&
 	git pull --rebase . ff &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse ff)" &&
+	test_cmp_rev HEAD ff &&
 
 	# The above only validates the result.  Did we actually bypass rebase?
 	git reflog -1 >reflog.actual &&
@@ -290,7 +290,7 @@ test_expect_success '--rebase --autostash fast forward' '
 	git checkout behind &&
 	echo dirty >file &&
 	git pull --rebase --autostash . to-rebase-ff &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse to-rebase-ff)"
+	test_cmp_rev HEAD to-rebase-ff
 '
 
 test_expect_success '--rebase with conflicts shows advice' '
@@ -328,7 +328,7 @@ test_expect_success 'failed --rebase shows advice' '
 test_expect_success '--rebase fails with multiple branches' '
 	git reset --hard before-rebase &&
 	test_must_fail git pull --rebase . copy master 2>err &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse before-rebase)" &&
+	test_cmp_rev HEAD before-rebase &&
 	test_i18ngrep "Cannot rebase onto multiple branches" err &&
 	test modified = "$(git show HEAD:file)"
 '
@@ -380,7 +380,7 @@ test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -398,7 +398,7 @@ test_expect_success 'branch.to-rebase.rebase' '
 	git reset --hard before-rebase &&
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -407,14 +407,14 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_config pull.rebase true &&
 	test_config branch.to-rebase.rebase false &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
+	test_cmp_rev ! HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)" &&
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
@@ -422,7 +422,7 @@ test_expect_success 'pull --rebase warns on --verify-signatures' '
 test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)" &&
 	test_i18ngrep ! "verify-signatures" err
 '
@@ -443,8 +443,8 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase false &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^1 before-preserve-rebase &&
+	test_cmp_rev HEAD^2 copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -452,7 +452,7 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -460,7 +460,7 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase 1 &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -469,8 +469,8 @@ test_expect_success REBASE_P \
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
+	test_cmp_rev HEAD^^ copy &&
+	test_cmp_rev HEAD^2 keep-merge
 '
 
 test_expect_success 'pull.rebase=interactive' '
@@ -505,8 +505,8 @@ test_expect_success '--rebase=false create a new merge commit' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull --rebase=false . copy &&
-	test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^1 before-preserve-rebase &&
+	test_cmp_rev HEAD^2 copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -514,7 +514,7 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull --rebase=true . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -523,8 +523,8 @@ test_expect_success REBASE_P \
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull --rebase=preserve . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
+	test_cmp_rev HEAD^^ copy &&
+	test_cmp_rev HEAD^2 keep-merge
 '
 
 test_expect_success '--rebase=invalid fails' '
@@ -536,7 +536,7 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull --rebase . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -597,10 +597,10 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	echo dirty >>file &&
 	git add file &&
 	test_must_fail git pull &&
-	test "$COPY" = "$(git rev-parse --verify me/copy)" &&
+	test_cmp_rev "$COPY" me/copy &&
 	git checkout HEAD -- file &&
 	git pull &&
-	test "$COPY" != "$(git rev-parse --verify me/copy)"
+	test_cmp_rev ! "$COPY" me/copy
 '
 
 test_expect_success 'pull --rebase works on branch yet to be born' '
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 10/14] t5520: test single-line files by git with test_cmp
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (8 preceding siblings ...)
  2019-10-22 10:20     ` [PATCH v3 09/14] t5520: use test_cmp_rev where possible Denton Liu
@ 2019-10-22 10:20     ` Denton Liu
  2019-10-22 10:20     ` [PATCH v3 11/14] t5520: don't put git in upstream of pipe Denton Liu
                       ` (5 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:20 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

In case an invocation of a Git command fails within the subshell, the
failure will be masked. Replace the subshell with a file-redirection and
a call to test_cmp.

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^ ]*\) = "$(\(git [^)]*\))"/\1echo \2 >expect \&\&\n\1\3 >actual \&\&\n\1test_cmp expect actual/
	s/\(\s*\)test "$(\(git [^)]*\))" = \([^ ]*\)/\1echo \3 >expect \&\&\n\1\2 >actual \&\&\n\1test_cmp expect actual/

A future patch will clean up situations where we have multiple duplicate
statements within a test case. This is done to keep this patch purely
mechanical.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 64 ++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 16 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 1af6ea06ee..8b7e7ae55d 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -255,7 +255,9 @@ test_expect_success '--rebase' '
 	git tag before-rebase &&
 	git pull --rebase . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase fast forward' '
@@ -330,7 +332,9 @@ test_expect_success '--rebase fails with multiple branches' '
 	test_must_fail git pull --rebase . copy master 2>err &&
 	test_cmp_rev HEAD before-rebase &&
 	test_i18ngrep "Cannot rebase onto multiple branches" err &&
-	test modified = "$(git show HEAD:file)"
+	echo modified >expect &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
@@ -381,7 +385,9 @@ test_expect_success 'pull.rebase' '
 	test_config pull.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --autostash & pull.rebase=true' '
@@ -399,7 +405,9 @@ test_expect_success 'branch.to-rebase.rebase' '
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
@@ -408,14 +416,18 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_config branch.to-rebase.rebase false &&
 	git pull . copy &&
 	test_cmp_rev ! HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)" &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual &&
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
 
@@ -423,7 +435,9 @@ test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)" &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual &&
 	test_i18ngrep ! "verify-signatures" err
 '
 
@@ -445,7 +459,9 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	git pull . copy &&
 	test_cmp_rev HEAD^1 before-preserve-rebase &&
 	test_cmp_rev HEAD^2 copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull.rebase=true flattens keep-merge' '
@@ -453,7 +469,9 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
 	test_config pull.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
@@ -461,7 +479,9 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	test_config pull.rebase 1 &&
 	git pull . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success REBASE_P \
@@ -507,7 +527,9 @@ test_expect_success '--rebase=false create a new merge commit' '
 	git pull --rebase=false . copy &&
 	test_cmp_rev HEAD^1 before-preserve-rebase &&
 	test_cmp_rev HEAD^2 copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase=true rebases and flattens keep-merge' '
@@ -515,7 +537,9 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
 	test_config pull.rebase preserve &&
 	git pull --rebase=true . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success REBASE_P \
@@ -537,7 +561,9 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 	test_config pull.rebase preserve &&
 	git pull --rebase . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase with rebased upstream' '
@@ -622,10 +648,16 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
 		cd empty_repo2 &&
 		echo staged-file >staged-file &&
 		git add staged-file &&
-		test "$(git ls-files)" = staged-file &&
+		echo staged-file >expect &&
+		git ls-files >actual &&
+		test_cmp expect actual &&
 		test_must_fail git pull --rebase .. master 2>err &&
-		test "$(git ls-files)" = staged-file &&
-		test "$(git show :staged-file)" = staged-file &&
+		echo staged-file >expect &&
+		git ls-files >actual &&
+		test_cmp expect actual &&
+		echo staged-file >expect &&
+		git show :staged-file >actual &&
+		test_cmp expect actual &&
 		test_i18ngrep "unborn branch with changes added to the index" err
 	)
 '
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 11/14] t5520: don't put git in upstream of pipe
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (9 preceding siblings ...)
  2019-10-22 10:20     ` [PATCH v3 10/14] t5520: test single-line files by git with test_cmp Denton Liu
@ 2019-10-22 10:20     ` Denton Liu
  2019-10-22 10:20     ` [PATCH v3 12/14] t5520: replace subshell cat comparison with test_cmp Denton Liu
                       ` (4 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:20 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

Before, if the invocation of git failed, it would be masked by the pipe
since only the return code of the last element of a pipe is used.
Rewrite the test to put the Git command on its own line so its return
code is not masked.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 8b7e7ae55d..8ddf89e550 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -668,7 +668,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 	(
 		cd corrupt &&
 		test_commit one &&
-		obj=$(git rev-parse --verify HEAD | sed "s#^..#&/#") &&
+		git rev-parse --verify HEAD >head &&
+		obj=$(sed "s#^..#&/#" head) &&
 		rm -f .git/objects/$obj &&
 		test_must_fail git pull --rebase
 	)
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 12/14] t5520: replace subshell cat comparison with test_cmp
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (10 preceding siblings ...)
  2019-10-22 10:20     ` [PATCH v3 11/14] t5520: don't put git in upstream of pipe Denton Liu
@ 2019-10-22 10:20     ` Denton Liu
  2019-10-22 10:20     ` [PATCH v3 13/14] t5520: remove redundant lines in test cases Denton Liu
                       ` (3 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:20 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

We currently have many instances of `test <line> = $(cat <file>)` and
`test $(cat <file>) = <line>`.  In the case where this fails, it will be
difficult for a developer to debug since the output will be masked.
Replace these instances with invocations of test_cmp().

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^=]*\)= "$(cat \([^)]*\))"/\1echo \2>expect \&\&\n\1test_cmp expect \3/
	s/\(\s*\)test "$(cat \([^)]*\))" = \([^&]*\)\( &&\)\?$/\1echo \3 >expect \&\&\n\1test_cmp expect \2\4/

A future patch will clean up situations where we have multiple duplicate
statements within a test case. This is done to keep this patch purely
mechanical.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 105 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 70 insertions(+), 35 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 8ddf89e550..c9e4eec004 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -15,8 +15,10 @@ test_pull_autostash () {
 	git add new_file &&
 	git pull "$@" . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test "$(cat new_file)" = dirty &&
-	test "$(cat file)" = "modified again"
+	echo dirty >expect &&
+	test_cmp expect new_file &&
+	echo "modified again" >expect &&
+	test_cmp expect file
 }
 
 test_pull_autostash_fail () {
@@ -110,9 +112,11 @@ test_expect_success 'test . as a remote' '
 	echo updated >file &&
 	git commit -a -m updated &&
 	git checkout copy &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull &&
-	test "$(cat file)" = updated &&
+	echo updated >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
@@ -125,9 +129,11 @@ test_expect_success 'the default remote . should not break explicit pull' '
 	git commit -a -m modified &&
 	git checkout copy &&
 	git reset --hard HEAD^ &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
@@ -137,10 +143,12 @@ test_expect_success 'the default remote . should not break explicit pull' '
 test_expect_success 'fail if wildcard spec does not match any refs' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 	test_i18ngrep "no candidates for merging" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no branches specified with non-default remote' '
@@ -148,11 +156,13 @@ test_expect_success 'fail if no branches specified with non-default remote' '
 	test_when_finished "git remote remove test_remote" &&
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_config branch.test.remote origin &&
 	test_must_fail git pull test_remote 2>err &&
 	test_i18ngrep "specify a branch on the command line" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if not on a branch' '
@@ -160,10 +170,12 @@ test_expect_success 'fail if not on a branch' '
 	test_when_finished "git remote remove origin" &&
 	git checkout HEAD^ &&
 	test_when_finished "git checkout -f copy" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "not currently on a branch" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no configuration for current branch' '
@@ -172,10 +184,12 @@ test_expect_success 'fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'pull --all: fail if no configuration for current branch' '
@@ -184,10 +198,12 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull --all 2>err &&
 	test_i18ngrep "There is no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if upstream branch does not exist' '
@@ -195,16 +211,19 @@ test_expect_success 'fail if upstream branch does not exist' '
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote . &&
 	test_config branch.test.merge refs/heads/nonexisting &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no such ref was fetched" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if the index has unresolved entries' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_commit modified2 file &&
 	git ls-files -u >unmerged &&
 	test_must_be_empty unmerged &&
@@ -226,21 +245,25 @@ test_expect_success 'fail if the index has unresolved entries' '
 test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	echo conflict >file &&
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
-	test "$(cat file)" = conflict &&
+	echo conflict >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
@@ -501,7 +524,8 @@ test_expect_success 'pull.rebase=interactive' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=interactive . copy &&
-	test "I was here" = "$(cat fake.out)"
+	echo "I was here" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull --rebase=i' '
@@ -512,7 +536,8 @@ test_expect_success 'pull --rebase=i' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=i . copy &&
-	test "I was here, too" = "$(cat fake.out)"
+	echo "I was here, too" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull.rebase=invalid fails' '
@@ -578,16 +603,20 @@ test_expect_success '--rebase with rebased upstream' '
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
 	test_when_finished "test_might_fail git rebase --abort" &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase -f me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase with rebased default upstream' '
@@ -595,8 +624,10 @@ test_expect_success '--rebase with rebased default upstream' '
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -607,8 +638,10 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 	git reset --hard to-rebase-orig &&
 	git fetch &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 
 '
 
@@ -744,8 +777,10 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 test_expect_success 'git pull --rebase against local branch' '
 	git checkout -b copy2 to-rebase-orig &&
 	git pull --rebase . to-rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_done
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 13/14] t5520: remove redundant lines in test cases
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (11 preceding siblings ...)
  2019-10-22 10:20     ` [PATCH v3 12/14] t5520: replace subshell cat comparison with test_cmp Denton Liu
@ 2019-10-22 10:20     ` Denton Liu
  2019-10-22 10:20     ` [PATCH v3 14/14] t5520: replace `! git` with `test_must_fail git` Denton Liu
                       ` (2 subsequent siblings)
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:20 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

In the previous patches, the mechanical application of changes left some
duplicate statements in the test case which were not strictly incorrect
but were redundant and possibly misleading. Remove these duplicate
statements so that it is clear that the intent behind the tests are that
the content of the file stays the same throughout the whole test case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index c9e4eec004..ef3dbc201a 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -147,7 +147,6 @@ test_expect_success 'fail if wildcard spec does not match any refs' '
 	test_cmp expect file &&
 	test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 	test_i18ngrep "no candidates for merging" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -161,7 +160,6 @@ test_expect_success 'fail if no branches specified with non-default remote' '
 	test_config branch.test.remote origin &&
 	test_must_fail git pull test_remote 2>err &&
 	test_i18ngrep "specify a branch on the command line" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -174,7 +172,6 @@ test_expect_success 'fail if not on a branch' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "not currently on a branch" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -188,7 +185,6 @@ test_expect_success 'fail if no configuration for current branch' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no tracking information" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -202,7 +198,6 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
 	test_cmp expect file &&
 	test_must_fail git pull --all 2>err &&
 	test_i18ngrep "There is no tracking information" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -215,7 +210,6 @@ test_expect_success 'fail if upstream branch does not exist' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no such ref was fetched" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -685,10 +679,8 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
 		git ls-files >actual &&
 		test_cmp expect actual &&
 		test_must_fail git pull --rebase .. master 2>err &&
-		echo staged-file >expect &&
 		git ls-files >actual &&
 		test_cmp expect actual &&
-		echo staged-file >expect &&
 		git show :staged-file >actual &&
 		test_cmp expect actual &&
 		test_i18ngrep "unborn branch with changes added to the index" err
-- 
2.24.0.rc0.197.g0926ab8072


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

* [PATCH v3 14/14] t5520: replace `! git` with `test_must_fail git`
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (12 preceding siblings ...)
  2019-10-22 10:20     ` [PATCH v3 13/14] t5520: remove redundant lines in test cases Denton Liu
@ 2019-10-22 10:20     ` Denton Liu
  2019-10-24 23:21     ` [PATCH v3 00/14] t5520: various test cleanup Denton Liu
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
  15 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-10-22 10:20 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor

Currently, if a Git command fails in an unexpected way, such as a
segfault, it will be masked and ignored. Replace the ! with
test_must_fail so that only expected failures pass.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index ef3dbc201a..602d996a33 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -537,7 +537,7 @@ test_expect_success 'pull --rebase=i' '
 test_expect_success 'pull.rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase invalid &&
-	! git pull . copy
+	test_must_fail git pull . copy
 '
 
 test_expect_success '--rebase=false create a new merge commit' '
@@ -572,7 +572,7 @@ test_expect_success REBASE_P \
 
 test_expect_success '--rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
-	! git pull --rebase=invalid . copy
+	test_must_fail git pull --rebase=invalid . copy
 '
 
 test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
-- 
2.24.0.rc0.197.g0926ab8072


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

* Re: [PATCH 08/12] t5520: use test_cmp_rev where possible
  2019-10-18 18:52     ` Denton Liu
@ 2019-10-23 13:53       ` Eric Sunshine
  0 siblings, 0 replies; 116+ messages in thread
From: Eric Sunshine @ 2019-10-23 13:53 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List

On Fri, Oct 18, 2019 at 2:52 PM Denton Liu <liu.denton@gmail.com> wrote:
> On Thu, Oct 17, 2019 at 07:41:44PM -0400, Eric Sunshine wrote:
> > On Thu, Oct 17, 2019 at 7:17 PM Denton Liu <liu.denton@gmail.com> wrote:
> > > -       test "$COPY" = "$(git rev-parse --verify me/copy)" &&
> > > +       test_cmp_rev "$COPY" me/copy &&
> >
> > This transformation doesn't look correct. COPY already holds the
> > result of a git-rev-parse invocation:
> >
> >     COPY="$(git rev-parse --verify me/copy)" &&
> >
> > so passing it to test_cmp_rev() -- which applies its own git-rev-parse
> > invocation -- doesn't make sense.
>
> So after grokking the test case, it seems like the the transformation is
> indeed correct. Maybe we can replace the last line with
>
>         test_cmp_rev copy me/copy
>
> but I think I'll leave it unless you have any strong opinions.

For some reason, I had it in my mind that test_cmp_rev() was primarily
meant for comparing _named_ revisions, but of course there is nothing
about the function which even suggests that that is its intended
use-case. In retrospect, using it to compare an OID against a named
revision is a sensible use-case too, so I withdraw the objection.

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

* Re: [PATCH v3 00/14] t5520: various test cleanup
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (13 preceding siblings ...)
  2019-10-22 10:20     ` [PATCH v3 14/14] t5520: replace `! git` with `test_must_fail git` Denton Liu
@ 2019-10-24 23:21     ` Denton Liu
  2019-10-25  3:44       ` Junio C Hamano
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
  15 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-10-24 23:21 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Git Mailing List

Hi Junio,

There haven't been any comments in a couple days so I think this
patchset is ready for inclusion.

Thanks,

Denton

On Tue, Oct 22, 2019 at 03:19:51AM -0700, Denton Liu wrote:
> Like earlier patchsets, I want to implement a feature that involves
> modifications to the test suite. Since that feature will probably take a
> while to polish up, however, let's clean up the test suite in a separate
> patchset first so it's not blocked by the feature work.
> 
> 1/15 is a general improvement to test_rev_cmp() that will be used later
> in the series.
> 
> Changes since v2:
> 
> * Drop 't7408: replace `test_must_fail test_path_is_file`' since it's
>   not a rabbit hole we want to go into right now
> 
> * Fix the output of `test_cmp_rev !` when revs are actually equal
> 
> * Rebase against the latest master since this topic hasn't been picked
>   up yet
> 
> Changes since v1:
> 
> * Incorporate Eric's feedback
> 
> Denton Liu (14):
>   t: teach test_cmp_rev to accept ! for not-equals
>   t5520: improve test style
>   t5520: use sq for test case names
>   t5520: let sed open its own input
>   t5520: replace test -f with test-lib functions
>   t5520: remove spaces after redirect operator
>   t5520: use test_line_count where possible
>   t5520: replace test -{n,z} with test-lib functions
>   t5520: use test_cmp_rev where possible
>   t5520: test single-line files by git with test_cmp
>   t5520: don't put git in upstream of pipe
>   t5520: replace subshell cat comparison with test_cmp
>   t5520: remove redundant lines in test cases
>   t5520: replace `! git` with `test_must_fail git`
> 
>  t/t2400-worktree-add.sh             |   4 +-
>  t/t3400-rebase.sh                   |   2 +-
>  t/t3421-rebase-topology-linear.sh   |   6 +-
>  t/t3430-rebase-merges.sh            |   2 +-
>  t/t3432-rebase-fast-forward.sh      |   2 +-
>  t/t3501-revert-cherry-pick.sh       |   2 +-
>  t/t3508-cherry-pick-many-commits.sh |   2 +-
>  t/t5520-pull.sh                     | 343 +++++++++++++++++-----------
>  t/test-lib-functions.sh             |  22 +-
>  9 files changed, 234 insertions(+), 151 deletions(-)
> 
> Range-diff against v2:
>  1:  987fee4652 <  -:  ---------- t7408: replace `test_must_fail test_path_is_file`
>  2:  417e808466 !  1:  9a96f113e7 t: teach test_cmp_rev to accept ! for not-equals
>     @@ t/test-lib-functions.sh: test_cmp_rev () {
>      -		if test "$r1" != "$r2"
>      +		if test "$r1" "$inverted_op" "$r2"
>       		then
>     ++			local comp_out
>     ++			if "x$inverted_op" = 'x='
>     ++			then
>     ++				comp_out='the same'
>     ++			else
>     ++				comp_out='different'
>     ++			fi
>       			cat >&4 <<-EOF
>     - 			error: two revisions point to different objects:
>     +-			error: two revisions point to different objects:
>     ++			error: two revisions point to $comp_out objects:
>     + 			  '$1': $r1
>     + 			  '$2': $r2
>     + 			EOF
>  3:  0a56980857 =  2:  dfc86a8d9b t5520: improve test style
>  4:  dfa89ba1cb =  3:  a1071038f5 t5520: use sq for test case names
>  5:  9fac3dff83 =  4:  0af3f5027b t5520: let sed open its own input
>  6:  c6ca45eb17 =  5:  b696ff0a67 t5520: replace test -f with test-lib functions
>  7:  830a8212ae =  6:  d2e49fd990 t5520: remove spaces after redirect operator
>  8:  3d982230be =  7:  fcfc3226f8 t5520: use test_line_count where possible
>  9:  2bca4f046d =  8:  86dafc7b54 t5520: replace test -{n,z} with test-lib functions
> 10:  1a54db1d5c =  9:  bf9b5023a3 t5520: use test_cmp_rev where possible
> 11:  52cf4f0d0f = 10:  bfabf8ceff t5520: test single-line files by git with test_cmp
> 12:  0cfabb201c = 11:  56bcbf3047 t5520: don't put git in upstream of pipe
> 13:  b2d0ce21c8 = 12:  e9d50b8bb0 t5520: replace subshell cat comparison with test_cmp
> 14:  5aac40a029 = 13:  9db0fc2156 t5520: remove redundant lines in test cases
> 15:  2c0d3ac416 = 14:  a721d5f119 t5520: replace `! git` with `test_must_fail git`
> -- 
> 2.24.0.rc0.197.g0926ab8072
> 

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

* Re: [PATCH v3 00/14] t5520: various test cleanup
  2019-10-24 23:21     ` [PATCH v3 00/14] t5520: various test cleanup Denton Liu
@ 2019-10-25  3:44       ` Junio C Hamano
  2019-11-04 19:17         ` Denton Liu
  0 siblings, 1 reply; 116+ messages in thread
From: Junio C Hamano @ 2019-10-25  3:44 UTC (permalink / raw)
  To: Denton Liu
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Git Mailing List

Denton Liu <liu.denton@gmail.com> writes:

> There haven't been any comments in a couple days so I think this
> patchset is ready for inclusion.

It's not like we are in a hurry that we need to fast-forward a topic
like this one (i.e. general improvement and clean-up, rather than
fixing regressions introduced in the cycle), so "a couple of days"
is probably being too impatient.

We'd prefer a positive ack or two.  

Thanks.

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

* Re: [PATCH v3 00/14] t5520: various test cleanup
  2019-10-25  3:44       ` Junio C Hamano
@ 2019-11-04 19:17         ` Denton Liu
  2019-11-06  2:37           ` Junio C Hamano
  0 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-11-04 19:17 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Git Mailing List

Hi Junio,

On Fri, Oct 25, 2019 at 12:44:52PM +0900, Junio C Hamano wrote:
> Denton Liu <liu.denton@gmail.com> writes:
> 
> > There haven't been any comments in a couple days so I think this
> > patchset is ready for inclusion.
> 
> It's not like we are in a hurry that we need to fast-forward a topic
> like this one (i.e. general improvement and clean-up, rather than
> fixing regressions introduced in the cycle), so "a couple of days"
> is probably being too impatient.

Since v2.24.0 has been released, would now be a good time to queue this
patchset?

Thanks,

Denton

> 
> We'd prefer a positive ack or two.  
> 
> Thanks.

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

* Re: [PATCH v3 00/14] t5520: various test cleanup
  2019-11-04 19:17         ` Denton Liu
@ 2019-11-06  2:37           ` Junio C Hamano
  0 siblings, 0 replies; 116+ messages in thread
From: Junio C Hamano @ 2019-11-06  2:37 UTC (permalink / raw)
  To: Denton Liu
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Git Mailing List

Denton Liu <liu.denton@gmail.com> writes:

> On Fri, Oct 25, 2019 at 12:44:52PM +0900, Junio C Hamano wrote:
>> Denton Liu <liu.denton@gmail.com> writes:
>> 
>> > There haven't been any comments in a couple days so I think this
>> > patchset is ready for inclusion.
>> 
>> It's not like we are in a hurry that we need to fast-forward a topic
>> like this one (i.e. general improvement and clean-up, rather than
>> fixing regressions introduced in the cycle), so "a couple of days"
>> is probably being too impatient.
>
> Since v2.24.0 has been released, would now be a good time to queue this
> patchset?

We'd prefer a positive ack or two.

Since they are rather ancient messages in Git timescale, perhaps
send a new version that is rebased (and retested) on top of 2.24
to ask for reviews?

Thanks.


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

* [PATCH v4 00/14] t5520: various test cleanup
  2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
                       ` (14 preceding siblings ...)
  2019-10-24 23:21     ` [PATCH v3 00/14] t5520: various test cleanup Denton Liu
@ 2019-11-07 18:51     ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
                         ` (14 more replies)
  15 siblings, 15 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Hi all, since this is general cleanup that shouldn't be too
controversial, I'm looking for some positive acks for this changeset.


Like earlier patchsets, I want to implement a feature that involves
modifications to the test suite. Since that feature will probably take a
while to polish up, however, let's clean up the test suite in a separate
patchset first so it's not blocked by the feature work.

1/15 is a general improvement to test_rev_cmp() that will be used later
in the series.

Changes since v3:

* Rebased and tested on top of v2.24.0

Changes since v2:

* Drop 't7408: replace `test_must_fail test_path_is_file`' since it's
  not a rabbit hole we want to go into right now

* Fix the output of `test_cmp_rev !` when revs are actually equal

* Rebase against the latest master since this topic hasn't been picked
  up yet

Changes since v1:

* Incorporate Eric's feedback

Denton Liu (14):
  t: teach test_cmp_rev to accept ! for not-equals
  t5520: improve test style
  t5520: use sq for test case names
  t5520: let sed open its own input
  t5520: replace test -f with test-lib functions
  t5520: remove spaces after redirect operator
  t5520: use test_line_count where possible
  t5520: replace test -{n,z} with test-lib functions
  t5520: use test_cmp_rev where possible
  t5520: test single-line files by git with test_cmp
  t5520: don't put git in upstream of pipe
  t5520: replace subshell cat comparison with test_cmp
  t5520: remove redundant lines in test cases
  t5520: replace `! git` with `test_must_fail git`

 t/t2400-worktree-add.sh             |   4 +-
 t/t3400-rebase.sh                   |   2 +-
 t/t3421-rebase-topology-linear.sh   |   6 +-
 t/t3430-rebase-merges.sh            |   2 +-
 t/t3432-rebase-fast-forward.sh      |   2 +-
 t/t3501-revert-cherry-pick.sh       |   2 +-
 t/t3508-cherry-pick-many-commits.sh |   2 +-
 t/t5520-pull.sh                     | 343 +++++++++++++++++-----------
 t/test-lib-functions.sh             |  22 +-
 9 files changed, 234 insertions(+), 151 deletions(-)

Range-diff against v3:
 1:  9a96f113e7 =  1:  0d0696f310 t: teach test_cmp_rev to accept ! for not-equals
 2:  dfc86a8d9b =  2:  b1dbe78f5d t5520: improve test style
 3:  a1071038f5 =  3:  ea06a1db3d t5520: use sq for test case names
 4:  0af3f5027b =  4:  d09b591250 t5520: let sed open its own input
 5:  b696ff0a67 =  5:  2af85e3913 t5520: replace test -f with test-lib functions
 6:  d2e49fd990 =  6:  280cfa0adc t5520: remove spaces after redirect operator
 7:  fcfc3226f8 =  7:  1e8ecb80a4 t5520: use test_line_count where possible
 8:  86dafc7b54 =  8:  f31142c683 t5520: replace test -{n,z} with test-lib functions
 9:  bf9b5023a3 =  9:  fdde875363 t5520: use test_cmp_rev where possible
10:  bfabf8ceff = 10:  6cb78bce40 t5520: test single-line files by git with test_cmp
11:  56bcbf3047 = 11:  acbfc39cb0 t5520: don't put git in upstream of pipe
12:  e9d50b8bb0 = 12:  bb529ad84a t5520: replace subshell cat comparison with test_cmp
13:  9db0fc2156 = 13:  d08e34b021 t5520: remove redundant lines in test cases
14:  a721d5f119 = 14:  70698bd902 t5520: replace `! git` with `test_must_fail git`
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 01/14] t: teach test_cmp_rev to accept ! for not-equals
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-08  3:24         ` Junio C Hamano
  2019-11-07 18:51       ` [PATCH v4 02/14] t5520: improve test style Denton Liu
                         ` (13 subsequent siblings)
  14 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Currently, in the case where we are using test_cmp_rev() to report
not-equals, we write `! test_cmp_rev`. However, since test_cmp_rev()
contains

	r1=$(git rev-parse --verify "$1") &&
	r2=$(git rev-parse --verify "$2") &&

In the case where `git rev-parse` segfaults and dies unexpectedly, the
failure will be ignored.

Rewrite test_cmp_rev() to optionally accept "!" as the first argument to
do a not-equals comparison. Rewrite `! test_cmp_rev` to `test_cmp_rev !`
in all tests to take advantage of this new functionality.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t2400-worktree-add.sh             |  4 ++--
 t/t3400-rebase.sh                   |  2 +-
 t/t3421-rebase-topology-linear.sh   |  6 +++---
 t/t3430-rebase-merges.sh            |  2 +-
 t/t3432-rebase-fast-forward.sh      |  2 +-
 t/t3501-revert-cherry-pick.sh       |  2 +-
 t/t3508-cherry-pick-many-commits.sh |  2 +-
 t/test-lib-functions.sh             | 22 +++++++++++++++++++---
 8 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index e819ba741e..52d476979b 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -438,7 +438,7 @@ test_expect_success 'git worktree add does not match remote' '
 		cd foo &&
 		test_must_fail git config "branch.foo.remote" &&
 		test_must_fail git config "branch.foo.merge" &&
-		! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
+		test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
 	)
 '
 
@@ -483,7 +483,7 @@ test_expect_success 'git worktree --no-guess-remote option overrides config' '
 		cd foo &&
 		test_must_fail git config "branch.foo.remote" &&
 		test_must_fail git config "branch.foo.merge" &&
-		! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
+		test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
 	)
 '
 
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index ab18ac5f28..f267f6cd54 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -64,7 +64,7 @@ test_expect_success 'rebase sets ORIG_HEAD to pre-rebase state' '
 	pre="$(git rev-parse --verify HEAD)" &&
 	git rebase master &&
 	test_cmp_rev "$pre" ORIG_HEAD &&
-	! test_cmp_rev "$pre" HEAD
+	test_cmp_rev ! "$pre" HEAD
 '
 
 test_expect_success 'rebase, with <onto> and <upstream> specified as :/quuxery' '
diff --git a/t/t3421-rebase-topology-linear.sh b/t/t3421-rebase-topology-linear.sh
index b847064f91..325072b0a3 100755
--- a/t/t3421-rebase-topology-linear.sh
+++ b/t/t3421-rebase-topology-linear.sh
@@ -61,7 +61,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" "
 		reset_rebase &&
 		git rebase $* -f b e &&
-		! test_cmp_rev e HEAD &&
+		test_cmp_rev ! e HEAD &&
 		test_cmp_rev b HEAD~2 &&
 		test_linear_range 'd e' b..
 	"
@@ -78,7 +78,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
 		reset_rebase &&
 		git rebase $* -f branch-b branch-e &&
-		! test_cmp_rev branch-e origin/branch-e &&
+		test_cmp_rev ! branch-e origin/branch-e &&
 		test_cmp_rev branch-b HEAD~2 &&
 		test_linear_range 'd e' branch-b..
 	"
@@ -368,7 +368,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f --root on linear history causes re-write" "
 		reset_rebase &&
 		git rebase $* -f --root c &&
-		! test_cmp_rev a HEAD~2 &&
+		test_cmp_rev ! a HEAD~2 &&
 		test_linear_range 'a b c' HEAD
 	"
 }
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index 9efcf4808a..abbdc26b1b 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -346,7 +346,7 @@ test_expect_success 'A root commit can be a cousin, treat it that way' '
 	git merge --allow-unrelated-histories khnum &&
 	test_tick &&
 	git rebase -f -r HEAD^ &&
-	! test_cmp_rev HEAD^2 khnum &&
+	test_cmp_rev ! HEAD^2 khnum &&
 	test_cmp_graph HEAD^.. <<-\EOF &&
 	*   Merge branch '\''khnum'\'' into asherah
 	|\
diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh
index 034ffc7e76..92f95b57da 100755
--- a/t/t3432-rebase-fast-forward.sh
+++ b/t/t3432-rebase-fast-forward.sh
@@ -64,7 +64,7 @@ test_rebase_same_head_ () {
 			test_cmp_rev \$oldhead \$newhead
 		elif test $cmp = diff
 		then
-			! test_cmp_rev \$oldhead \$newhead
+			test_cmp_rev ! \$oldhead \$newhead
 		fi
 	"
 }
diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh
index d1c68af8c5..1c51a9131d 100755
--- a/t/t3501-revert-cherry-pick.sh
+++ b/t/t3501-revert-cherry-pick.sh
@@ -106,7 +106,7 @@ test_expect_success 'cherry-pick on unborn branch' '
 	rm -rf * &&
 	git cherry-pick initial &&
 	git diff --quiet initial &&
-	! test_cmp_rev initial HEAD
+	test_cmp_rev ! initial HEAD
 '
 
 test_expect_success 'cherry-pick "-" to pick from previous branch' '
diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh
index b457333e18..23070a7b73 100755
--- a/t/t3508-cherry-pick-many-commits.sh
+++ b/t/t3508-cherry-pick-many-commits.sh
@@ -5,7 +5,7 @@ test_description='test cherry-picking many commits'
 . ./test-lib.sh
 
 check_head_differs_from() {
-	! test_cmp_rev HEAD "$1"
+	test_cmp_rev ! HEAD "$1"
 }
 
 check_head_equals() {
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b299ecc326..064131ac39 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1012,8 +1012,17 @@ test_must_be_empty () {
 	fi
 }
 
-# Tests that its two parameters refer to the same revision
+# Tests that its two parameters refer to the same revision, or if '!' is
+# provided first, that its other two parameters refer to different
+# revisions.
 test_cmp_rev () {
+	local inverted_op
+	inverted_op='!='
+	if test $# -ge 1 && test "x$1" = 'x!'
+	then
+	    inverted_op='='
+	    shift
+	fi
 	if test $# != 2
 	then
 		error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
@@ -1021,10 +1030,17 @@ test_cmp_rev () {
 		local r1 r2
 		r1=$(git rev-parse --verify "$1") &&
 		r2=$(git rev-parse --verify "$2") &&
-		if test "$r1" != "$r2"
+		if test "$r1" "$inverted_op" "$r2"
 		then
+			local comp_out
+			if "x$inverted_op" = 'x='
+			then
+				comp_out='the same'
+			else
+				comp_out='different'
+			fi
 			cat >&4 <<-EOF
-			error: two revisions point to different objects:
+			error: two revisions point to $comp_out objects:
 			  '$1': $r1
 			  '$2': $r2
 			EOF
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 02/14] t5520: improve test style
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
  2019-11-07 18:51       ` [PATCH v4 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 03/14] t5520: use sq for test case names Denton Liu
                         ` (12 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Improve the test style by removing leading and trailing empty lines
within test cases. Also, reformat multi-line subshells to conform to the
existing style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 88 +++++++++++++++++++++++++------------------------
 1 file changed, 45 insertions(+), 43 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index cf4cc32fd0..51d6ce8aec 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -538,7 +538,6 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 '
 
 test_expect_success '--rebase with rebased upstream' '
-
 	git remote add -f me . &&
 	git checkout copy &&
 	git tag copy-orig &&
@@ -552,7 +551,6 @@ test_expect_success '--rebase with rebased upstream' '
 	git pull --rebase me copy &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = "$(cat file2)"
-
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
@@ -564,14 +562,12 @@ test_expect_success '--rebase -f with rebased upstream' '
 '
 
 test_expect_success '--rebase with rebased default upstream' '
-
 	git update-ref refs/remotes/me/copy copy-orig &&
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = "$(cat file2)"
-
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -588,7 +584,6 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 '
 
 test_expect_success 'pull --rebase dies early with dirty working directory' '
-
 	git checkout to-rebase &&
 	git update-ref refs/remotes/me/copy copy^ &&
 	COPY="$(git rev-parse --verify me/copy)" &&
@@ -603,16 +598,16 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	git checkout HEAD -- file &&
 	git pull &&
 	test "$COPY" != "$(git rev-parse --verify me/copy)"
-
 '
 
 test_expect_success 'pull --rebase works on branch yet to be born' '
 	git rev-parse master >expect &&
 	mkdir empty_repo &&
-	(cd empty_repo &&
-	 git init &&
-	 git pull --rebase .. master &&
-	 git rev-parse HEAD >../actual
+	(
+		cd empty_repo &&
+		git init &&
+		git pull --rebase .. master &&
+		git rev-parse HEAD >../actual
 	) &&
 	test_cmp expect actual
 '
@@ -646,58 +641,65 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 
 test_expect_success 'setup for detecting upstreamed changes' '
 	mkdir src &&
-	(cd src &&
-	 git init &&
-	 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
-	 git add stuff &&
-	 git commit -m "Initial revision"
+	(
+		cd src &&
+		git init &&
+		printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
+		git add stuff &&
+		git commit -m "Initial revision"
 	) &&
 	git clone src dst &&
-	(cd src &&
-	 modify s/5/43/ stuff &&
-	 git commit -a -m "5->43" &&
-	 modify s/6/42/ stuff &&
-	 git commit -a -m "Make it bigger"
+	(
+		cd src &&
+		modify s/5/43/ stuff &&
+		git commit -a -m "5->43" &&
+		modify s/6/42/ stuff &&
+		git commit -a -m "Make it bigger"
 	) &&
-	(cd dst &&
-	 modify s/5/43/ stuff &&
-	 git commit -a -m "Independent discovery of 5->43"
+	(
+		cd dst &&
+		modify s/5/43/ stuff &&
+		git commit -a -m "Independent discovery of 5->43"
 	)
 '
 
 test_expect_success 'git pull --rebase detects upstreamed changes' '
-	(cd dst &&
-	 git pull --rebase &&
-	 test -z "$(git ls-files -u)"
+	(
+		cd dst &&
+		git pull --rebase &&
+		test -z "$(git ls-files -u)"
 	)
 '
 
 test_expect_success 'setup for avoiding reapplying old patches' '
-	(cd dst &&
-	 test_might_fail git rebase --abort &&
-	 git reset --hard origin/master
+	(
+		cd dst &&
+		test_might_fail git rebase --abort &&
+		git reset --hard origin/master
 	) &&
 	git clone --bare src src-replace.git &&
 	rm -rf src &&
 	mv src-replace.git src &&
-	(cd dst &&
-	 modify s/2/22/ stuff &&
-	 git commit -a -m "Change 2" &&
-	 modify s/3/33/ stuff &&
-	 git commit -a -m "Change 3" &&
-	 modify s/4/44/ stuff &&
-	 git commit -a -m "Change 4" &&
-	 git push &&
-
-	 modify s/44/55/ stuff &&
-	 git commit --amend -a -m "Modified Change 4"
+	(
+		cd dst &&
+		modify s/2/22/ stuff &&
+		git commit -a -m "Change 2" &&
+		modify s/3/33/ stuff &&
+		git commit -a -m "Change 3" &&
+		modify s/4/44/ stuff &&
+		git commit -a -m "Change 4" &&
+		git push &&
+
+		modify s/44/55/ stuff &&
+		git commit --amend -a -m "Modified Change 4"
 	)
 '
 
 test_expect_success 'git pull --rebase does not reapply old patches' '
-	(cd dst &&
-	 test_must_fail git pull --rebase &&
-	 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+	(
+		cd dst &&
+		test_must_fail git pull --rebase &&
+		test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
 	)
 '
 
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 03/14] t5520: use sq for test case names
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
  2019-11-07 18:51       ` [PATCH v4 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
  2019-11-07 18:51       ` [PATCH v4 02/14] t5520: improve test style Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 04/14] t5520: let sed open its own input Denton Liu
                         ` (11 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

The usual convention is for test case names to be written between
single-quotes. Change all double-quoted test case names to single-quotes
except for two test case names that use variables within.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 51d6ce8aec..a3de2e19b6 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -408,7 +408,7 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test new = "$(git show HEAD:file2)"
 '
 
-test_expect_success "pull --rebase warns on --verify-signatures" '
+test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
 	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
@@ -416,7 +416,7 @@ test_expect_success "pull --rebase warns on --verify-signatures" '
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
 
-test_expect_success "pull --rebase does not warn on --no-verify-signatures" '
+test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
 	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 04/14] t5520: let sed open its own input
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
                         ` (2 preceding siblings ...)
  2019-11-07 18:51       ` [PATCH v4 03/14] t5520: use sq for test case names Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 05/14] t5520: replace test -f with test-lib functions Denton Liu
                         ` (10 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

We were using a redirection operator to feed input into sed. However,
since sed is capable of opening its own files, make sed open its own
files instead of redirecting input into it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a3de2e19b6..55560ce3cd 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -5,7 +5,7 @@ test_description='pulling into void'
 . ./test-lib.sh
 
 modify () {
-	sed -e "$1" <"$2" >"$2.x" &&
+	sed -e "$1" "$2" >"$2.x" &&
 	mv "$2.x" "$2"
 }
 
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 05/14] t5520: replace test -f with test-lib functions
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
                         ` (3 preceding siblings ...)
  2019-11-07 18:51       ` [PATCH v4 04/14] t5520: let sed open its own input Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 06/14] t5520: remove spaces after redirect operator Denton Liu
                         ` (9 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Although `test -f` has the same functionality as test_path_is_file(), in
the case where test_path_is_file() fails, we get much better debugging
information.

Replace `test -f` with test_path_is_file() so that future developers
will have a better experience debugging these test cases.

Also, in the case of `! test -f`, not only should that path not be a
file, it shouldn't exist at all so replace it with
test_path_is_missing().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 55560ce3cd..004d5884cd 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -39,8 +39,8 @@ test_expect_success 'pulling into void' '
 		cd cloned &&
 		git pull ..
 	) &&
-	test -f file &&
-	test -f cloned/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned/file &&
 	test_cmp file cloned/file
 '
 
@@ -50,8 +50,8 @@ test_expect_success 'pulling into void using master:master' '
 		cd cloned-uho &&
 		git pull .. master:master
 	) &&
-	test -f file &&
-	test -f cloned-uho/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned-uho/file &&
 	test_cmp file cloned-uho/file
 '
 
@@ -99,7 +99,7 @@ test_expect_success 'pulling into void must not create an octopus' '
 	(
 		cd cloned-octopus &&
 		test_must_fail git pull .. master master &&
-		! test -f file
+		test_path_is_missing file
 	)
 '
 
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 06/14] t5520: remove spaces after redirect operator
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
                         ` (4 preceding siblings ...)
  2019-11-07 18:51       ` [PATCH v4 05/14] t5520: replace test -f with test-lib functions Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 07/14] t5520: use test_line_count where possible Denton Liu
                         ` (8 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

The style for tests in Git is to have the redirect operator attached to
the filename with no spaces. Fix test cases where this is not the case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 004d5884cd..7bb9031140 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -243,10 +243,10 @@ test_expect_success 'fast-forward fails with conflicting work tree' '
 
 test_expect_success '--rebase' '
 	git branch to-rebase &&
-	echo modified again > file &&
+	echo modified again >file &&
 	git commit -m file file &&
 	git checkout to-rebase &&
-	echo new > file2 &&
+	echo new >file2 &&
 	git add file2 &&
 	git commit -m "new file" &&
 	git tag before-rebase &&
@@ -542,10 +542,10 @@ test_expect_success '--rebase with rebased upstream' '
 	git checkout copy &&
 	git tag copy-orig &&
 	git reset --hard HEAD^ &&
-	echo conflicting modification > file &&
+	echo conflicting modification >file &&
 	git commit -m conflict file &&
 	git checkout to-rebase &&
-	echo file > file2 &&
+	echo file >file2 &&
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
@@ -591,7 +591,7 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	test_config branch.to-rebase.remote me &&
 	test_config branch.to-rebase.merge refs/heads/copy &&
 	test_config branch.to-rebase.rebase true &&
-	echo dirty >> file &&
+	echo dirty >>file &&
 	git add file &&
 	test_must_fail git pull &&
 	test "$COPY" = "$(git rev-parse --verify me/copy)" &&
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 07/14] t5520: use test_line_count where possible
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
                         ` (5 preceding siblings ...)
  2019-11-07 18:51       ` [PATCH v4 06/14] t5520: remove spaces after redirect operator Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 08/14] t5520: replace test -{n,z} with test-lib functions Denton Liu
                         ` (7 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Instead of rolling our own functionality to test the number of lines a
command outputs, use test_line_count() which provides better debugging
information in the case of a failure.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 7bb9031140..0ca4867e96 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -699,7 +699,8 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 	(
 		cd dst &&
 		test_must_fail git pull --rebase &&
-		test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+		find .git/rebase-apply -name "000*" >patches &&
+		test_line_count = 1 patches
 	)
 '
 
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 08/14] t5520: replace test -{n,z} with test-lib functions
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
                         ` (6 preceding siblings ...)
  2019-11-07 18:51       ` [PATCH v4 07/14] t5520: use test_line_count where possible Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 09/14] t5520: use test_cmp_rev where possible Denton Liu
                         ` (6 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

When wrapping a Git command in a subshell within another command, we
throw away the Git command's exit code. In case the Git command fails,
we would like to know about it rather than the failure being silent.
Extract Git commands so that their exit codes are not lost.

Instead of using `test -n` or `test -z`, replace them respectively with
invocations of test_file_not_empty() and test_must_be_empty() so that we
get better debugging information in the case of a failure.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 0ca4867e96..18225d8430 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -206,15 +206,18 @@ test_expect_success 'fail if the index has unresolved entries' '
 	test_when_finished "git checkout -f copy && git branch -D third" &&
 	test "$(cat file)" = file &&
 	test_commit modified2 file &&
-	test -z "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_must_be_empty unmerged &&
 	test_must_fail git pull . second &&
-	test -n "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_file_not_empty unmerged &&
 	cp file expected &&
 	test_must_fail git pull . second 2>err &&
 	test_i18ngrep "Pulling is not possible because you have unmerged files." err &&
 	test_cmp expected file &&
 	git add file &&
-	test -z "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_must_be_empty unmerged &&
 	test_must_fail git pull . second 2>err &&
 	test_i18ngrep "You have not concluded your merge" err &&
 	test_cmp expected file
@@ -667,7 +670,8 @@ test_expect_success 'git pull --rebase detects upstreamed changes' '
 	(
 		cd dst &&
 		git pull --rebase &&
-		test -z "$(git ls-files -u)"
+		git ls-files -u >untracked &&
+		test_must_be_empty untracked
 	)
 '
 
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 09/14] t5520: use test_cmp_rev where possible
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
                         ` (7 preceding siblings ...)
  2019-11-07 18:51       ` [PATCH v4 08/14] t5520: replace test -{n,z} with test-lib functions Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 10/14] t5520: test single-line files by git with test_cmp Denton Liu
                         ` (5 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

In case an invocation of `git rev-list` fails within the subshell, the
failure will be masked. Remove the subshell and use test_cmp_rev() so
that failures can be discovered.

This change was done with the following sed expressions:

	s/test "$(git rev-parse.* \([^)]*\))" = "$(git rev-parse \([^)]*\))"/test_cmp_rev \1 \2/
	s/test \([^ ]*\) = "$(git rev-parse.* \([^)]*\))"/test_cmp_rev \1 \2/
	s/test "$(git rev-parse.* \([^)]*\))" != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/
	s/test \([^ ]*\) != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 50 ++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 18225d8430..1af6ea06ee 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -230,7 +230,7 @@ test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
 	test "$(cat file)" = modified &&
-	test "$(git rev-parse third)" = "$(git rev-parse second)"
+	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
@@ -241,7 +241,7 @@ test_expect_success 'fast-forward fails with conflicting work tree' '
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
 	test "$(cat file)" = conflict &&
-	test "$(git rev-parse third)" = "$(git rev-parse second)"
+	test_cmp_rev third second
 '
 
 test_expect_success '--rebase' '
@@ -254,7 +254,7 @@ test_expect_success '--rebase' '
 	git commit -m "new file" &&
 	git tag before-rebase &&
 	git pull --rebase . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -266,7 +266,7 @@ test_expect_success '--rebase fast forward' '
 
 	git checkout to-rebase &&
 	git pull --rebase . ff &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse ff)" &&
+	test_cmp_rev HEAD ff &&
 
 	# The above only validates the result.  Did we actually bypass rebase?
 	git reflog -1 >reflog.actual &&
@@ -290,7 +290,7 @@ test_expect_success '--rebase --autostash fast forward' '
 	git checkout behind &&
 	echo dirty >file &&
 	git pull --rebase --autostash . to-rebase-ff &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse to-rebase-ff)"
+	test_cmp_rev HEAD to-rebase-ff
 '
 
 test_expect_success '--rebase with conflicts shows advice' '
@@ -328,7 +328,7 @@ test_expect_success 'failed --rebase shows advice' '
 test_expect_success '--rebase fails with multiple branches' '
 	git reset --hard before-rebase &&
 	test_must_fail git pull --rebase . copy master 2>err &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse before-rebase)" &&
+	test_cmp_rev HEAD before-rebase &&
 	test_i18ngrep "Cannot rebase onto multiple branches" err &&
 	test modified = "$(git show HEAD:file)"
 '
@@ -380,7 +380,7 @@ test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -398,7 +398,7 @@ test_expect_success 'branch.to-rebase.rebase' '
 	git reset --hard before-rebase &&
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -407,14 +407,14 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_config pull.rebase true &&
 	test_config branch.to-rebase.rebase false &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
+	test_cmp_rev ! HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)" &&
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
@@ -422,7 +422,7 @@ test_expect_success 'pull --rebase warns on --verify-signatures' '
 test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)" &&
 	test_i18ngrep ! "verify-signatures" err
 '
@@ -443,8 +443,8 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase false &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^1 before-preserve-rebase &&
+	test_cmp_rev HEAD^2 copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -452,7 +452,7 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -460,7 +460,7 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase 1 &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -469,8 +469,8 @@ test_expect_success REBASE_P \
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
+	test_cmp_rev HEAD^^ copy &&
+	test_cmp_rev HEAD^2 keep-merge
 '
 
 test_expect_success 'pull.rebase=interactive' '
@@ -505,8 +505,8 @@ test_expect_success '--rebase=false create a new merge commit' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull --rebase=false . copy &&
-	test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^1 before-preserve-rebase &&
+	test_cmp_rev HEAD^2 copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -514,7 +514,7 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull --rebase=true . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -523,8 +523,8 @@ test_expect_success REBASE_P \
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull --rebase=preserve . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
+	test_cmp_rev HEAD^^ copy &&
+	test_cmp_rev HEAD^2 keep-merge
 '
 
 test_expect_success '--rebase=invalid fails' '
@@ -536,7 +536,7 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull --rebase . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -597,10 +597,10 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	echo dirty >>file &&
 	git add file &&
 	test_must_fail git pull &&
-	test "$COPY" = "$(git rev-parse --verify me/copy)" &&
+	test_cmp_rev "$COPY" me/copy &&
 	git checkout HEAD -- file &&
 	git pull &&
-	test "$COPY" != "$(git rev-parse --verify me/copy)"
+	test_cmp_rev ! "$COPY" me/copy
 '
 
 test_expect_success 'pull --rebase works on branch yet to be born' '
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 10/14] t5520: test single-line files by git with test_cmp
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
                         ` (8 preceding siblings ...)
  2019-11-07 18:51       ` [PATCH v4 09/14] t5520: use test_cmp_rev where possible Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 11/14] t5520: don't put git in upstream of pipe Denton Liu
                         ` (4 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

In case an invocation of a Git command fails within the subshell, the
failure will be masked. Replace the subshell with a file-redirection and
a call to test_cmp.

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^ ]*\) = "$(\(git [^)]*\))"/\1echo \2 >expect \&\&\n\1\3 >actual \&\&\n\1test_cmp expect actual/
	s/\(\s*\)test "$(\(git [^)]*\))" = \([^ ]*\)/\1echo \3 >expect \&\&\n\1\2 >actual \&\&\n\1test_cmp expect actual/

A future patch will clean up situations where we have multiple duplicate
statements within a test case. This is done to keep this patch purely
mechanical.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 64 ++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 16 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 1af6ea06ee..8b7e7ae55d 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -255,7 +255,9 @@ test_expect_success '--rebase' '
 	git tag before-rebase &&
 	git pull --rebase . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase fast forward' '
@@ -330,7 +332,9 @@ test_expect_success '--rebase fails with multiple branches' '
 	test_must_fail git pull --rebase . copy master 2>err &&
 	test_cmp_rev HEAD before-rebase &&
 	test_i18ngrep "Cannot rebase onto multiple branches" err &&
-	test modified = "$(git show HEAD:file)"
+	echo modified >expect &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
@@ -381,7 +385,9 @@ test_expect_success 'pull.rebase' '
 	test_config pull.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --autostash & pull.rebase=true' '
@@ -399,7 +405,9 @@ test_expect_success 'branch.to-rebase.rebase' '
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
@@ -408,14 +416,18 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_config branch.to-rebase.rebase false &&
 	git pull . copy &&
 	test_cmp_rev ! HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)" &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual &&
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
 
@@ -423,7 +435,9 @@ test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)" &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual &&
 	test_i18ngrep ! "verify-signatures" err
 '
 
@@ -445,7 +459,9 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	git pull . copy &&
 	test_cmp_rev HEAD^1 before-preserve-rebase &&
 	test_cmp_rev HEAD^2 copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull.rebase=true flattens keep-merge' '
@@ -453,7 +469,9 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
 	test_config pull.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
@@ -461,7 +479,9 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	test_config pull.rebase 1 &&
 	git pull . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success REBASE_P \
@@ -507,7 +527,9 @@ test_expect_success '--rebase=false create a new merge commit' '
 	git pull --rebase=false . copy &&
 	test_cmp_rev HEAD^1 before-preserve-rebase &&
 	test_cmp_rev HEAD^2 copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase=true rebases and flattens keep-merge' '
@@ -515,7 +537,9 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
 	test_config pull.rebase preserve &&
 	git pull --rebase=true . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success REBASE_P \
@@ -537,7 +561,9 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 	test_config pull.rebase preserve &&
 	git pull --rebase . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase with rebased upstream' '
@@ -622,10 +648,16 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
 		cd empty_repo2 &&
 		echo staged-file >staged-file &&
 		git add staged-file &&
-		test "$(git ls-files)" = staged-file &&
+		echo staged-file >expect &&
+		git ls-files >actual &&
+		test_cmp expect actual &&
 		test_must_fail git pull --rebase .. master 2>err &&
-		test "$(git ls-files)" = staged-file &&
-		test "$(git show :staged-file)" = staged-file &&
+		echo staged-file >expect &&
+		git ls-files >actual &&
+		test_cmp expect actual &&
+		echo staged-file >expect &&
+		git show :staged-file >actual &&
+		test_cmp expect actual &&
 		test_i18ngrep "unborn branch with changes added to the index" err
 	)
 '
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 11/14] t5520: don't put git in upstream of pipe
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
                         ` (9 preceding siblings ...)
  2019-11-07 18:51       ` [PATCH v4 10/14] t5520: test single-line files by git with test_cmp Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 12/14] t5520: replace subshell cat comparison with test_cmp Denton Liu
                         ` (3 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Before, if the invocation of git failed, it would be masked by the pipe
since only the return code of the last element of a pipe is used.
Rewrite the test to put the Git command on its own line so its return
code is not masked.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 8b7e7ae55d..8ddf89e550 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -668,7 +668,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 	(
 		cd corrupt &&
 		test_commit one &&
-		obj=$(git rev-parse --verify HEAD | sed "s#^..#&/#") &&
+		git rev-parse --verify HEAD >head &&
+		obj=$(sed "s#^..#&/#" head) &&
 		rm -f .git/objects/$obj &&
 		test_must_fail git pull --rebase
 	)
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 12/14] t5520: replace subshell cat comparison with test_cmp
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
                         ` (10 preceding siblings ...)
  2019-11-07 18:51       ` [PATCH v4 11/14] t5520: don't put git in upstream of pipe Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 13/14] t5520: remove redundant lines in test cases Denton Liu
                         ` (2 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

We currently have many instances of `test <line> = $(cat <file>)` and
`test $(cat <file>) = <line>`.  In the case where this fails, it will be
difficult for a developer to debug since the output will be masked.
Replace these instances with invocations of test_cmp().

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^=]*\)= "$(cat \([^)]*\))"/\1echo \2>expect \&\&\n\1test_cmp expect \3/
	s/\(\s*\)test "$(cat \([^)]*\))" = \([^&]*\)\( &&\)\?$/\1echo \3 >expect \&\&\n\1test_cmp expect \2\4/

A future patch will clean up situations where we have multiple duplicate
statements within a test case. This is done to keep this patch purely
mechanical.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 105 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 70 insertions(+), 35 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 8ddf89e550..c9e4eec004 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -15,8 +15,10 @@ test_pull_autostash () {
 	git add new_file &&
 	git pull "$@" . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test "$(cat new_file)" = dirty &&
-	test "$(cat file)" = "modified again"
+	echo dirty >expect &&
+	test_cmp expect new_file &&
+	echo "modified again" >expect &&
+	test_cmp expect file
 }
 
 test_pull_autostash_fail () {
@@ -110,9 +112,11 @@ test_expect_success 'test . as a remote' '
 	echo updated >file &&
 	git commit -a -m updated &&
 	git checkout copy &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull &&
-	test "$(cat file)" = updated &&
+	echo updated >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
@@ -125,9 +129,11 @@ test_expect_success 'the default remote . should not break explicit pull' '
 	git commit -a -m modified &&
 	git checkout copy &&
 	git reset --hard HEAD^ &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
@@ -137,10 +143,12 @@ test_expect_success 'the default remote . should not break explicit pull' '
 test_expect_success 'fail if wildcard spec does not match any refs' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 	test_i18ngrep "no candidates for merging" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no branches specified with non-default remote' '
@@ -148,11 +156,13 @@ test_expect_success 'fail if no branches specified with non-default remote' '
 	test_when_finished "git remote remove test_remote" &&
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_config branch.test.remote origin &&
 	test_must_fail git pull test_remote 2>err &&
 	test_i18ngrep "specify a branch on the command line" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if not on a branch' '
@@ -160,10 +170,12 @@ test_expect_success 'fail if not on a branch' '
 	test_when_finished "git remote remove origin" &&
 	git checkout HEAD^ &&
 	test_when_finished "git checkout -f copy" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "not currently on a branch" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no configuration for current branch' '
@@ -172,10 +184,12 @@ test_expect_success 'fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'pull --all: fail if no configuration for current branch' '
@@ -184,10 +198,12 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull --all 2>err &&
 	test_i18ngrep "There is no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if upstream branch does not exist' '
@@ -195,16 +211,19 @@ test_expect_success 'fail if upstream branch does not exist' '
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote . &&
 	test_config branch.test.merge refs/heads/nonexisting &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no such ref was fetched" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if the index has unresolved entries' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_commit modified2 file &&
 	git ls-files -u >unmerged &&
 	test_must_be_empty unmerged &&
@@ -226,21 +245,25 @@ test_expect_success 'fail if the index has unresolved entries' '
 test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	echo conflict >file &&
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
-	test "$(cat file)" = conflict &&
+	echo conflict >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
@@ -501,7 +524,8 @@ test_expect_success 'pull.rebase=interactive' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=interactive . copy &&
-	test "I was here" = "$(cat fake.out)"
+	echo "I was here" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull --rebase=i' '
@@ -512,7 +536,8 @@ test_expect_success 'pull --rebase=i' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=i . copy &&
-	test "I was here, too" = "$(cat fake.out)"
+	echo "I was here, too" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull.rebase=invalid fails' '
@@ -578,16 +603,20 @@ test_expect_success '--rebase with rebased upstream' '
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
 	test_when_finished "test_might_fail git rebase --abort" &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase -f me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase with rebased default upstream' '
@@ -595,8 +624,10 @@ test_expect_success '--rebase with rebased default upstream' '
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -607,8 +638,10 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 	git reset --hard to-rebase-orig &&
 	git fetch &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 
 '
 
@@ -744,8 +777,10 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 test_expect_success 'git pull --rebase against local branch' '
 	git checkout -b copy2 to-rebase-orig &&
 	git pull --rebase . to-rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_done
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 13/14] t5520: remove redundant lines in test cases
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
                         ` (11 preceding siblings ...)
  2019-11-07 18:51       ` [PATCH v4 12/14] t5520: replace subshell cat comparison with test_cmp Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-07 18:51       ` [PATCH v4 14/14] t5520: replace `! git` with `test_must_fail git` Denton Liu
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

In the previous patches, the mechanical application of changes left some
duplicate statements in the test case which were not strictly incorrect
but were redundant and possibly misleading. Remove these duplicate
statements so that it is clear that the intent behind the tests are that
the content of the file stays the same throughout the whole test case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index c9e4eec004..ef3dbc201a 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -147,7 +147,6 @@ test_expect_success 'fail if wildcard spec does not match any refs' '
 	test_cmp expect file &&
 	test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 	test_i18ngrep "no candidates for merging" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -161,7 +160,6 @@ test_expect_success 'fail if no branches specified with non-default remote' '
 	test_config branch.test.remote origin &&
 	test_must_fail git pull test_remote 2>err &&
 	test_i18ngrep "specify a branch on the command line" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -174,7 +172,6 @@ test_expect_success 'fail if not on a branch' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "not currently on a branch" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -188,7 +185,6 @@ test_expect_success 'fail if no configuration for current branch' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no tracking information" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -202,7 +198,6 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
 	test_cmp expect file &&
 	test_must_fail git pull --all 2>err &&
 	test_i18ngrep "There is no tracking information" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -215,7 +210,6 @@ test_expect_success 'fail if upstream branch does not exist' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no such ref was fetched" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -685,10 +679,8 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
 		git ls-files >actual &&
 		test_cmp expect actual &&
 		test_must_fail git pull --rebase .. master 2>err &&
-		echo staged-file >expect &&
 		git ls-files >actual &&
 		test_cmp expect actual &&
-		echo staged-file >expect &&
 		git show :staged-file >actual &&
 		test_cmp expect actual &&
 		test_i18ngrep "unborn branch with changes added to the index" err
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* [PATCH v4 14/14] t5520: replace `! git` with `test_must_fail git`
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
                         ` (12 preceding siblings ...)
  2019-11-07 18:51       ` [PATCH v4 13/14] t5520: remove redundant lines in test cases Denton Liu
@ 2019-11-07 18:51       ` Denton Liu
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-07 18:51 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Currently, if a Git command fails in an unexpected way, such as a
segfault, it will be masked and ignored. Replace the ! with
test_must_fail so that only expected failures pass.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index ef3dbc201a..602d996a33 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -537,7 +537,7 @@ test_expect_success 'pull --rebase=i' '
 test_expect_success 'pull.rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase invalid &&
-	! git pull . copy
+	test_must_fail git pull . copy
 '
 
 test_expect_success '--rebase=false create a new merge commit' '
@@ -572,7 +572,7 @@ test_expect_success REBASE_P \
 
 test_expect_success '--rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
-	! git pull --rebase=invalid . copy
+	test_must_fail git pull --rebase=invalid . copy
 '
 
 test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
-- 
2.24.0.rc2.262.g2d07a97ef5


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

* Re: [PATCH v4 01/14] t: teach test_cmp_rev to accept ! for not-equals
  2019-11-07 18:51       ` [PATCH v4 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
@ 2019-11-08  3:24         ` Junio C Hamano
  2019-11-08  8:23           ` Denton Liu
  0 siblings, 1 reply; 116+ messages in thread
From: Junio C Hamano @ 2019-11-08  3:24 UTC (permalink / raw)
  To: Denton Liu
  Cc: Git Mailing List, Eric Sunshine, Johannes Sixt, SZEDER Gábor

Denton Liu <liu.denton@gmail.com> writes:

> Currently, in the case where we are using test_cmp_rev() to report
> not-equals, we write `! test_cmp_rev`. However, since test_cmp_rev()
> contains
>
> 	r1=$(git rev-parse --verify "$1") &&
> 	r2=$(git rev-parse --verify "$2") &&
>
> In the case where `git rev-parse` segfaults and dies unexpectedly, the
> failure will be ignored.

Good justification.  The last two lines are continuation of the
sentence that begins the proposed log message, so downcase "In" at
the beginning of the line.  Also, when we present the problem to be
solved at the beginning, it is customary to describe the status quo,
and "Currently, " is a noiseword that does not add much information,
so drop it.

> Rewrite test_cmp_rev() to optionally accept "!" as the first argument to
> do a not-equals comparison. Rewrite `! test_cmp_rev` to `test_cmp_rev !`
> in all tests to take advantage of this new functionality.

Good.

> -# Tests that its two parameters refer to the same revision
> +# Tests that its two parameters refer to the same revision, or if '!' is
> +# provided first, that its other two parameters refer to different
> +# revisions.

OK.

>  test_cmp_rev () {
> +	local inverted_op
> +	inverted_op='!='
> +	if test $# -ge 1 && test "x$1" = 'x!'
> +	then
> +	    inverted_op='='
> +	    shift
> +	fi

I'd rather avoid having to keep track of negation to reduce mental
burden.  How about using = by default and != when '!' was given
(which would be more natural to readers) and call it $op, and say
"if ! test $r1 $op $r2" where it is used?


>  	if test $# != 2
>  	then
>  		error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
>  	else
>  		local r1 r2
>  		r1=$(git rev-parse --verify "$1") &&
>  		r2=$(git rev-parse --verify "$2") &&

If either of the calls fail, the assignment itself would fail, and
the &&-cascade would stop without executing the if statment below.

I see the "!" feature, but where is the promised "fix" for
segfaulting rev-parse?

Puzzled.


> -		if test "$r1" != "$r2"
> +		if test "$r1" "$inverted_op" "$r2"
>  		then
> +			local comp_out
> +			if "x$inverted_op" = 'x='
> +			then
> +				comp_out='the same'
> +			else
> +				comp_out='different'
> +			fi
>  			cat >&4 <<-EOF
> -			error: two revisions point to different objects:
> +			error: two revisions point to $comp_out objects:
>  			  '$1': $r1
>  			  '$2': $r2
>  			EOF
>  			return 1
>  		fi
>  	fi
>  }

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

* Re: [PATCH v4 01/14] t: teach test_cmp_rev to accept ! for not-equals
  2019-11-08  3:24         ` Junio C Hamano
@ 2019-11-08  8:23           ` Denton Liu
  2019-11-08 12:49             ` Junio C Hamano
  0 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-11-08  8:23 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Eric Sunshine, Johannes Sixt, SZEDER Gábor

On Fri, Nov 08, 2019 at 12:24:12PM +0900, Junio C Hamano wrote:
> Denton Liu <liu.denton@gmail.com> writes:
> 
> > Currently, in the case where we are using test_cmp_rev() to report
> > not-equals, we write `! test_cmp_rev`. However, since test_cmp_rev()
> > contains
> >
> > 	r1=$(git rev-parse --verify "$1") &&
> > 	r2=$(git rev-parse --verify "$2") &&
> >
> > In the case where `git rev-parse` segfaults and dies unexpectedly, the
> > failure will be ignored.

I'll probably reword this to

	In the case where we are using test_cmp_rev() to report
	not-equals, we write `! test_cmp_rev`. However, since
	test_cmp_rev() contains

		r1=$(git rev-parse --verify "$1") &&
		r2=$(git rev-parse --verify "$2") &&

	`! test_cmp_rev` will succeed if any of the rev-parses fail.
	This behavior is not desired. We want the rev-parses to _always_
	be successful.

because of your puzzlement below.

> 
> Good justification.  The last two lines are continuation of the
> sentence that begins the proposed log message, so downcase "In" at
> the beginning of the line.  Also, when we present the problem to be
> solved at the beginning, it is customary to describe the status quo,
> and "Currently, " is a noiseword that does not add much information,
> so drop it.

Thanks, I'll make a note to stop doing this in future patches as well.

[...]

> 
> >  test_cmp_rev () {
> > +	local inverted_op
> > +	inverted_op='!='
> > +	if test $# -ge 1 && test "x$1" = 'x!'
> > +	then
> > +	    inverted_op='='
> > +	    shift
> > +	fi
> 
> I'd rather avoid having to keep track of negation to reduce mental
> burden.  How about using = by default and != when '!' was given
> (which would be more natural to readers) and call it $op, and say
> "if ! test $r1 $op $r2" where it is used?

Good idea, I felt a little uneasy doing the inverted thing but it never
occurred to me to just negate the return code of `test`.

> 
> 
> >  	if test $# != 2
> >  	then
> >  		error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
> >  	else
> >  		local r1 r2
> >  		r1=$(git rev-parse --verify "$1") &&
> >  		r2=$(git rev-parse --verify "$2") &&
> 
> If either of the calls fail, the assignment itself would fail, and
> the &&-cascade would stop without executing the if statment below.
> 
> I see the "!" feature, but where is the promised "fix" for
> segfaulting rev-parse?
> 
> Puzzled.

I suppose your puzzlement comes from my badly worded commit message
above. I meant to say that in the _hypothetical_ case that 
`git rev-parse` segfaults, it wouldn't be caught because we're
blanket-ignoring failures if we do `! test_cmp_rev`.

But I suppose I focused too much on segfaults. I guess I didn't realise
that the problem is more general than that; any failure of 
`git rev-parse` should be reported.

Thanks for the review,

Denton

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

* Re: [PATCH v4 01/14] t: teach test_cmp_rev to accept ! for not-equals
  2019-11-08  8:23           ` Denton Liu
@ 2019-11-08 12:49             ` Junio C Hamano
  2019-11-08 21:19               ` Denton Liu
  0 siblings, 1 reply; 116+ messages in thread
From: Junio C Hamano @ 2019-11-08 12:49 UTC (permalink / raw)
  To: Denton Liu
  Cc: Git Mailing List, Eric Sunshine, Johannes Sixt, SZEDER Gábor

Denton Liu <liu.denton@gmail.com> writes:

>> >  		local r1 r2
>> >  		r1=$(git rev-parse --verify "$1") &&
>> >  		r2=$(git rev-parse --verify "$2") &&
>> 
>> If either of the calls fail, the assignment itself would fail, and
>> the &&-cascade would stop without executing the if statment below.
>> 
>> I see the "!" feature, but where is the promised "fix" for
>> segfaulting rev-parse?
>> 
>> Puzzled.
>
> I suppose your puzzlement comes from my badly worded commit message
> above. I meant to say that in the _hypothetical_ case that 
> `git rev-parse` segfaults, it wouldn't be caught because we're
> blanket-ignoring failures if we do `! test_cmp_rev`.
>
> But I suppose I focused too much on segfaults. I guess I didn't realise
> that the problem is more general than that; any failure of 
> `git rev-parse` should be reported.

But if that is the case, shouldn't the part that runs two rev-parse
read more like this?

	r1=$(git rev-parse --verify "$1") ||
		error "'$1' does not name a valid object"
	r2=$(git rev-parse --verify "$2") ||
		error "'$2' does not name a valid object"
	if ! test "$r1" $op "$r2"
	then
		... they do not compare the same ...
	fi

Offhand I do not know if the current callers depend on being able to
pass a string that is not an object name in either $1 or $2 and a
valid object name in the other one, and relying on the helper
function to say "$1 and $2 are different!"  If such callers exist, a
defensive change like the above that requires the caller to always
pass valid object names would need to be accompanied with changes to
these callers, too.  Overall, I think that would give us a better
end result, but it might be a bit more work.

Thanks.

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

* Re: [PATCH v4 01/14] t: teach test_cmp_rev to accept ! for not-equals
  2019-11-08 12:49             ` Junio C Hamano
@ 2019-11-08 21:19               ` Denton Liu
  2019-11-10  6:58                 ` Junio C Hamano
  0 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-11-08 21:19 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Eric Sunshine, Johannes Sixt, SZEDER Gábor

Hi Junio,

On Fri, Nov 08, 2019 at 09:49:02PM +0900, Junio C Hamano wrote:
> Denton Liu <liu.denton@gmail.com> writes:
>
> >> >  		local r1 r2
> >> >  		r1=$(git rev-parse --verify "$1") &&
> >> >  		r2=$(git rev-parse --verify "$2") &&
> >>
> >> If either of the calls fail, the assignment itself would fail, and
> >> the &&-cascade would stop without executing the if statment below.
> >>
> >> I see the "!" feature, but where is the promised "fix" for
> >> segfaulting rev-parse?
> >>
> >> Puzzled.
> >
> > I suppose your puzzlement comes from my badly worded commit message
> > above. I meant to say that in the _hypothetical_ case that
> > `git rev-parse` segfaults, it wouldn't be caught because we're
> > blanket-ignoring failures if we do `! test_cmp_rev`.
> >
> > But I suppose I focused too much on segfaults. I guess I didn't realise
> > that the problem is more general than that; any failure of
> > `git rev-parse` should be reported.
>
> But if that is the case, shouldn't the part that runs two rev-parse
> read more like this?
>
> 	r1=$(git rev-parse --verify "$1") ||
> 		error "'$1' does not name a valid object"
> 	r2=$(git rev-parse --verify "$2") ||
> 		error "'$2' does not name a valid object"
> 	if ! test "$r1" $op "$r2"
> 	then
> 		... they do not compare the same ...
> 	fi

With your suggestion, we actually introduce subtle undesired behaviour.
The `error` calls don't actually exit the function early. To make it
work, we need to add && to the end of the `error` calls.

I'm wondering why we want to do this, though. rev-parse should already
output an error message on stderr in the case where the rev-parse fails.
I guess the error message of "fatal: Needed a single revision" could
probably be improved but that feels like an improvement that should be
targeted to rev-parse.

>
> Offhand I do not know if the current callers depend on being able to
> pass a string that is not an object name in either $1 or $2 and a
> valid object name in the other one, and relying on the helper
> function to say "$1 and $2 are different!"  If such callers exist, a
> defensive change like the above that requires the caller to always
> pass valid object names would need to be accompanied with changes to
> these callers, too.  Overall, I think that would give us a better
> end result, but it might be a bit more work.

This patch changes all instances of `! test_cmp_rev` to
`test_cmp_rev !`. Since nothing failed after applying the patch, I
believe that all callers already pass in valid object names.

Thanks,

Denton

>
> Thanks.

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

* Re: [PATCH v4 01/14] t: teach test_cmp_rev to accept ! for not-equals
  2019-11-08 21:19               ` Denton Liu
@ 2019-11-10  6:58                 ` Junio C Hamano
  0 siblings, 0 replies; 116+ messages in thread
From: Junio C Hamano @ 2019-11-10  6:58 UTC (permalink / raw)
  To: Denton Liu
  Cc: Git Mailing List, Eric Sunshine, Johannes Sixt, SZEDER Gábor

Denton Liu <liu.denton@gmail.com> writes:

> Hi Junio,
>
> On Fri, Nov 08, 2019 at 09:49:02PM +0900, Junio C Hamano wrote:
>> Denton Liu <liu.denton@gmail.com> writes:
>>
>> >> >  		local r1 r2
>> >> >  		r1=$(git rev-parse --verify "$1") &&
>> >> >  		r2=$(git rev-parse --verify "$2") &&
>> >>
>> >> If either of the calls fail, the assignment itself would fail, and
>> >> the &&-cascade would stop without executing the if statment below.
>> >>
>> 	r1=$(git rev-parse --verify "$1") ||
>> 		error "'$1' does not name a valid object"
>> 	r2=$(git rev-parse --verify "$2") ||
>> 		error "'$2' does not name a valid object"
>> 	if ! test "$r1" $op "$r2"
>> 	then
>> 		... they do not compare the same ...
>> 	fi
>
> With your suggestion, we actually introduce subtle undesired behaviour.
> The `error` calls don't actually exit the function early. To make it
> work, we need to add && to the end of the `error` calls.

Not &&-at-the-end, but yes, we'd need some early return after
noticing a bad input from the caller.

You said earlier that one of the issues that motivated you to update
the helper was that this obvious typo

	r1=... r2= ... &&
	! test_rev_cmp "$r1" "$rr2"

would not be noticed.  For such a fix, I do not think it is
sufficient to tweak the return value from the test_rev_cmp
helper function if we allow callers to expect failure like so.

And for that reason, your "allow 'test_rev_cmp ! R1 R2' syntax" part
of the change makes quite a lot of sense.  That again allows the
callers to rely on failure return from test_rev_cmp as an error.

> I'm wondering why we want to do this, though. rev-parse should already
> output an error message on stderr in the case where the rev-parse fails.
>
> I guess the error message of "fatal: Needed a single revision" could
> probably be improved but that feels like an improvement that should be
> targeted to rev-parse.

Not really.  The callers of rev-parse plumbing should expect that
exact string, if they want to differenciate different errors from
the program.


	r1=$(git rev-parse --verify "$1") &&
	r2=$(git rev-parse --verify "$2") || return 1

before we start the comparison between $r1 and $r2 may be a good way
to clarify the intent of the code.  Using "&&" instead of "|| return"
and letting the whole function fail would not be incorrect, though.

Thanks.



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

* [PATCH v5 00/14] t5520: various test cleanup
  2019-11-07 18:51     ` [PATCH v4 " Denton Liu
                         ` (13 preceding siblings ...)
  2019-11-07 18:51       ` [PATCH v4 14/14] t5520: replace `! git` with `test_must_fail git` Denton Liu
@ 2019-11-12  0:13       ` Denton Liu
  2019-11-12  0:13         ` [PATCH v5 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
                           ` (14 more replies)
  14 siblings, 15 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:13 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Like earlier patchsets, I want to implement a feature that involves
modifications to the test suite. Since that feature will probably take a
while to polish up, however, let's clean up the test suite in a separate
patchset first so it's not blocked by the feature work.

1/15 is a general improvement to test_rev_cmp() that will be used later
in the series.

Changes since v4:

* Cleaned up test_cmp_rev() logic with suggestions from Junio

Changes since v3:

* Rebased and tested on top of v2.24.0

Changes since v2:

* Drop 't7408: replace `test_must_fail test_path_is_file`' since it's
  not a rabbit hole we want to go into right now

* Fix the output of `test_cmp_rev !` when revs are actually equal

* Rebase against the latest master since this topic hasn't been picked
  up yet

Changes since v1:

* Incorporate Eric's feedback

Denton Liu (14):
  t: teach test_cmp_rev to accept ! for not-equals
  t5520: improve test style
  t5520: use sq for test case names
  t5520: let sed open its own input
  t5520: replace test -f with test-lib functions
  t5520: remove spaces after redirect operator
  t5520: use test_line_count where possible
  t5520: replace test -{n,z} with test-lib functions
  t5520: use test_cmp_rev where possible
  t5520: test single-line files by git with test_cmp
  t5520: don't put git in upstream of pipe
  t5520: replace subshell cat comparison with test_cmp
  t5520: remove redundant lines in test cases
  t5520: replace `! git` with `test_must_fail git`

 t/t2400-worktree-add.sh             |   4 +-
 t/t3400-rebase.sh                   |   2 +-
 t/t3421-rebase-topology-linear.sh   |   6 +-
 t/t3430-rebase-merges.sh            |   2 +-
 t/t3432-rebase-fast-forward.sh      |   2 +-
 t/t3501-revert-cherry-pick.sh       |   2 +-
 t/t3508-cherry-pick-many-commits.sh |   2 +-
 t/t5520-pull.sh                     | 343 +++++++++++++++++-----------
 t/test-lib-functions.sh             |  25 +-
 9 files changed, 236 insertions(+), 152 deletions(-)

Range-diff against v4:
 1:  06f89b85f3 !  1:  3c58df27c4 t: teach test_cmp_rev to accept ! for not-equals
    @@ Metadata
      ## Commit message ##
         t: teach test_cmp_rev to accept ! for not-equals
     
    -    Currently, in the case where we are using test_cmp_rev() to report
    -    not-equals, we write `! test_cmp_rev`. However, since test_cmp_rev()
    -    contains
    +    In the case where we are using test_cmp_rev() to report not-equals, we
    +    write `! test_cmp_rev`. However, since test_cmp_rev() contains
     
                 r1=$(git rev-parse --verify "$1") &&
                 r2=$(git rev-parse --verify "$2") &&
     
    -    In the case where `git rev-parse` segfaults and dies unexpectedly, the
    -    failure will be ignored.
    +    `! test_cmp_rev` will succeed if any of the rev-parses fail. This
    +    behavior is not desired. We want the rev-parses to _always_ be
    +    successful.
     
         Rewrite test_cmp_rev() to optionally accept "!" as the first argument to
         do a not-equals comparison. Rewrite `! test_cmp_rev` to `test_cmp_rev !`
         in all tests to take advantage of this new functionality.
     
    +    Also, rewrite the rev-parse logic to end with a `|| return 1` instead of
    +    &&-chaining into the rev-comparison logic. This makes it obvious to
    +    future readers that we explicitly intend on returning early if either of
    +    the rev-parses fail.
    +
         Signed-off-by: Denton Liu <liu.denton@gmail.com>
     
      ## t/t2400-worktree-add.sh ##
    @@ t/test-lib-functions.sh: test_must_be_empty () {
     +# provided first, that its other two parameters refer to different
     +# revisions.
      test_cmp_rev () {
    -+	local inverted_op
    -+	inverted_op='!='
    ++	local op
    ++	op='='
     +	if test $# -ge 1 && test "x$1" = 'x!'
     +	then
    -+	    inverted_op='='
    ++	    op='!='
     +	    shift
     +	fi
      	if test $# != 2
      	then
      		error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
    -@@ t/test-lib-functions.sh: test_cmp_rev () {
    + 	else
      		local r1 r2
      		r1=$(git rev-parse --verify "$1") &&
    - 		r2=$(git rev-parse --verify "$2") &&
    +-		r2=$(git rev-parse --verify "$2") &&
     -		if test "$r1" != "$r2"
    -+		if test "$r1" "$inverted_op" "$r2"
    ++		r2=$(git rev-parse --verify "$2") || return 1
    ++
    ++		if ! test "$r1" "$op" "$r2"
      		then
     +			local comp_out
    -+			if "x$inverted_op" = 'x='
    ++			if "x$op" = 'x='
     +			then
    -+				comp_out='the same'
    -+			else
     +				comp_out='different'
    ++			else
    ++				comp_out='the same'
     +			fi
      			cat >&4 <<-EOF
     -			error: two revisions point to different objects:
 2:  11714ca897 =  2:  023e0ccc11 t5520: improve test style
 3:  2c27c8d60a =  3:  1bb65a59da t5520: use sq for test case names
 4:  5a196cf136 =  4:  d2fbae6ade t5520: let sed open its own input
 5:  0c8baddc7d =  5:  1d73546eb6 t5520: replace test -f with test-lib functions
 6:  2775817d02 =  6:  f1141f244f t5520: remove spaces after redirect operator
 7:  d71fe3d097 =  7:  5106004e95 t5520: use test_line_count where possible
 8:  dd16809b68 =  8:  85b444e8a6 t5520: replace test -{n,z} with test-lib functions
 9:  abfa6539aa =  9:  3d43784391 t5520: use test_cmp_rev where possible
10:  06cb5c1302 = 10:  2f9052fd94 t5520: test single-line files by git with test_cmp
11:  f47f11ccfa = 11:  3fd10a58c6 t5520: don't put git in upstream of pipe
12:  3dfc417670 = 12:  ed78ed75bd t5520: replace subshell cat comparison with test_cmp
13:  575bd0f0cd = 13:  7888757bd0 t5520: remove redundant lines in test cases
14:  bd92e3821e = 14:  1bc7ad364f t5520: replace `! git` with `test_must_fail git`
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 01/14] t: teach test_cmp_rev to accept ! for not-equals
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
@ 2019-11-12  0:13         ` Denton Liu
  2019-11-12  6:52           ` Junio C Hamano
  2019-11-12  0:13         ` [PATCH v5 02/14] t5520: improve test style Denton Liu
                           ` (13 subsequent siblings)
  14 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:13 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

In the case where we are using test_cmp_rev() to report not-equals, we
write `! test_cmp_rev`. However, since test_cmp_rev() contains

	r1=$(git rev-parse --verify "$1") &&
	r2=$(git rev-parse --verify "$2") &&

`! test_cmp_rev` will succeed if any of the rev-parses fail. This
behavior is not desired. We want the rev-parses to _always_ be
successful.

Rewrite test_cmp_rev() to optionally accept "!" as the first argument to
do a not-equals comparison. Rewrite `! test_cmp_rev` to `test_cmp_rev !`
in all tests to take advantage of this new functionality.

Also, rewrite the rev-parse logic to end with a `|| return 1` instead of
&&-chaining into the rev-comparison logic. This makes it obvious to
future readers that we explicitly intend on returning early if either of
the rev-parses fail.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t2400-worktree-add.sh             |  4 ++--
 t/t3400-rebase.sh                   |  2 +-
 t/t3421-rebase-topology-linear.sh   |  6 +++---
 t/t3430-rebase-merges.sh            |  2 +-
 t/t3432-rebase-fast-forward.sh      |  2 +-
 t/t3501-revert-cherry-pick.sh       |  2 +-
 t/t3508-cherry-pick-many-commits.sh |  2 +-
 t/test-lib-functions.sh             | 25 +++++++++++++++++++++----
 8 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index e819ba741e..52d476979b 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -438,7 +438,7 @@ test_expect_success 'git worktree add does not match remote' '
 		cd foo &&
 		test_must_fail git config "branch.foo.remote" &&
 		test_must_fail git config "branch.foo.merge" &&
-		! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
+		test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
 	)
 '
 
@@ -483,7 +483,7 @@ test_expect_success 'git worktree --no-guess-remote option overrides config' '
 		cd foo &&
 		test_must_fail git config "branch.foo.remote" &&
 		test_must_fail git config "branch.foo.merge" &&
-		! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
+		test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
 	)
 '
 
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index ab18ac5f28..f267f6cd54 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -64,7 +64,7 @@ test_expect_success 'rebase sets ORIG_HEAD to pre-rebase state' '
 	pre="$(git rev-parse --verify HEAD)" &&
 	git rebase master &&
 	test_cmp_rev "$pre" ORIG_HEAD &&
-	! test_cmp_rev "$pre" HEAD
+	test_cmp_rev ! "$pre" HEAD
 '
 
 test_expect_success 'rebase, with <onto> and <upstream> specified as :/quuxery' '
diff --git a/t/t3421-rebase-topology-linear.sh b/t/t3421-rebase-topology-linear.sh
index b847064f91..325072b0a3 100755
--- a/t/t3421-rebase-topology-linear.sh
+++ b/t/t3421-rebase-topology-linear.sh
@@ -61,7 +61,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" "
 		reset_rebase &&
 		git rebase $* -f b e &&
-		! test_cmp_rev e HEAD &&
+		test_cmp_rev ! e HEAD &&
 		test_cmp_rev b HEAD~2 &&
 		test_linear_range 'd e' b..
 	"
@@ -78,7 +78,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
 		reset_rebase &&
 		git rebase $* -f branch-b branch-e &&
-		! test_cmp_rev branch-e origin/branch-e &&
+		test_cmp_rev ! branch-e origin/branch-e &&
 		test_cmp_rev branch-b HEAD~2 &&
 		test_linear_range 'd e' branch-b..
 	"
@@ -368,7 +368,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f --root on linear history causes re-write" "
 		reset_rebase &&
 		git rebase $* -f --root c &&
-		! test_cmp_rev a HEAD~2 &&
+		test_cmp_rev ! a HEAD~2 &&
 		test_linear_range 'a b c' HEAD
 	"
 }
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index 9efcf4808a..abbdc26b1b 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -346,7 +346,7 @@ test_expect_success 'A root commit can be a cousin, treat it that way' '
 	git merge --allow-unrelated-histories khnum &&
 	test_tick &&
 	git rebase -f -r HEAD^ &&
-	! test_cmp_rev HEAD^2 khnum &&
+	test_cmp_rev ! HEAD^2 khnum &&
 	test_cmp_graph HEAD^.. <<-\EOF &&
 	*   Merge branch '\''khnum'\'' into asherah
 	|\
diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh
index 034ffc7e76..92f95b57da 100755
--- a/t/t3432-rebase-fast-forward.sh
+++ b/t/t3432-rebase-fast-forward.sh
@@ -64,7 +64,7 @@ test_rebase_same_head_ () {
 			test_cmp_rev \$oldhead \$newhead
 		elif test $cmp = diff
 		then
-			! test_cmp_rev \$oldhead \$newhead
+			test_cmp_rev ! \$oldhead \$newhead
 		fi
 	"
 }
diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh
index d1c68af8c5..1c51a9131d 100755
--- a/t/t3501-revert-cherry-pick.sh
+++ b/t/t3501-revert-cherry-pick.sh
@@ -106,7 +106,7 @@ test_expect_success 'cherry-pick on unborn branch' '
 	rm -rf * &&
 	git cherry-pick initial &&
 	git diff --quiet initial &&
-	! test_cmp_rev initial HEAD
+	test_cmp_rev ! initial HEAD
 '
 
 test_expect_success 'cherry-pick "-" to pick from previous branch' '
diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh
index b457333e18..23070a7b73 100755
--- a/t/t3508-cherry-pick-many-commits.sh
+++ b/t/t3508-cherry-pick-many-commits.sh
@@ -5,7 +5,7 @@ test_description='test cherry-picking many commits'
 . ./test-lib.sh
 
 check_head_differs_from() {
-	! test_cmp_rev HEAD "$1"
+	test_cmp_rev ! HEAD "$1"
 }
 
 check_head_equals() {
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b299ecc326..01cdbb0478 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1012,19 +1012,36 @@ test_must_be_empty () {
 	fi
 }
 
-# Tests that its two parameters refer to the same revision
+# Tests that its two parameters refer to the same revision, or if '!' is
+# provided first, that its other two parameters refer to different
+# revisions.
 test_cmp_rev () {
+	local op
+	op='='
+	if test $# -ge 1 && test "x$1" = 'x!'
+	then
+	    op='!='
+	    shift
+	fi
 	if test $# != 2
 	then
 		error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
 	else
 		local r1 r2
 		r1=$(git rev-parse --verify "$1") &&
-		r2=$(git rev-parse --verify "$2") &&
-		if test "$r1" != "$r2"
+		r2=$(git rev-parse --verify "$2") || return 1
+
+		if ! test "$r1" "$op" "$r2"
 		then
+			local comp_out
+			if "x$op" = 'x='
+			then
+				comp_out='different'
+			else
+				comp_out='the same'
+			fi
 			cat >&4 <<-EOF
-			error: two revisions point to different objects:
+			error: two revisions point to $comp_out objects:
 			  '$1': $r1
 			  '$2': $r2
 			EOF
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 02/14] t5520: improve test style
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
  2019-11-12  0:13         ` [PATCH v5 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
@ 2019-11-12  0:13         ` Denton Liu
  2019-11-12  0:13         ` [PATCH v5 03/14] t5520: use sq for test case names Denton Liu
                           ` (12 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:13 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Improve the test style by removing leading and trailing empty lines
within test cases. Also, reformat multi-line subshells to conform to the
existing style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 88 +++++++++++++++++++++++++------------------------
 1 file changed, 45 insertions(+), 43 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index cf4cc32fd0..51d6ce8aec 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -538,7 +538,6 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 '
 
 test_expect_success '--rebase with rebased upstream' '
-
 	git remote add -f me . &&
 	git checkout copy &&
 	git tag copy-orig &&
@@ -552,7 +551,6 @@ test_expect_success '--rebase with rebased upstream' '
 	git pull --rebase me copy &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = "$(cat file2)"
-
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
@@ -564,14 +562,12 @@ test_expect_success '--rebase -f with rebased upstream' '
 '
 
 test_expect_success '--rebase with rebased default upstream' '
-
 	git update-ref refs/remotes/me/copy copy-orig &&
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = "$(cat file2)"
-
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -588,7 +584,6 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 '
 
 test_expect_success 'pull --rebase dies early with dirty working directory' '
-
 	git checkout to-rebase &&
 	git update-ref refs/remotes/me/copy copy^ &&
 	COPY="$(git rev-parse --verify me/copy)" &&
@@ -603,16 +598,16 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	git checkout HEAD -- file &&
 	git pull &&
 	test "$COPY" != "$(git rev-parse --verify me/copy)"
-
 '
 
 test_expect_success 'pull --rebase works on branch yet to be born' '
 	git rev-parse master >expect &&
 	mkdir empty_repo &&
-	(cd empty_repo &&
-	 git init &&
-	 git pull --rebase .. master &&
-	 git rev-parse HEAD >../actual
+	(
+		cd empty_repo &&
+		git init &&
+		git pull --rebase .. master &&
+		git rev-parse HEAD >../actual
 	) &&
 	test_cmp expect actual
 '
@@ -646,58 +641,65 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 
 test_expect_success 'setup for detecting upstreamed changes' '
 	mkdir src &&
-	(cd src &&
-	 git init &&
-	 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
-	 git add stuff &&
-	 git commit -m "Initial revision"
+	(
+		cd src &&
+		git init &&
+		printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
+		git add stuff &&
+		git commit -m "Initial revision"
 	) &&
 	git clone src dst &&
-	(cd src &&
-	 modify s/5/43/ stuff &&
-	 git commit -a -m "5->43" &&
-	 modify s/6/42/ stuff &&
-	 git commit -a -m "Make it bigger"
+	(
+		cd src &&
+		modify s/5/43/ stuff &&
+		git commit -a -m "5->43" &&
+		modify s/6/42/ stuff &&
+		git commit -a -m "Make it bigger"
 	) &&
-	(cd dst &&
-	 modify s/5/43/ stuff &&
-	 git commit -a -m "Independent discovery of 5->43"
+	(
+		cd dst &&
+		modify s/5/43/ stuff &&
+		git commit -a -m "Independent discovery of 5->43"
 	)
 '
 
 test_expect_success 'git pull --rebase detects upstreamed changes' '
-	(cd dst &&
-	 git pull --rebase &&
-	 test -z "$(git ls-files -u)"
+	(
+		cd dst &&
+		git pull --rebase &&
+		test -z "$(git ls-files -u)"
 	)
 '
 
 test_expect_success 'setup for avoiding reapplying old patches' '
-	(cd dst &&
-	 test_might_fail git rebase --abort &&
-	 git reset --hard origin/master
+	(
+		cd dst &&
+		test_might_fail git rebase --abort &&
+		git reset --hard origin/master
 	) &&
 	git clone --bare src src-replace.git &&
 	rm -rf src &&
 	mv src-replace.git src &&
-	(cd dst &&
-	 modify s/2/22/ stuff &&
-	 git commit -a -m "Change 2" &&
-	 modify s/3/33/ stuff &&
-	 git commit -a -m "Change 3" &&
-	 modify s/4/44/ stuff &&
-	 git commit -a -m "Change 4" &&
-	 git push &&
-
-	 modify s/44/55/ stuff &&
-	 git commit --amend -a -m "Modified Change 4"
+	(
+		cd dst &&
+		modify s/2/22/ stuff &&
+		git commit -a -m "Change 2" &&
+		modify s/3/33/ stuff &&
+		git commit -a -m "Change 3" &&
+		modify s/4/44/ stuff &&
+		git commit -a -m "Change 4" &&
+		git push &&
+
+		modify s/44/55/ stuff &&
+		git commit --amend -a -m "Modified Change 4"
 	)
 '
 
 test_expect_success 'git pull --rebase does not reapply old patches' '
-	(cd dst &&
-	 test_must_fail git pull --rebase &&
-	 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+	(
+		cd dst &&
+		test_must_fail git pull --rebase &&
+		test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
 	)
 '
 
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 03/14] t5520: use sq for test case names
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
  2019-11-12  0:13         ` [PATCH v5 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
  2019-11-12  0:13         ` [PATCH v5 02/14] t5520: improve test style Denton Liu
@ 2019-11-12  0:13         ` Denton Liu
  2019-11-12  0:13         ` [PATCH v5 04/14] t5520: let sed open its own input Denton Liu
                           ` (11 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:13 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

The usual convention is for test case names to be written between
single-quotes. Change all double-quoted test case names to single-quotes
except for two test case names that use variables within.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 51d6ce8aec..a3de2e19b6 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -408,7 +408,7 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test new = "$(git show HEAD:file2)"
 '
 
-test_expect_success "pull --rebase warns on --verify-signatures" '
+test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
 	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
@@ -416,7 +416,7 @@ test_expect_success "pull --rebase warns on --verify-signatures" '
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
 
-test_expect_success "pull --rebase does not warn on --no-verify-signatures" '
+test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
 	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 04/14] t5520: let sed open its own input
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
                           ` (2 preceding siblings ...)
  2019-11-12  0:13         ` [PATCH v5 03/14] t5520: use sq for test case names Denton Liu
@ 2019-11-12  0:13         ` Denton Liu
  2019-11-12  0:13         ` [PATCH v5 05/14] t5520: replace test -f with test-lib functions Denton Liu
                           ` (10 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:13 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

We were using a redirection operator to feed input into sed. However,
since sed is capable of opening its own files, make sed open its own
files instead of redirecting input into it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a3de2e19b6..55560ce3cd 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -5,7 +5,7 @@ test_description='pulling into void'
 . ./test-lib.sh
 
 modify () {
-	sed -e "$1" <"$2" >"$2.x" &&
+	sed -e "$1" "$2" >"$2.x" &&
 	mv "$2.x" "$2"
 }
 
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 05/14] t5520: replace test -f with test-lib functions
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
                           ` (3 preceding siblings ...)
  2019-11-12  0:13         ` [PATCH v5 04/14] t5520: let sed open its own input Denton Liu
@ 2019-11-12  0:13         ` Denton Liu
  2019-11-12  0:13         ` [PATCH v5 06/14] t5520: remove spaces after redirect operator Denton Liu
                           ` (9 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:13 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Although `test -f` has the same functionality as test_path_is_file(), in
the case where test_path_is_file() fails, we get much better debugging
information.

Replace `test -f` with test_path_is_file() so that future developers
will have a better experience debugging these test cases.

Also, in the case of `! test -f`, not only should that path not be a
file, it shouldn't exist at all so replace it with
test_path_is_missing().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 55560ce3cd..004d5884cd 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -39,8 +39,8 @@ test_expect_success 'pulling into void' '
 		cd cloned &&
 		git pull ..
 	) &&
-	test -f file &&
-	test -f cloned/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned/file &&
 	test_cmp file cloned/file
 '
 
@@ -50,8 +50,8 @@ test_expect_success 'pulling into void using master:master' '
 		cd cloned-uho &&
 		git pull .. master:master
 	) &&
-	test -f file &&
-	test -f cloned-uho/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned-uho/file &&
 	test_cmp file cloned-uho/file
 '
 
@@ -99,7 +99,7 @@ test_expect_success 'pulling into void must not create an octopus' '
 	(
 		cd cloned-octopus &&
 		test_must_fail git pull .. master master &&
-		! test -f file
+		test_path_is_missing file
 	)
 '
 
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 06/14] t5520: remove spaces after redirect operator
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
                           ` (4 preceding siblings ...)
  2019-11-12  0:13         ` [PATCH v5 05/14] t5520: replace test -f with test-lib functions Denton Liu
@ 2019-11-12  0:13         ` Denton Liu
  2019-11-12  0:13         ` [PATCH v5 07/14] t5520: use test_line_count where possible Denton Liu
                           ` (8 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:13 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

The style for tests in Git is to have the redirect operator attached to
the filename with no spaces. Fix test cases where this is not the case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 004d5884cd..7bb9031140 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -243,10 +243,10 @@ test_expect_success 'fast-forward fails with conflicting work tree' '
 
 test_expect_success '--rebase' '
 	git branch to-rebase &&
-	echo modified again > file &&
+	echo modified again >file &&
 	git commit -m file file &&
 	git checkout to-rebase &&
-	echo new > file2 &&
+	echo new >file2 &&
 	git add file2 &&
 	git commit -m "new file" &&
 	git tag before-rebase &&
@@ -542,10 +542,10 @@ test_expect_success '--rebase with rebased upstream' '
 	git checkout copy &&
 	git tag copy-orig &&
 	git reset --hard HEAD^ &&
-	echo conflicting modification > file &&
+	echo conflicting modification >file &&
 	git commit -m conflict file &&
 	git checkout to-rebase &&
-	echo file > file2 &&
+	echo file >file2 &&
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
@@ -591,7 +591,7 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	test_config branch.to-rebase.remote me &&
 	test_config branch.to-rebase.merge refs/heads/copy &&
 	test_config branch.to-rebase.rebase true &&
-	echo dirty >> file &&
+	echo dirty >>file &&
 	git add file &&
 	test_must_fail git pull &&
 	test "$COPY" = "$(git rev-parse --verify me/copy)" &&
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 07/14] t5520: use test_line_count where possible
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
                           ` (5 preceding siblings ...)
  2019-11-12  0:13         ` [PATCH v5 06/14] t5520: remove spaces after redirect operator Denton Liu
@ 2019-11-12  0:13         ` Denton Liu
  2019-11-12  0:13         ` [PATCH v5 08/14] t5520: replace test -{n,z} with test-lib functions Denton Liu
                           ` (7 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:13 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Instead of rolling our own functionality to test the number of lines a
command outputs, use test_line_count() which provides better debugging
information in the case of a failure.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 7bb9031140..0ca4867e96 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -699,7 +699,8 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 	(
 		cd dst &&
 		test_must_fail git pull --rebase &&
-		test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+		find .git/rebase-apply -name "000*" >patches &&
+		test_line_count = 1 patches
 	)
 '
 
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 08/14] t5520: replace test -{n,z} with test-lib functions
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
                           ` (6 preceding siblings ...)
  2019-11-12  0:13         ` [PATCH v5 07/14] t5520: use test_line_count where possible Denton Liu
@ 2019-11-12  0:13         ` Denton Liu
  2019-11-12  0:14         ` [PATCH v5 09/14] t5520: use test_cmp_rev where possible Denton Liu
                           ` (6 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:13 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

When wrapping a Git command in a subshell within another command, we
throw away the Git command's exit code. In case the Git command fails,
we would like to know about it rather than the failure being silent.
Extract Git commands so that their exit codes are not lost.

Instead of using `test -n` or `test -z`, replace them respectively with
invocations of test_file_not_empty() and test_must_be_empty() so that we
get better debugging information in the case of a failure.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 0ca4867e96..18225d8430 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -206,15 +206,18 @@ test_expect_success 'fail if the index has unresolved entries' '
 	test_when_finished "git checkout -f copy && git branch -D third" &&
 	test "$(cat file)" = file &&
 	test_commit modified2 file &&
-	test -z "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_must_be_empty unmerged &&
 	test_must_fail git pull . second &&
-	test -n "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_file_not_empty unmerged &&
 	cp file expected &&
 	test_must_fail git pull . second 2>err &&
 	test_i18ngrep "Pulling is not possible because you have unmerged files." err &&
 	test_cmp expected file &&
 	git add file &&
-	test -z "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_must_be_empty unmerged &&
 	test_must_fail git pull . second 2>err &&
 	test_i18ngrep "You have not concluded your merge" err &&
 	test_cmp expected file
@@ -667,7 +670,8 @@ test_expect_success 'git pull --rebase detects upstreamed changes' '
 	(
 		cd dst &&
 		git pull --rebase &&
-		test -z "$(git ls-files -u)"
+		git ls-files -u >untracked &&
+		test_must_be_empty untracked
 	)
 '
 
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 09/14] t5520: use test_cmp_rev where possible
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
                           ` (7 preceding siblings ...)
  2019-11-12  0:13         ` [PATCH v5 08/14] t5520: replace test -{n,z} with test-lib functions Denton Liu
@ 2019-11-12  0:14         ` Denton Liu
  2019-11-12  0:14         ` [PATCH v5 10/14] t5520: test single-line files by git with test_cmp Denton Liu
                           ` (5 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:14 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

In case an invocation of `git rev-list` fails within the subshell, the
failure will be masked. Remove the subshell and use test_cmp_rev() so
that failures can be discovered.

This change was done with the following sed expressions:

	s/test "$(git rev-parse.* \([^)]*\))" = "$(git rev-parse \([^)]*\))"/test_cmp_rev \1 \2/
	s/test \([^ ]*\) = "$(git rev-parse.* \([^)]*\))"/test_cmp_rev \1 \2/
	s/test "$(git rev-parse.* \([^)]*\))" != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/
	s/test \([^ ]*\) != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 50 ++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 18225d8430..1af6ea06ee 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -230,7 +230,7 @@ test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
 	test "$(cat file)" = modified &&
-	test "$(git rev-parse third)" = "$(git rev-parse second)"
+	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
@@ -241,7 +241,7 @@ test_expect_success 'fast-forward fails with conflicting work tree' '
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
 	test "$(cat file)" = conflict &&
-	test "$(git rev-parse third)" = "$(git rev-parse second)"
+	test_cmp_rev third second
 '
 
 test_expect_success '--rebase' '
@@ -254,7 +254,7 @@ test_expect_success '--rebase' '
 	git commit -m "new file" &&
 	git tag before-rebase &&
 	git pull --rebase . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -266,7 +266,7 @@ test_expect_success '--rebase fast forward' '
 
 	git checkout to-rebase &&
 	git pull --rebase . ff &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse ff)" &&
+	test_cmp_rev HEAD ff &&
 
 	# The above only validates the result.  Did we actually bypass rebase?
 	git reflog -1 >reflog.actual &&
@@ -290,7 +290,7 @@ test_expect_success '--rebase --autostash fast forward' '
 	git checkout behind &&
 	echo dirty >file &&
 	git pull --rebase --autostash . to-rebase-ff &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse to-rebase-ff)"
+	test_cmp_rev HEAD to-rebase-ff
 '
 
 test_expect_success '--rebase with conflicts shows advice' '
@@ -328,7 +328,7 @@ test_expect_success 'failed --rebase shows advice' '
 test_expect_success '--rebase fails with multiple branches' '
 	git reset --hard before-rebase &&
 	test_must_fail git pull --rebase . copy master 2>err &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse before-rebase)" &&
+	test_cmp_rev HEAD before-rebase &&
 	test_i18ngrep "Cannot rebase onto multiple branches" err &&
 	test modified = "$(git show HEAD:file)"
 '
@@ -380,7 +380,7 @@ test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -398,7 +398,7 @@ test_expect_success 'branch.to-rebase.rebase' '
 	git reset --hard before-rebase &&
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -407,14 +407,14 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_config pull.rebase true &&
 	test_config branch.to-rebase.rebase false &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
+	test_cmp_rev ! HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)" &&
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
@@ -422,7 +422,7 @@ test_expect_success 'pull --rebase warns on --verify-signatures' '
 test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)" &&
 	test_i18ngrep ! "verify-signatures" err
 '
@@ -443,8 +443,8 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase false &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^1 before-preserve-rebase &&
+	test_cmp_rev HEAD^2 copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -452,7 +452,7 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -460,7 +460,7 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase 1 &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -469,8 +469,8 @@ test_expect_success REBASE_P \
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
+	test_cmp_rev HEAD^^ copy &&
+	test_cmp_rev HEAD^2 keep-merge
 '
 
 test_expect_success 'pull.rebase=interactive' '
@@ -505,8 +505,8 @@ test_expect_success '--rebase=false create a new merge commit' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull --rebase=false . copy &&
-	test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^1 before-preserve-rebase &&
+	test_cmp_rev HEAD^2 copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -514,7 +514,7 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull --rebase=true . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -523,8 +523,8 @@ test_expect_success REBASE_P \
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull --rebase=preserve . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
+	test_cmp_rev HEAD^^ copy &&
+	test_cmp_rev HEAD^2 keep-merge
 '
 
 test_expect_success '--rebase=invalid fails' '
@@ -536,7 +536,7 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull --rebase . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -597,10 +597,10 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	echo dirty >>file &&
 	git add file &&
 	test_must_fail git pull &&
-	test "$COPY" = "$(git rev-parse --verify me/copy)" &&
+	test_cmp_rev "$COPY" me/copy &&
 	git checkout HEAD -- file &&
 	git pull &&
-	test "$COPY" != "$(git rev-parse --verify me/copy)"
+	test_cmp_rev ! "$COPY" me/copy
 '
 
 test_expect_success 'pull --rebase works on branch yet to be born' '
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 10/14] t5520: test single-line files by git with test_cmp
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
                           ` (8 preceding siblings ...)
  2019-11-12  0:14         ` [PATCH v5 09/14] t5520: use test_cmp_rev where possible Denton Liu
@ 2019-11-12  0:14         ` Denton Liu
  2019-11-12  5:17           ` Junio C Hamano
  2019-11-12  0:14         ` [PATCH v5 11/14] t5520: don't put git in upstream of pipe Denton Liu
                           ` (4 subsequent siblings)
  14 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:14 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

In case an invocation of a Git command fails within the subshell, the
failure will be masked. Replace the subshell with a file-redirection and
a call to test_cmp.

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^ ]*\) = "$(\(git [^)]*\))"/\1echo \2 >expect \&\&\n\1\3 >actual \&\&\n\1test_cmp expect actual/
	s/\(\s*\)test "$(\(git [^)]*\))" = \([^ ]*\)/\1echo \3 >expect \&\&\n\1\2 >actual \&\&\n\1test_cmp expect actual/

A future patch will clean up situations where we have multiple duplicate
statements within a test case. This is done to keep this patch purely
mechanical.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 64 ++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 16 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 1af6ea06ee..8b7e7ae55d 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -255,7 +255,9 @@ test_expect_success '--rebase' '
 	git tag before-rebase &&
 	git pull --rebase . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase fast forward' '
@@ -330,7 +332,9 @@ test_expect_success '--rebase fails with multiple branches' '
 	test_must_fail git pull --rebase . copy master 2>err &&
 	test_cmp_rev HEAD before-rebase &&
 	test_i18ngrep "Cannot rebase onto multiple branches" err &&
-	test modified = "$(git show HEAD:file)"
+	echo modified >expect &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
@@ -381,7 +385,9 @@ test_expect_success 'pull.rebase' '
 	test_config pull.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --autostash & pull.rebase=true' '
@@ -399,7 +405,9 @@ test_expect_success 'branch.to-rebase.rebase' '
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
@@ -408,14 +416,18 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_config branch.to-rebase.rebase false &&
 	git pull . copy &&
 	test_cmp_rev ! HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)" &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual &&
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
 
@@ -423,7 +435,9 @@ test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)" &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual &&
 	test_i18ngrep ! "verify-signatures" err
 '
 
@@ -445,7 +459,9 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	git pull . copy &&
 	test_cmp_rev HEAD^1 before-preserve-rebase &&
 	test_cmp_rev HEAD^2 copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull.rebase=true flattens keep-merge' '
@@ -453,7 +469,9 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
 	test_config pull.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
@@ -461,7 +479,9 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	test_config pull.rebase 1 &&
 	git pull . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success REBASE_P \
@@ -507,7 +527,9 @@ test_expect_success '--rebase=false create a new merge commit' '
 	git pull --rebase=false . copy &&
 	test_cmp_rev HEAD^1 before-preserve-rebase &&
 	test_cmp_rev HEAD^2 copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase=true rebases and flattens keep-merge' '
@@ -515,7 +537,9 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
 	test_config pull.rebase preserve &&
 	git pull --rebase=true . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success REBASE_P \
@@ -537,7 +561,9 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 	test_config pull.rebase preserve &&
 	git pull --rebase . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase with rebased upstream' '
@@ -622,10 +648,16 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
 		cd empty_repo2 &&
 		echo staged-file >staged-file &&
 		git add staged-file &&
-		test "$(git ls-files)" = staged-file &&
+		echo staged-file >expect &&
+		git ls-files >actual &&
+		test_cmp expect actual &&
 		test_must_fail git pull --rebase .. master 2>err &&
-		test "$(git ls-files)" = staged-file &&
-		test "$(git show :staged-file)" = staged-file &&
+		echo staged-file >expect &&
+		git ls-files >actual &&
+		test_cmp expect actual &&
+		echo staged-file >expect &&
+		git show :staged-file >actual &&
+		test_cmp expect actual &&
 		test_i18ngrep "unborn branch with changes added to the index" err
 	)
 '
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 11/14] t5520: don't put git in upstream of pipe
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
                           ` (9 preceding siblings ...)
  2019-11-12  0:14         ` [PATCH v5 10/14] t5520: test single-line files by git with test_cmp Denton Liu
@ 2019-11-12  0:14         ` Denton Liu
  2019-11-12  0:14         ` [PATCH v5 12/14] t5520: replace subshell cat comparison with test_cmp Denton Liu
                           ` (3 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:14 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Before, if the invocation of git failed, it would be masked by the pipe
since only the return code of the last element of a pipe is used.
Rewrite the test to put the Git command on its own line so its return
code is not masked.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 8b7e7ae55d..8ddf89e550 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -668,7 +668,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 	(
 		cd corrupt &&
 		test_commit one &&
-		obj=$(git rev-parse --verify HEAD | sed "s#^..#&/#") &&
+		git rev-parse --verify HEAD >head &&
+		obj=$(sed "s#^..#&/#" head) &&
 		rm -f .git/objects/$obj &&
 		test_must_fail git pull --rebase
 	)
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 12/14] t5520: replace subshell cat comparison with test_cmp
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
                           ` (10 preceding siblings ...)
  2019-11-12  0:14         ` [PATCH v5 11/14] t5520: don't put git in upstream of pipe Denton Liu
@ 2019-11-12  0:14         ` Denton Liu
  2019-11-12  0:14         ` [PATCH v5 13/14] t5520: remove redundant lines in test cases Denton Liu
                           ` (2 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:14 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

We currently have many instances of `test <line> = $(cat <file>)` and
`test $(cat <file>) = <line>`.  In the case where this fails, it will be
difficult for a developer to debug since the output will be masked.
Replace these instances with invocations of test_cmp().

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^=]*\)= "$(cat \([^)]*\))"/\1echo \2>expect \&\&\n\1test_cmp expect \3/
	s/\(\s*\)test "$(cat \([^)]*\))" = \([^&]*\)\( &&\)\?$/\1echo \3 >expect \&\&\n\1test_cmp expect \2\4/

A future patch will clean up situations where we have multiple duplicate
statements within a test case. This is done to keep this patch purely
mechanical.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 105 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 70 insertions(+), 35 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 8ddf89e550..c9e4eec004 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -15,8 +15,10 @@ test_pull_autostash () {
 	git add new_file &&
 	git pull "$@" . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test "$(cat new_file)" = dirty &&
-	test "$(cat file)" = "modified again"
+	echo dirty >expect &&
+	test_cmp expect new_file &&
+	echo "modified again" >expect &&
+	test_cmp expect file
 }
 
 test_pull_autostash_fail () {
@@ -110,9 +112,11 @@ test_expect_success 'test . as a remote' '
 	echo updated >file &&
 	git commit -a -m updated &&
 	git checkout copy &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull &&
-	test "$(cat file)" = updated &&
+	echo updated >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
@@ -125,9 +129,11 @@ test_expect_success 'the default remote . should not break explicit pull' '
 	git commit -a -m modified &&
 	git checkout copy &&
 	git reset --hard HEAD^ &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
@@ -137,10 +143,12 @@ test_expect_success 'the default remote . should not break explicit pull' '
 test_expect_success 'fail if wildcard spec does not match any refs' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 	test_i18ngrep "no candidates for merging" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no branches specified with non-default remote' '
@@ -148,11 +156,13 @@ test_expect_success 'fail if no branches specified with non-default remote' '
 	test_when_finished "git remote remove test_remote" &&
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_config branch.test.remote origin &&
 	test_must_fail git pull test_remote 2>err &&
 	test_i18ngrep "specify a branch on the command line" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if not on a branch' '
@@ -160,10 +170,12 @@ test_expect_success 'fail if not on a branch' '
 	test_when_finished "git remote remove origin" &&
 	git checkout HEAD^ &&
 	test_when_finished "git checkout -f copy" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "not currently on a branch" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no configuration for current branch' '
@@ -172,10 +184,12 @@ test_expect_success 'fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'pull --all: fail if no configuration for current branch' '
@@ -184,10 +198,12 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull --all 2>err &&
 	test_i18ngrep "There is no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if upstream branch does not exist' '
@@ -195,16 +211,19 @@ test_expect_success 'fail if upstream branch does not exist' '
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote . &&
 	test_config branch.test.merge refs/heads/nonexisting &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no such ref was fetched" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if the index has unresolved entries' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_commit modified2 file &&
 	git ls-files -u >unmerged &&
 	test_must_be_empty unmerged &&
@@ -226,21 +245,25 @@ test_expect_success 'fail if the index has unresolved entries' '
 test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	echo conflict >file &&
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
-	test "$(cat file)" = conflict &&
+	echo conflict >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
@@ -501,7 +524,8 @@ test_expect_success 'pull.rebase=interactive' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=interactive . copy &&
-	test "I was here" = "$(cat fake.out)"
+	echo "I was here" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull --rebase=i' '
@@ -512,7 +536,8 @@ test_expect_success 'pull --rebase=i' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=i . copy &&
-	test "I was here, too" = "$(cat fake.out)"
+	echo "I was here, too" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull.rebase=invalid fails' '
@@ -578,16 +603,20 @@ test_expect_success '--rebase with rebased upstream' '
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
 	test_when_finished "test_might_fail git rebase --abort" &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase -f me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase with rebased default upstream' '
@@ -595,8 +624,10 @@ test_expect_success '--rebase with rebased default upstream' '
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -607,8 +638,10 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 	git reset --hard to-rebase-orig &&
 	git fetch &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 
 '
 
@@ -744,8 +777,10 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 test_expect_success 'git pull --rebase against local branch' '
 	git checkout -b copy2 to-rebase-orig &&
 	git pull --rebase . to-rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_done
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 13/14] t5520: remove redundant lines in test cases
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
                           ` (11 preceding siblings ...)
  2019-11-12  0:14         ` [PATCH v5 12/14] t5520: replace subshell cat comparison with test_cmp Denton Liu
@ 2019-11-12  0:14         ` Denton Liu
  2019-11-12  0:14         ` [PATCH v5 14/14] t5520: replace `! git` with `test_must_fail git` Denton Liu
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:14 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

In the previous patches, the mechanical application of changes left some
duplicate statements in the test case which were not strictly incorrect
but were redundant and possibly misleading. Remove these duplicate
statements so that it is clear that the intent behind the tests are that
the content of the file stays the same throughout the whole test case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index c9e4eec004..ef3dbc201a 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -147,7 +147,6 @@ test_expect_success 'fail if wildcard spec does not match any refs' '
 	test_cmp expect file &&
 	test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 	test_i18ngrep "no candidates for merging" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -161,7 +160,6 @@ test_expect_success 'fail if no branches specified with non-default remote' '
 	test_config branch.test.remote origin &&
 	test_must_fail git pull test_remote 2>err &&
 	test_i18ngrep "specify a branch on the command line" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -174,7 +172,6 @@ test_expect_success 'fail if not on a branch' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "not currently on a branch" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -188,7 +185,6 @@ test_expect_success 'fail if no configuration for current branch' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no tracking information" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -202,7 +198,6 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
 	test_cmp expect file &&
 	test_must_fail git pull --all 2>err &&
 	test_i18ngrep "There is no tracking information" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -215,7 +210,6 @@ test_expect_success 'fail if upstream branch does not exist' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no such ref was fetched" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -685,10 +679,8 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
 		git ls-files >actual &&
 		test_cmp expect actual &&
 		test_must_fail git pull --rebase .. master 2>err &&
-		echo staged-file >expect &&
 		git ls-files >actual &&
 		test_cmp expect actual &&
-		echo staged-file >expect &&
 		git show :staged-file >actual &&
 		test_cmp expect actual &&
 		test_i18ngrep "unborn branch with changes added to the index" err
-- 
2.24.0.300.g722ba42680


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

* [PATCH v5 14/14] t5520: replace `! git` with `test_must_fail git`
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
                           ` (12 preceding siblings ...)
  2019-11-12  0:14         ` [PATCH v5 13/14] t5520: remove redundant lines in test cases Denton Liu
@ 2019-11-12  0:14         ` Denton Liu
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12  0:14 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Currently, if a Git command fails in an unexpected way, such as a
segfault, it will be masked and ignored. Replace the ! with
test_must_fail so that only expected failures pass.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index ef3dbc201a..602d996a33 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -537,7 +537,7 @@ test_expect_success 'pull --rebase=i' '
 test_expect_success 'pull.rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase invalid &&
-	! git pull . copy
+	test_must_fail git pull . copy
 '
 
 test_expect_success '--rebase=false create a new merge commit' '
@@ -572,7 +572,7 @@ test_expect_success REBASE_P \
 
 test_expect_success '--rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
-	! git pull --rebase=invalid . copy
+	test_must_fail git pull --rebase=invalid . copy
 '
 
 test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
-- 
2.24.0.300.g722ba42680


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

* Re: [PATCH v5 10/14] t5520: test single-line files by git with test_cmp
  2019-11-12  0:14         ` [PATCH v5 10/14] t5520: test single-line files by git with test_cmp Denton Liu
@ 2019-11-12  5:17           ` Junio C Hamano
  2019-11-12 23:06             ` Denton Liu
  0 siblings, 1 reply; 116+ messages in thread
From: Junio C Hamano @ 2019-11-12  5:17 UTC (permalink / raw)
  To: Denton Liu
  Cc: Git Mailing List, Eric Sunshine, Johannes Sixt, SZEDER Gábor

Denton Liu <liu.denton@gmail.com> writes:

> In case an invocation of a Git command fails within the subshell, the
> failure will be masked. Replace the subshell with a file-redirection and
> a call to test_cmp.

I.e.

    test "$(git cmd args)" = "expected-string"

=>

    git cmd args >actual && echo "expected-string" >expect &&
    test_cmp expect actual

which makes sense.  It may break if expected-string begins with a
dash or something silly like that, but a quick eyeballing over the
patch tells me that we are safe there.

Technically, "$(git cmd args)" used as a command line option of
another command is called "command substitution", not "subshell".
The proposed log message may need to be updated.

> This change was done with the following GNU sed expressions:
>
> 	s/\(\s*\)test \([^ ]*\) = "$(\(git [^)]*\))"/\1echo \2 >expect \&\&\n\1\3 >actual \&\&\n\1test_cmp expect actual/
> 	s/\(\s*\)test "$(\(git [^)]*\))" = \([^ ]*\)/\1echo \3 >expect \&\&\n\1\2 >actual \&\&\n\1test_cmp expect actual/
>
> A future patch will clean up situations where we have multiple duplicate
> statements within a test case. This is done to keep this patch purely
> mechanical.

OK.  One thing that worries me is if the existing tests are not
expecting (no pun intended) to see 'expect' or 'actual' (e.g. if
they somehow rely on output of "ls-files -u", we are now adding two
untracked files in the working tree).  Another is if the git command
is expected to produce nothing, possibly after failing, and the test
is expecting to see an empty string---in such a case, the hiding of
the exit status would have been intentional ;-)  We'd want to be sure
that we aren't breaking the tests like that by reading through the
result of applying this patch.

Since this is just a single file, I trust you have already done such
sanity checking ;-)

The mechanical conversion procedure itself looks OK.

Thanks.

> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
>  t/t5520-pull.sh | 64 ++++++++++++++++++++++++++++++++++++-------------
>  1 file changed, 48 insertions(+), 16 deletions(-)
>
> diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
> index 1af6ea06ee..8b7e7ae55d 100755
> --- a/t/t5520-pull.sh
> +++ b/t/t5520-pull.sh
> @@ -255,7 +255,9 @@ test_expect_success '--rebase' '
>  	git tag before-rebase &&
>  	git pull --rebase . copy &&
>  	test_cmp_rev HEAD^ copy &&
> -	test new = "$(git show HEAD:file2)"
> +	echo new >expect &&
> +	git show HEAD:file2 >actual &&
> +	test_cmp expect actual
>  '
>  
>  test_expect_success '--rebase fast forward' '
> @@ -330,7 +332,9 @@ test_expect_success '--rebase fails with multiple branches' '
>  	test_must_fail git pull --rebase . copy master 2>err &&
>  	test_cmp_rev HEAD before-rebase &&
>  	test_i18ngrep "Cannot rebase onto multiple branches" err &&
> -	test modified = "$(git show HEAD:file)"
> +	echo modified >expect &&
> +	git show HEAD:file >actual &&
> +	test_cmp expect actual
>  '
>  
>  test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
> @@ -381,7 +385,9 @@ test_expect_success 'pull.rebase' '
>  	test_config pull.rebase true &&
>  	git pull . copy &&
>  	test_cmp_rev HEAD^ copy &&
> -	test new = "$(git show HEAD:file2)"
> +	echo new >expect &&
> +	git show HEAD:file2 >actual &&
> +	test_cmp expect actual
>  '
>  
>  test_expect_success 'pull --autostash & pull.rebase=true' '
> @@ -399,7 +405,9 @@ test_expect_success 'branch.to-rebase.rebase' '
>  	test_config branch.to-rebase.rebase true &&
>  	git pull . copy &&
>  	test_cmp_rev HEAD^ copy &&
> -	test new = "$(git show HEAD:file2)"
> +	echo new >expect &&
> +	git show HEAD:file2 >actual &&
> +	test_cmp expect actual
>  '
>  
>  test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
> @@ -408,14 +416,18 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
>  	test_config branch.to-rebase.rebase false &&
>  	git pull . copy &&
>  	test_cmp_rev ! HEAD^ copy &&
> -	test new = "$(git show HEAD:file2)"
> +	echo new >expect &&
> +	git show HEAD:file2 >actual &&
> +	test_cmp expect actual
>  '
>  
>  test_expect_success 'pull --rebase warns on --verify-signatures' '
>  	git reset --hard before-rebase &&
>  	git pull --rebase --verify-signatures . copy 2>err &&
>  	test_cmp_rev HEAD^ copy &&
> -	test new = "$(git show HEAD:file2)" &&
> +	echo new >expect &&
> +	git show HEAD:file2 >actual &&
> +	test_cmp expect actual &&
>  	test_i18ngrep "ignoring --verify-signatures for rebase" err
>  '
>  
> @@ -423,7 +435,9 @@ test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
>  	git reset --hard before-rebase &&
>  	git pull --rebase --no-verify-signatures . copy 2>err &&
>  	test_cmp_rev HEAD^ copy &&
> -	test new = "$(git show HEAD:file2)" &&
> +	echo new >expect &&
> +	git show HEAD:file2 >actual &&
> +	test_cmp expect actual &&
>  	test_i18ngrep ! "verify-signatures" err
>  '
>  
> @@ -445,7 +459,9 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
>  	git pull . copy &&
>  	test_cmp_rev HEAD^1 before-preserve-rebase &&
>  	test_cmp_rev HEAD^2 copy &&
> -	test file3 = "$(git show HEAD:file3.t)"
> +	echo file3 >expect &&
> +	git show HEAD:file3.t >actual &&
> +	test_cmp expect actual
>  '
>  
>  test_expect_success 'pull.rebase=true flattens keep-merge' '
> @@ -453,7 +469,9 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
>  	test_config pull.rebase true &&
>  	git pull . copy &&
>  	test_cmp_rev HEAD^^ copy &&
> -	test file3 = "$(git show HEAD:file3.t)"
> +	echo file3 >expect &&
> +	git show HEAD:file3.t >actual &&
> +	test_cmp expect actual
>  '
>  
>  test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
> @@ -461,7 +479,9 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
>  	test_config pull.rebase 1 &&
>  	git pull . copy &&
>  	test_cmp_rev HEAD^^ copy &&
> -	test file3 = "$(git show HEAD:file3.t)"
> +	echo file3 >expect &&
> +	git show HEAD:file3.t >actual &&
> +	test_cmp expect actual
>  '
>  
>  test_expect_success REBASE_P \
> @@ -507,7 +527,9 @@ test_expect_success '--rebase=false create a new merge commit' '
>  	git pull --rebase=false . copy &&
>  	test_cmp_rev HEAD^1 before-preserve-rebase &&
>  	test_cmp_rev HEAD^2 copy &&
> -	test file3 = "$(git show HEAD:file3.t)"
> +	echo file3 >expect &&
> +	git show HEAD:file3.t >actual &&
> +	test_cmp expect actual
>  '
>  
>  test_expect_success '--rebase=true rebases and flattens keep-merge' '
> @@ -515,7 +537,9 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
>  	test_config pull.rebase preserve &&
>  	git pull --rebase=true . copy &&
>  	test_cmp_rev HEAD^^ copy &&
> -	test file3 = "$(git show HEAD:file3.t)"
> +	echo file3 >expect &&
> +	git show HEAD:file3.t >actual &&
> +	test_cmp expect actual
>  '
>  
>  test_expect_success REBASE_P \
> @@ -537,7 +561,9 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
>  	test_config pull.rebase preserve &&
>  	git pull --rebase . copy &&
>  	test_cmp_rev HEAD^^ copy &&
> -	test file3 = "$(git show HEAD:file3.t)"
> +	echo file3 >expect &&
> +	git show HEAD:file3.t >actual &&
> +	test_cmp expect actual
>  '
>  
>  test_expect_success '--rebase with rebased upstream' '
> @@ -622,10 +648,16 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
>  		cd empty_repo2 &&
>  		echo staged-file >staged-file &&
>  		git add staged-file &&
> -		test "$(git ls-files)" = staged-file &&
> +		echo staged-file >expect &&
> +		git ls-files >actual &&
> +		test_cmp expect actual &&
>  		test_must_fail git pull --rebase .. master 2>err &&
> -		test "$(git ls-files)" = staged-file &&
> -		test "$(git show :staged-file)" = staged-file &&
> +		echo staged-file >expect &&
> +		git ls-files >actual &&
> +		test_cmp expect actual &&
> +		echo staged-file >expect &&
> +		git show :staged-file >actual &&
> +		test_cmp expect actual &&
>  		test_i18ngrep "unborn branch with changes added to the index" err
>  	)
>  '

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

* Re: [PATCH v5 01/14] t: teach test_cmp_rev to accept ! for not-equals
  2019-11-12  0:13         ` [PATCH v5 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
@ 2019-11-12  6:52           ` Junio C Hamano
  2019-11-12 19:38             ` [PATCH] fixup! " Denton Liu
  0 siblings, 1 reply; 116+ messages in thread
From: Junio C Hamano @ 2019-11-12  6:52 UTC (permalink / raw)
  To: Denton Liu
  Cc: Git Mailing List, Eric Sunshine, Johannes Sixt, SZEDER Gábor

Denton Liu <liu.denton@gmail.com> writes:

> +# Tests that its two parameters refer to the same revision, or if '!' is
> +# provided first, that its other two parameters refer to different
> +# revisions.
>  test_cmp_rev () {
> +	local op
> +	op='='
> +	if test $# -ge 1 && test "x$1" = 'x!'
> +	then
> +	    op='!='
> +	    shift
> +	fi

Not that it is all that important, but how about setting up comp_out
up here at the same time?  I.e.


	local op comp_out

	if ...
	then
		op="!=" comp_out="the same"
		shift
	else
		op="=" comp_out=different
	fi

That way, we can lose 7 lines down there, while spending only one
line up here, collecting all the things that conditional on '!' on
the command line in one place.

I would have named the message variable "$wrong_result" or
something, by the way, i.e. "two revisions point to $wrong_result
objects".

Thanks.  Will queue the whole thing.

>  	if test $# != 2
>  	then
>  		error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
>  	else
>  		local r1 r2
>  		r1=$(git rev-parse --verify "$1") &&
> -		r2=$(git rev-parse --verify "$2") &&
> -		if test "$r1" != "$r2"
> +		r2=$(git rev-parse --verify "$2") || return 1
> +
> +		if ! test "$r1" "$op" "$r2"
>  		then
> +			local comp_out
> +			if "x$op" = 'x='
> +			then
> +				comp_out='different'
> +			else
> +				comp_out='the same'
> +			fi
>  			cat >&4 <<-EOF
> -			error: two revisions point to different objects:
> +			error: two revisions point to $comp_out objects:
>  			  '$1': $r1
>  			  '$2': $r2
>  			EOF

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

* [PATCH] fixup! t: teach test_cmp_rev to accept ! for not-equals
  2019-11-12  6:52           ` Junio C Hamano
@ 2019-11-12 19:38             ` Denton Liu
  0 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 19:38 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
Thanks for the suggestion, Junio. Since it's just a minor cleanup,
here's the fixup patch for it.

 t/test-lib-functions.sh | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 01cdbb0478..15f4c96777 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1016,11 +1016,13 @@ test_must_be_empty () {
 # provided first, that its other two parameters refer to different
 # revisions.
 test_cmp_rev () {
-	local op
+	local op wrong_result
 	op='='
+	wrong_result='different'
 	if test $# -ge 1 && test "x$1" = 'x!'
 	then
 	    op='!='
+	    wrong_result='the same'
 	    shift
 	fi
 	if test $# != 2
@@ -1033,15 +1035,8 @@ test_cmp_rev () {
 
 		if ! test "$r1" "$op" "$r2"
 		then
-			local comp_out
-			if "x$op" = 'x='
-			then
-				comp_out='different'
-			else
-				comp_out='the same'
-			fi
 			cat >&4 <<-EOF
-			error: two revisions point to $comp_out objects:
+			error: two revisions point to $wrong_result objects:
 			  '$1': $r1
 			  '$2': $r2
 			EOF
-- 
2.24.0.300.g722ba42680


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

* Re: [PATCH v5 10/14] t5520: test single-line files by git with test_cmp
  2019-11-12  5:17           ` Junio C Hamano
@ 2019-11-12 23:06             ` Denton Liu
  0 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:06 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Eric Sunshine, Johannes Sixt, SZEDER Gábor

Hi Junio,

On Tue, Nov 12, 2019 at 02:17:33PM +0900, Junio C Hamano wrote:
> Denton Liu <liu.denton@gmail.com> writes:
> 
> > In case an invocation of a Git command fails within the subshell, the
> > failure will be masked. Replace the subshell with a file-redirection and
> > a call to test_cmp.
> 
> I.e.
> 
>     test "$(git cmd args)" = "expected-string"
> 
> =>
> 
>     git cmd args >actual && echo "expected-string" >expect &&
>     test_cmp expect actual
> 
> which makes sense.  It may break if expected-string begins with a
> dash or something silly like that, but a quick eyeballing over the
> patch tells me that we are safe there.
> 
> Technically, "$(git cmd args)" used as a command line option of
> another command is called "command substitution", not "subshell".
> The proposed log message may need to be updated.

Okay, I'll send out a new reroll with some log message cleanup.

> 
> > This change was done with the following GNU sed expressions:
> >
> > 	s/\(\s*\)test \([^ ]*\) = "$(\(git [^)]*\))"/\1echo \2 >expect \&\&\n\1\3 >actual \&\&\n\1test_cmp expect actual/
> > 	s/\(\s*\)test "$(\(git [^)]*\))" = \([^ ]*\)/\1echo \3 >expect \&\&\n\1\2 >actual \&\&\n\1test_cmp expect actual/
> >
> > A future patch will clean up situations where we have multiple duplicate
> > statements within a test case. This is done to keep this patch purely
> > mechanical.
> 
> OK.  One thing that worries me is if the existing tests are not
> expecting (no pun intended) to see 'expect' or 'actual' (e.g. if
> they somehow rely on output of "ls-files -u", we are now adding two
> untracked files in the working tree).

Do you mean `ls-files -o`? I think `-u` means "unmerged" while `-o`
means "others" (or "untracked"). This test doesn't have any instances of
`-o` being used.

> Another is if the git command
> is expected to produce nothing, possibly after failing, and the test
> is expecting to see an empty string---in such a case, the hiding of
> the exit status would have been intentional ;-)  We'd want to be sure
> that we aren't breaking the tests like that by reading through the
> result of applying this patch.
> 
> Since this is just a single file, I trust you have already done such
> sanity checking ;-)

Thanks for double-checking on me. I have, indeed, manually verified the
changes.

> 
> The mechanical conversion procedure itself looks OK.
> 
> Thanks.

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

* [PATCH v6 00/14] t5520: various test cleanup
  2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
                           ` (13 preceding siblings ...)
  2019-11-12  0:14         ` [PATCH v5 14/14] t5520: replace `! git` with `test_must_fail git` Denton Liu
@ 2019-11-12 23:07         ` Denton Liu
  2019-11-12 23:07           ` [PATCH v6 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
                             ` (14 more replies)
  14 siblings, 15 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:07 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Thanks for the comments on the last round, Junio.

Please ignore the fixup patch from earlier, it has been bundled into
this reroll.


Like earlier patchsets, I want to implement a feature that involves
modifications to the test suite. Since that feature will probably take a
while to polish up, however, let's clean up the test suite in a separate
patchset first so it's not blocked by the feature work.

1/15 is a general improvement to test_rev_cmp() that will be used later
in the series.

Changes since v5:

* More test_cmp_rev() cleanup

* Changed instances of "subshell" to "command substitution" where appropriate

* Change instances of "Git" to "git" when we are referring to the command

Changes since v4:

* Cleaned up test_cmp_rev() logic with suggestions from Junio

Changes since v3:

* Rebased and tested on top of v2.24.0

Changes since v2:

* Drop 't7408: replace `test_must_fail test_path_is_file`' since it's
  not a rabbit hole we want to go into right now

* Fix the output of `test_cmp_rev !` when revs are actually equal

* Rebase against the latest master since this topic hasn't been picked
  up yet

Changes since v1:

* Incorporate Eric's feedback

Denton Liu (14):
  t: teach test_cmp_rev to accept ! for not-equals
  t5520: improve test style
  t5520: use sq for test case names
  t5520: let sed open its own input
  t5520: replace test -f with test-lib functions
  t5520: remove spaces after redirect operator
  t5520: use test_line_count where possible
  t5520: replace test -{n,z} with test-lib functions
  t5520: use test_cmp_rev where possible
  t5520: test single-line files by git with test_cmp
  t5520: don't put git in upstream of pipe
  t5520: replace $(cat ...) comparison with test_cmp
  t5520: remove redundant lines in test cases
  t5520: replace `! git` with `test_must_fail git`

 t/t2400-worktree-add.sh             |   4 +-
 t/t3400-rebase.sh                   |   2 +-
 t/t3421-rebase-topology-linear.sh   |   6 +-
 t/t3430-rebase-merges.sh            |   2 +-
 t/t3432-rebase-fast-forward.sh      |   2 +-
 t/t3501-revert-cherry-pick.sh       |   2 +-
 t/t3508-cherry-pick-many-commits.sh |   2 +-
 t/t5520-pull.sh                     | 343 +++++++++++++++++-----------
 t/test-lib-functions.sh             |  20 +-
 9 files changed, 231 insertions(+), 152 deletions(-)

Range-diff against v5:
 1:  85fac754e2 !  1:  0532847787 t: teach test_cmp_rev to accept ! for not-equals
    @@ t/test-lib-functions.sh: test_must_be_empty () {
     +# provided first, that its other two parameters refer to different
     +# revisions.
      test_cmp_rev () {
    -+	local op
    ++	local op wrong_result
     +	op='='
    ++	wrong_result='different'
     +	if test $# -ge 1 && test "x$1" = 'x!'
     +	then
     +	    op='!='
    ++	    wrong_result='the same'
     +	    shift
     +	fi
      	if test $# != 2
    @@ t/test-lib-functions.sh: test_must_be_empty () {
     +
     +		if ! test "$r1" "$op" "$r2"
      		then
    -+			local comp_out
    -+			if "x$op" = 'x='
    -+			then
    -+				comp_out='different'
    -+			else
    -+				comp_out='the same'
    -+			fi
      			cat >&4 <<-EOF
     -			error: two revisions point to different objects:
    -+			error: two revisions point to $comp_out objects:
    ++			error: two revisions point to $wrong_result objects:
      			  '$1': $r1
      			  '$2': $r2
      			EOF
 2:  2b1caec3d7 =  2:  aa3f2e3395 t5520: improve test style
 3:  1aa0cdad1c =  3:  99b0fb0e1c t5520: use sq for test case names
 4:  edd4446554 =  4:  0660aa3fff t5520: let sed open its own input
 5:  c5d5966405 =  5:  00b7143b30 t5520: replace test -f with test-lib functions
 6:  6a99400ba4 =  6:  c451940c5b t5520: remove spaces after redirect operator
 7:  b7b66b13f6 =  7:  8e1c90eb70 t5520: use test_line_count where possible
 8:  07517c868c !  8:  8043b230a7 t5520: replace test -{n,z} with test-lib functions
    @@ Metadata
      ## Commit message ##
         t5520: replace test -{n,z} with test-lib functions
     
    -    When wrapping a Git command in a subshell within another command, we
    -    throw away the Git command's exit code. In case the Git command fails,
    -    we would like to know about it rather than the failure being silent.
    -    Extract Git commands so that their exit codes are not lost.
    +    When wrapping a git command in a command substitution within another
    +    command, we throw away the git command's exit code. In case the git
    +    command fails, we would like to know about it rather than the failure
    +    being silent. Extract git commands so that their exit codes are not
    +    lost.
     
         Instead of using `test -n` or `test -z`, replace them respectively with
         invocations of test_file_not_empty() and test_must_be_empty() so that we
 9:  29d9ff3b21 !  9:  7f5347bb40 t5520: use test_cmp_rev where possible
    @@ Metadata
      ## Commit message ##
         t5520: use test_cmp_rev where possible
     
    -    In case an invocation of `git rev-list` fails within the subshell, the
    -    failure will be masked. Remove the subshell and use test_cmp_rev() so
    -    that failures can be discovered.
    +    In case an invocation of `git rev-list` fails within the command
    +    substitution, the failure will be masked. Remove the command
    +    substitution and use test_cmp_rev() so that failures can be discovered.
     
         This change was done with the following sed expressions:
     
10:  aeaa3374a7 ! 10:  73004d6cc3 t5520: test single-line files by git with test_cmp
    @@ Metadata
      ## Commit message ##
         t5520: test single-line files by git with test_cmp
     
    -    In case an invocation of a Git command fails within the subshell, the
    -    failure will be masked. Replace the subshell with a file-redirection and
    -    a call to test_cmp.
    +    In case an invocation of a git command fails within the command
    +    substitution, the failure will be masked. Replace the command
    +    substitution with a file-redirection and a call to test_cmp.
     
         This change was done with the following GNU sed expressions:
     
11:  131609fc5c ! 11:  463f5c11b9 t5520: don't put git in upstream of pipe
    @@ Commit message
     
         Before, if the invocation of git failed, it would be masked by the pipe
         since only the return code of the last element of a pipe is used.
    -    Rewrite the test to put the Git command on its own line so its return
    +    Rewrite the test to put the git command on its own line so its return
         code is not masked.
     
      ## t/t5520-pull.sh ##
12:  c67be3d18c ! 12:  67ea3f0238 t5520: replace subshell cat comparison with test_cmp
    @@ Metadata
     Author: Denton Liu <liu.denton@gmail.com>
     
      ## Commit message ##
    -    t5520: replace subshell cat comparison with test_cmp
    +    t5520: replace $(cat ...) comparison with test_cmp
     
         We currently have many instances of `test <line> = $(cat <file>)` and
         `test $(cat <file>) = <line>`.  In the case where this fails, it will be
13:  04ef898857 = 13:  b45c088d20 t5520: remove redundant lines in test cases
14:  153ff07dc0 ! 14:  c605afa537 t5520: replace `! git` with `test_must_fail git`
    @@ Metadata
      ## Commit message ##
         t5520: replace `! git` with `test_must_fail git`
     
    -    Currently, if a Git command fails in an unexpected way, such as a
    +    Currently, if a git command fails in an unexpected way, such as a
         segfault, it will be masked and ignored. Replace the ! with
         test_must_fail so that only expected failures pass.
     
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 01/14] t: teach test_cmp_rev to accept ! for not-equals
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
@ 2019-11-12 23:07           ` Denton Liu
  2019-11-13  1:57             ` Junio C Hamano
  2019-11-12 23:07           ` [PATCH v6 02/14] t5520: improve test style Denton Liu
                             ` (13 subsequent siblings)
  14 siblings, 1 reply; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:07 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

In the case where we are using test_cmp_rev() to report not-equals, we
write `! test_cmp_rev`. However, since test_cmp_rev() contains

	r1=$(git rev-parse --verify "$1") &&
	r2=$(git rev-parse --verify "$2") &&

`! test_cmp_rev` will succeed if any of the rev-parses fail. This
behavior is not desired. We want the rev-parses to _always_ be
successful.

Rewrite test_cmp_rev() to optionally accept "!" as the first argument to
do a not-equals comparison. Rewrite `! test_cmp_rev` to `test_cmp_rev !`
in all tests to take advantage of this new functionality.

Also, rewrite the rev-parse logic to end with a `|| return 1` instead of
&&-chaining into the rev-comparison logic. This makes it obvious to
future readers that we explicitly intend on returning early if either of
the rev-parses fail.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t2400-worktree-add.sh             |  4 ++--
 t/t3400-rebase.sh                   |  2 +-
 t/t3421-rebase-topology-linear.sh   |  6 +++---
 t/t3430-rebase-merges.sh            |  2 +-
 t/t3432-rebase-fast-forward.sh      |  2 +-
 t/t3501-revert-cherry-pick.sh       |  2 +-
 t/t3508-cherry-pick-many-commits.sh |  2 +-
 t/test-lib-functions.sh             | 20 ++++++++++++++++----
 8 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index e819ba741e..52d476979b 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -438,7 +438,7 @@ test_expect_success 'git worktree add does not match remote' '
 		cd foo &&
 		test_must_fail git config "branch.foo.remote" &&
 		test_must_fail git config "branch.foo.merge" &&
-		! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
+		test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
 	)
 '
 
@@ -483,7 +483,7 @@ test_expect_success 'git worktree --no-guess-remote option overrides config' '
 		cd foo &&
 		test_must_fail git config "branch.foo.remote" &&
 		test_must_fail git config "branch.foo.merge" &&
-		! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
+		test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
 	)
 '
 
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index ab18ac5f28..f267f6cd54 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -64,7 +64,7 @@ test_expect_success 'rebase sets ORIG_HEAD to pre-rebase state' '
 	pre="$(git rev-parse --verify HEAD)" &&
 	git rebase master &&
 	test_cmp_rev "$pre" ORIG_HEAD &&
-	! test_cmp_rev "$pre" HEAD
+	test_cmp_rev ! "$pre" HEAD
 '
 
 test_expect_success 'rebase, with <onto> and <upstream> specified as :/quuxery' '
diff --git a/t/t3421-rebase-topology-linear.sh b/t/t3421-rebase-topology-linear.sh
index b847064f91..325072b0a3 100755
--- a/t/t3421-rebase-topology-linear.sh
+++ b/t/t3421-rebase-topology-linear.sh
@@ -61,7 +61,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" "
 		reset_rebase &&
 		git rebase $* -f b e &&
-		! test_cmp_rev e HEAD &&
+		test_cmp_rev ! e HEAD &&
 		test_cmp_rev b HEAD~2 &&
 		test_linear_range 'd e' b..
 	"
@@ -78,7 +78,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
 		reset_rebase &&
 		git rebase $* -f branch-b branch-e &&
-		! test_cmp_rev branch-e origin/branch-e &&
+		test_cmp_rev ! branch-e origin/branch-e &&
 		test_cmp_rev branch-b HEAD~2 &&
 		test_linear_range 'd e' branch-b..
 	"
@@ -368,7 +368,7 @@ test_run_rebase () {
 	test_expect_$result "rebase $* -f --root on linear history causes re-write" "
 		reset_rebase &&
 		git rebase $* -f --root c &&
-		! test_cmp_rev a HEAD~2 &&
+		test_cmp_rev ! a HEAD~2 &&
 		test_linear_range 'a b c' HEAD
 	"
 }
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index 9efcf4808a..abbdc26b1b 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -346,7 +346,7 @@ test_expect_success 'A root commit can be a cousin, treat it that way' '
 	git merge --allow-unrelated-histories khnum &&
 	test_tick &&
 	git rebase -f -r HEAD^ &&
-	! test_cmp_rev HEAD^2 khnum &&
+	test_cmp_rev ! HEAD^2 khnum &&
 	test_cmp_graph HEAD^.. <<-\EOF &&
 	*   Merge branch '\''khnum'\'' into asherah
 	|\
diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh
index 034ffc7e76..92f95b57da 100755
--- a/t/t3432-rebase-fast-forward.sh
+++ b/t/t3432-rebase-fast-forward.sh
@@ -64,7 +64,7 @@ test_rebase_same_head_ () {
 			test_cmp_rev \$oldhead \$newhead
 		elif test $cmp = diff
 		then
-			! test_cmp_rev \$oldhead \$newhead
+			test_cmp_rev ! \$oldhead \$newhead
 		fi
 	"
 }
diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh
index d1c68af8c5..1c51a9131d 100755
--- a/t/t3501-revert-cherry-pick.sh
+++ b/t/t3501-revert-cherry-pick.sh
@@ -106,7 +106,7 @@ test_expect_success 'cherry-pick on unborn branch' '
 	rm -rf * &&
 	git cherry-pick initial &&
 	git diff --quiet initial &&
-	! test_cmp_rev initial HEAD
+	test_cmp_rev ! initial HEAD
 '
 
 test_expect_success 'cherry-pick "-" to pick from previous branch' '
diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh
index b457333e18..23070a7b73 100755
--- a/t/t3508-cherry-pick-many-commits.sh
+++ b/t/t3508-cherry-pick-many-commits.sh
@@ -5,7 +5,7 @@ test_description='test cherry-picking many commits'
 . ./test-lib.sh
 
 check_head_differs_from() {
-	! test_cmp_rev HEAD "$1"
+	test_cmp_rev ! HEAD "$1"
 }
 
 check_head_equals() {
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b299ecc326..15f4c96777 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1012,19 +1012,31 @@ test_must_be_empty () {
 	fi
 }
 
-# Tests that its two parameters refer to the same revision
+# Tests that its two parameters refer to the same revision, or if '!' is
+# provided first, that its other two parameters refer to different
+# revisions.
 test_cmp_rev () {
+	local op wrong_result
+	op='='
+	wrong_result='different'
+	if test $# -ge 1 && test "x$1" = 'x!'
+	then
+	    op='!='
+	    wrong_result='the same'
+	    shift
+	fi
 	if test $# != 2
 	then
 		error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
 	else
 		local r1 r2
 		r1=$(git rev-parse --verify "$1") &&
-		r2=$(git rev-parse --verify "$2") &&
-		if test "$r1" != "$r2"
+		r2=$(git rev-parse --verify "$2") || return 1
+
+		if ! test "$r1" "$op" "$r2"
 		then
 			cat >&4 <<-EOF
-			error: two revisions point to different objects:
+			error: two revisions point to $wrong_result objects:
 			  '$1': $r1
 			  '$2': $r2
 			EOF
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 02/14] t5520: improve test style
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
  2019-11-12 23:07           ` [PATCH v6 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
@ 2019-11-12 23:07           ` Denton Liu
  2019-11-12 23:07           ` [PATCH v6 03/14] t5520: use sq for test case names Denton Liu
                             ` (12 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:07 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Improve the test style by removing leading and trailing empty lines
within test cases. Also, reformat multi-line subshells to conform to the
existing style.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 88 +++++++++++++++++++++++++------------------------
 1 file changed, 45 insertions(+), 43 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index cf4cc32fd0..51d6ce8aec 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -538,7 +538,6 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 '
 
 test_expect_success '--rebase with rebased upstream' '
-
 	git remote add -f me . &&
 	git checkout copy &&
 	git tag copy-orig &&
@@ -552,7 +551,6 @@ test_expect_success '--rebase with rebased upstream' '
 	git pull --rebase me copy &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = "$(cat file2)"
-
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
@@ -564,14 +562,12 @@ test_expect_success '--rebase -f with rebased upstream' '
 '
 
 test_expect_success '--rebase with rebased default upstream' '
-
 	git update-ref refs/remotes/me/copy copy-orig &&
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
 	test "conflicting modification" = "$(cat file)" &&
 	test file = "$(cat file2)"
-
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -588,7 +584,6 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 '
 
 test_expect_success 'pull --rebase dies early with dirty working directory' '
-
 	git checkout to-rebase &&
 	git update-ref refs/remotes/me/copy copy^ &&
 	COPY="$(git rev-parse --verify me/copy)" &&
@@ -603,16 +598,16 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	git checkout HEAD -- file &&
 	git pull &&
 	test "$COPY" != "$(git rev-parse --verify me/copy)"
-
 '
 
 test_expect_success 'pull --rebase works on branch yet to be born' '
 	git rev-parse master >expect &&
 	mkdir empty_repo &&
-	(cd empty_repo &&
-	 git init &&
-	 git pull --rebase .. master &&
-	 git rev-parse HEAD >../actual
+	(
+		cd empty_repo &&
+		git init &&
+		git pull --rebase .. master &&
+		git rev-parse HEAD >../actual
 	) &&
 	test_cmp expect actual
 '
@@ -646,58 +641,65 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 
 test_expect_success 'setup for detecting upstreamed changes' '
 	mkdir src &&
-	(cd src &&
-	 git init &&
-	 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
-	 git add stuff &&
-	 git commit -m "Initial revision"
+	(
+		cd src &&
+		git init &&
+		printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
+		git add stuff &&
+		git commit -m "Initial revision"
 	) &&
 	git clone src dst &&
-	(cd src &&
-	 modify s/5/43/ stuff &&
-	 git commit -a -m "5->43" &&
-	 modify s/6/42/ stuff &&
-	 git commit -a -m "Make it bigger"
+	(
+		cd src &&
+		modify s/5/43/ stuff &&
+		git commit -a -m "5->43" &&
+		modify s/6/42/ stuff &&
+		git commit -a -m "Make it bigger"
 	) &&
-	(cd dst &&
-	 modify s/5/43/ stuff &&
-	 git commit -a -m "Independent discovery of 5->43"
+	(
+		cd dst &&
+		modify s/5/43/ stuff &&
+		git commit -a -m "Independent discovery of 5->43"
 	)
 '
 
 test_expect_success 'git pull --rebase detects upstreamed changes' '
-	(cd dst &&
-	 git pull --rebase &&
-	 test -z "$(git ls-files -u)"
+	(
+		cd dst &&
+		git pull --rebase &&
+		test -z "$(git ls-files -u)"
 	)
 '
 
 test_expect_success 'setup for avoiding reapplying old patches' '
-	(cd dst &&
-	 test_might_fail git rebase --abort &&
-	 git reset --hard origin/master
+	(
+		cd dst &&
+		test_might_fail git rebase --abort &&
+		git reset --hard origin/master
 	) &&
 	git clone --bare src src-replace.git &&
 	rm -rf src &&
 	mv src-replace.git src &&
-	(cd dst &&
-	 modify s/2/22/ stuff &&
-	 git commit -a -m "Change 2" &&
-	 modify s/3/33/ stuff &&
-	 git commit -a -m "Change 3" &&
-	 modify s/4/44/ stuff &&
-	 git commit -a -m "Change 4" &&
-	 git push &&
-
-	 modify s/44/55/ stuff &&
-	 git commit --amend -a -m "Modified Change 4"
+	(
+		cd dst &&
+		modify s/2/22/ stuff &&
+		git commit -a -m "Change 2" &&
+		modify s/3/33/ stuff &&
+		git commit -a -m "Change 3" &&
+		modify s/4/44/ stuff &&
+		git commit -a -m "Change 4" &&
+		git push &&
+
+		modify s/44/55/ stuff &&
+		git commit --amend -a -m "Modified Change 4"
 	)
 '
 
 test_expect_success 'git pull --rebase does not reapply old patches' '
-	(cd dst &&
-	 test_must_fail git pull --rebase &&
-	 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+	(
+		cd dst &&
+		test_must_fail git pull --rebase &&
+		test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
 	)
 '
 
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 03/14] t5520: use sq for test case names
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
  2019-11-12 23:07           ` [PATCH v6 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
  2019-11-12 23:07           ` [PATCH v6 02/14] t5520: improve test style Denton Liu
@ 2019-11-12 23:07           ` Denton Liu
  2019-11-12 23:07           ` [PATCH v6 04/14] t5520: let sed open its own input Denton Liu
                             ` (11 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:07 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

The usual convention is for test case names to be written between
single-quotes. Change all double-quoted test case names to single-quotes
except for two test case names that use variables within.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 51d6ce8aec..a3de2e19b6 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -408,7 +408,7 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test new = "$(git show HEAD:file2)"
 '
 
-test_expect_success "pull --rebase warns on --verify-signatures" '
+test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
 	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
@@ -416,7 +416,7 @@ test_expect_success "pull --rebase warns on --verify-signatures" '
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
 
-test_expect_success "pull --rebase does not warn on --no-verify-signatures" '
+test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
 	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 04/14] t5520: let sed open its own input
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
                             ` (2 preceding siblings ...)
  2019-11-12 23:07           ` [PATCH v6 03/14] t5520: use sq for test case names Denton Liu
@ 2019-11-12 23:07           ` Denton Liu
  2019-11-12 23:07           ` [PATCH v6 05/14] t5520: replace test -f with test-lib functions Denton Liu
                             ` (10 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:07 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

We were using a redirection operator to feed input into sed. However,
since sed is capable of opening its own files, make sed open its own
files instead of redirecting input into it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a3de2e19b6..55560ce3cd 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -5,7 +5,7 @@ test_description='pulling into void'
 . ./test-lib.sh
 
 modify () {
-	sed -e "$1" <"$2" >"$2.x" &&
+	sed -e "$1" "$2" >"$2.x" &&
 	mv "$2.x" "$2"
 }
 
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 05/14] t5520: replace test -f with test-lib functions
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
                             ` (3 preceding siblings ...)
  2019-11-12 23:07           ` [PATCH v6 04/14] t5520: let sed open its own input Denton Liu
@ 2019-11-12 23:07           ` Denton Liu
  2019-11-12 23:07           ` [PATCH v6 06/14] t5520: remove spaces after redirect operator Denton Liu
                             ` (9 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:07 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Although `test -f` has the same functionality as test_path_is_file(), in
the case where test_path_is_file() fails, we get much better debugging
information.

Replace `test -f` with test_path_is_file() so that future developers
will have a better experience debugging these test cases.

Also, in the case of `! test -f`, not only should that path not be a
file, it shouldn't exist at all so replace it with
test_path_is_missing().

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 55560ce3cd..004d5884cd 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -39,8 +39,8 @@ test_expect_success 'pulling into void' '
 		cd cloned &&
 		git pull ..
 	) &&
-	test -f file &&
-	test -f cloned/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned/file &&
 	test_cmp file cloned/file
 '
 
@@ -50,8 +50,8 @@ test_expect_success 'pulling into void using master:master' '
 		cd cloned-uho &&
 		git pull .. master:master
 	) &&
-	test -f file &&
-	test -f cloned-uho/file &&
+	test_path_is_file file &&
+	test_path_is_file cloned-uho/file &&
 	test_cmp file cloned-uho/file
 '
 
@@ -99,7 +99,7 @@ test_expect_success 'pulling into void must not create an octopus' '
 	(
 		cd cloned-octopus &&
 		test_must_fail git pull .. master master &&
-		! test -f file
+		test_path_is_missing file
 	)
 '
 
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 06/14] t5520: remove spaces after redirect operator
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
                             ` (4 preceding siblings ...)
  2019-11-12 23:07           ` [PATCH v6 05/14] t5520: replace test -f with test-lib functions Denton Liu
@ 2019-11-12 23:07           ` Denton Liu
  2019-11-12 23:08           ` [PATCH v6 07/14] t5520: use test_line_count where possible Denton Liu
                             ` (8 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:07 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

The style for tests in Git is to have the redirect operator attached to
the filename with no spaces. Fix test cases where this is not the case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 004d5884cd..7bb9031140 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -243,10 +243,10 @@ test_expect_success 'fast-forward fails with conflicting work tree' '
 
 test_expect_success '--rebase' '
 	git branch to-rebase &&
-	echo modified again > file &&
+	echo modified again >file &&
 	git commit -m file file &&
 	git checkout to-rebase &&
-	echo new > file2 &&
+	echo new >file2 &&
 	git add file2 &&
 	git commit -m "new file" &&
 	git tag before-rebase &&
@@ -542,10 +542,10 @@ test_expect_success '--rebase with rebased upstream' '
 	git checkout copy &&
 	git tag copy-orig &&
 	git reset --hard HEAD^ &&
-	echo conflicting modification > file &&
+	echo conflicting modification >file &&
 	git commit -m conflict file &&
 	git checkout to-rebase &&
-	echo file > file2 &&
+	echo file >file2 &&
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
@@ -591,7 +591,7 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	test_config branch.to-rebase.remote me &&
 	test_config branch.to-rebase.merge refs/heads/copy &&
 	test_config branch.to-rebase.rebase true &&
-	echo dirty >> file &&
+	echo dirty >>file &&
 	git add file &&
 	test_must_fail git pull &&
 	test "$COPY" = "$(git rev-parse --verify me/copy)" &&
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 07/14] t5520: use test_line_count where possible
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
                             ` (5 preceding siblings ...)
  2019-11-12 23:07           ` [PATCH v6 06/14] t5520: remove spaces after redirect operator Denton Liu
@ 2019-11-12 23:08           ` Denton Liu
  2019-11-12 23:08           ` [PATCH v6 08/14] t5520: replace test -{n,z} with test-lib functions Denton Liu
                             ` (7 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:08 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Instead of rolling our own functionality to test the number of lines a
command outputs, use test_line_count() which provides better debugging
information in the case of a failure.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 7bb9031140..0ca4867e96 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -699,7 +699,8 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 	(
 		cd dst &&
 		test_must_fail git pull --rebase &&
-		test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
+		find .git/rebase-apply -name "000*" >patches &&
+		test_line_count = 1 patches
 	)
 '
 
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 08/14] t5520: replace test -{n,z} with test-lib functions
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
                             ` (6 preceding siblings ...)
  2019-11-12 23:08           ` [PATCH v6 07/14] t5520: use test_line_count where possible Denton Liu
@ 2019-11-12 23:08           ` Denton Liu
  2019-11-12 23:08           ` [PATCH v6 09/14] t5520: use test_cmp_rev where possible Denton Liu
                             ` (6 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:08 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

When wrapping a git command in a command substitution within another
command, we throw away the git command's exit code. In case the git
command fails, we would like to know about it rather than the failure
being silent. Extract git commands so that their exit codes are not
lost.

Instead of using `test -n` or `test -z`, replace them respectively with
invocations of test_file_not_empty() and test_must_be_empty() so that we
get better debugging information in the case of a failure.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 0ca4867e96..18225d8430 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -206,15 +206,18 @@ test_expect_success 'fail if the index has unresolved entries' '
 	test_when_finished "git checkout -f copy && git branch -D third" &&
 	test "$(cat file)" = file &&
 	test_commit modified2 file &&
-	test -z "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_must_be_empty unmerged &&
 	test_must_fail git pull . second &&
-	test -n "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_file_not_empty unmerged &&
 	cp file expected &&
 	test_must_fail git pull . second 2>err &&
 	test_i18ngrep "Pulling is not possible because you have unmerged files." err &&
 	test_cmp expected file &&
 	git add file &&
-	test -z "$(git ls-files -u)" &&
+	git ls-files -u >unmerged &&
+	test_must_be_empty unmerged &&
 	test_must_fail git pull . second 2>err &&
 	test_i18ngrep "You have not concluded your merge" err &&
 	test_cmp expected file
@@ -667,7 +670,8 @@ test_expect_success 'git pull --rebase detects upstreamed changes' '
 	(
 		cd dst &&
 		git pull --rebase &&
-		test -z "$(git ls-files -u)"
+		git ls-files -u >untracked &&
+		test_must_be_empty untracked
 	)
 '
 
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 09/14] t5520: use test_cmp_rev where possible
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
                             ` (7 preceding siblings ...)
  2019-11-12 23:08           ` [PATCH v6 08/14] t5520: replace test -{n,z} with test-lib functions Denton Liu
@ 2019-11-12 23:08           ` Denton Liu
  2019-11-12 23:08           ` [PATCH v6 10/14] t5520: test single-line files by git with test_cmp Denton Liu
                             ` (5 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:08 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

In case an invocation of `git rev-list` fails within the command
substitution, the failure will be masked. Remove the command
substitution and use test_cmp_rev() so that failures can be discovered.

This change was done with the following sed expressions:

	s/test "$(git rev-parse.* \([^)]*\))" = "$(git rev-parse \([^)]*\))"/test_cmp_rev \1 \2/
	s/test \([^ ]*\) = "$(git rev-parse.* \([^)]*\))"/test_cmp_rev \1 \2/
	s/test "$(git rev-parse.* \([^)]*\))" != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/
	s/test \([^ ]*\) != "$(git rev-parse.* \([^)]*\))"/test_cmp_rev ! \1 \2/

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 50 ++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 18225d8430..1af6ea06ee 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -230,7 +230,7 @@ test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
 	test "$(cat file)" = modified &&
-	test "$(git rev-parse third)" = "$(git rev-parse second)"
+	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
@@ -241,7 +241,7 @@ test_expect_success 'fast-forward fails with conflicting work tree' '
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
 	test "$(cat file)" = conflict &&
-	test "$(git rev-parse third)" = "$(git rev-parse second)"
+	test_cmp_rev third second
 '
 
 test_expect_success '--rebase' '
@@ -254,7 +254,7 @@ test_expect_success '--rebase' '
 	git commit -m "new file" &&
 	git tag before-rebase &&
 	git pull --rebase . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -266,7 +266,7 @@ test_expect_success '--rebase fast forward' '
 
 	git checkout to-rebase &&
 	git pull --rebase . ff &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse ff)" &&
+	test_cmp_rev HEAD ff &&
 
 	# The above only validates the result.  Did we actually bypass rebase?
 	git reflog -1 >reflog.actual &&
@@ -290,7 +290,7 @@ test_expect_success '--rebase --autostash fast forward' '
 	git checkout behind &&
 	echo dirty >file &&
 	git pull --rebase --autostash . to-rebase-ff &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse to-rebase-ff)"
+	test_cmp_rev HEAD to-rebase-ff
 '
 
 test_expect_success '--rebase with conflicts shows advice' '
@@ -328,7 +328,7 @@ test_expect_success 'failed --rebase shows advice' '
 test_expect_success '--rebase fails with multiple branches' '
 	git reset --hard before-rebase &&
 	test_must_fail git pull --rebase . copy master 2>err &&
-	test "$(git rev-parse HEAD)" = "$(git rev-parse before-rebase)" &&
+	test_cmp_rev HEAD before-rebase &&
 	test_i18ngrep "Cannot rebase onto multiple branches" err &&
 	test modified = "$(git show HEAD:file)"
 '
@@ -380,7 +380,7 @@ test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -398,7 +398,7 @@ test_expect_success 'branch.to-rebase.rebase' '
 	git reset --hard before-rebase &&
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
@@ -407,14 +407,14 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_config pull.rebase true &&
 	test_config branch.to-rebase.rebase false &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
+	test_cmp_rev ! HEAD^ copy &&
 	test new = "$(git show HEAD:file2)"
 '
 
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)" &&
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
@@ -422,7 +422,7 @@ test_expect_success 'pull --rebase warns on --verify-signatures' '
 test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
-	test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^ copy &&
 	test new = "$(git show HEAD:file2)" &&
 	test_i18ngrep ! "verify-signatures" err
 '
@@ -443,8 +443,8 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase false &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^1 before-preserve-rebase &&
+	test_cmp_rev HEAD^2 copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -452,7 +452,7 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -460,7 +460,7 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase 1 &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -469,8 +469,8 @@ test_expect_success REBASE_P \
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
+	test_cmp_rev HEAD^^ copy &&
+	test_cmp_rev HEAD^2 keep-merge
 '
 
 test_expect_success 'pull.rebase=interactive' '
@@ -505,8 +505,8 @@ test_expect_success '--rebase=false create a new merge commit' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull --rebase=false . copy &&
-	test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^1 before-preserve-rebase &&
+	test_cmp_rev HEAD^2 copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -514,7 +514,7 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull --rebase=true . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -523,8 +523,8 @@ test_expect_success REBASE_P \
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull --rebase=preserve . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
-	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
+	test_cmp_rev HEAD^^ copy &&
+	test_cmp_rev HEAD^2 keep-merge
 '
 
 test_expect_success '--rebase=invalid fails' '
@@ -536,7 +536,7 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull --rebase . copy &&
-	test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
+	test_cmp_rev HEAD^^ copy &&
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
@@ -597,10 +597,10 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
 	echo dirty >>file &&
 	git add file &&
 	test_must_fail git pull &&
-	test "$COPY" = "$(git rev-parse --verify me/copy)" &&
+	test_cmp_rev "$COPY" me/copy &&
 	git checkout HEAD -- file &&
 	git pull &&
-	test "$COPY" != "$(git rev-parse --verify me/copy)"
+	test_cmp_rev ! "$COPY" me/copy
 '
 
 test_expect_success 'pull --rebase works on branch yet to be born' '
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 10/14] t5520: test single-line files by git with test_cmp
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
                             ` (8 preceding siblings ...)
  2019-11-12 23:08           ` [PATCH v6 09/14] t5520: use test_cmp_rev where possible Denton Liu
@ 2019-11-12 23:08           ` Denton Liu
  2019-11-12 23:08           ` [PATCH v6 11/14] t5520: don't put git in upstream of pipe Denton Liu
                             ` (4 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:08 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

In case an invocation of a git command fails within the command
substitution, the failure will be masked. Replace the command
substitution with a file-redirection and a call to test_cmp.

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^ ]*\) = "$(\(git [^)]*\))"/\1echo \2 >expect \&\&\n\1\3 >actual \&\&\n\1test_cmp expect actual/
	s/\(\s*\)test "$(\(git [^)]*\))" = \([^ ]*\)/\1echo \3 >expect \&\&\n\1\2 >actual \&\&\n\1test_cmp expect actual/

A future patch will clean up situations where we have multiple duplicate
statements within a test case. This is done to keep this patch purely
mechanical.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 64 ++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 16 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 1af6ea06ee..8b7e7ae55d 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -255,7 +255,9 @@ test_expect_success '--rebase' '
 	git tag before-rebase &&
 	git pull --rebase . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase fast forward' '
@@ -330,7 +332,9 @@ test_expect_success '--rebase fails with multiple branches' '
 	test_must_fail git pull --rebase . copy master 2>err &&
 	test_cmp_rev HEAD before-rebase &&
 	test_i18ngrep "Cannot rebase onto multiple branches" err &&
-	test modified = "$(git show HEAD:file)"
+	echo modified >expect &&
+	git show HEAD:file >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
@@ -381,7 +385,9 @@ test_expect_success 'pull.rebase' '
 	test_config pull.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --autostash & pull.rebase=true' '
@@ -399,7 +405,9 @@ test_expect_success 'branch.to-rebase.rebase' '
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
@@ -408,14 +416,18 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_config branch.to-rebase.rebase false &&
 	git pull . copy &&
 	test_cmp_rev ! HEAD^ copy &&
-	test new = "$(git show HEAD:file2)"
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)" &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual &&
 	test_i18ngrep "ignoring --verify-signatures for rebase" err
 '
 
@@ -423,7 +435,9 @@ test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --no-verify-signatures . copy 2>err &&
 	test_cmp_rev HEAD^ copy &&
-	test new = "$(git show HEAD:file2)" &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual &&
 	test_i18ngrep ! "verify-signatures" err
 '
 
@@ -445,7 +459,9 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	git pull . copy &&
 	test_cmp_rev HEAD^1 before-preserve-rebase &&
 	test_cmp_rev HEAD^2 copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull.rebase=true flattens keep-merge' '
@@ -453,7 +469,9 @@ test_expect_success 'pull.rebase=true flattens keep-merge' '
 	test_config pull.rebase true &&
 	git pull . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
@@ -461,7 +479,9 @@ test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	test_config pull.rebase 1 &&
 	git pull . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success REBASE_P \
@@ -507,7 +527,9 @@ test_expect_success '--rebase=false create a new merge commit' '
 	git pull --rebase=false . copy &&
 	test_cmp_rev HEAD^1 before-preserve-rebase &&
 	test_cmp_rev HEAD^2 copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase=true rebases and flattens keep-merge' '
@@ -515,7 +537,9 @@ test_expect_success '--rebase=true rebases and flattens keep-merge' '
 	test_config pull.rebase preserve &&
 	git pull --rebase=true . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success REBASE_P \
@@ -537,7 +561,9 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
 	test_config pull.rebase preserve &&
 	git pull --rebase . copy &&
 	test_cmp_rev HEAD^^ copy &&
-	test file3 = "$(git show HEAD:file3.t)"
+	echo file3 >expect &&
+	git show HEAD:file3.t >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '--rebase with rebased upstream' '
@@ -622,10 +648,16 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
 		cd empty_repo2 &&
 		echo staged-file >staged-file &&
 		git add staged-file &&
-		test "$(git ls-files)" = staged-file &&
+		echo staged-file >expect &&
+		git ls-files >actual &&
+		test_cmp expect actual &&
 		test_must_fail git pull --rebase .. master 2>err &&
-		test "$(git ls-files)" = staged-file &&
-		test "$(git show :staged-file)" = staged-file &&
+		echo staged-file >expect &&
+		git ls-files >actual &&
+		test_cmp expect actual &&
+		echo staged-file >expect &&
+		git show :staged-file >actual &&
+		test_cmp expect actual &&
 		test_i18ngrep "unborn branch with changes added to the index" err
 	)
 '
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 11/14] t5520: don't put git in upstream of pipe
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
                             ` (9 preceding siblings ...)
  2019-11-12 23:08           ` [PATCH v6 10/14] t5520: test single-line files by git with test_cmp Denton Liu
@ 2019-11-12 23:08           ` Denton Liu
  2019-11-12 23:08           ` [PATCH v6 12/14] t5520: replace $(cat ...) comparison with test_cmp Denton Liu
                             ` (3 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:08 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Before, if the invocation of git failed, it would be masked by the pipe
since only the return code of the last element of a pipe is used.
Rewrite the test to put the git command on its own line so its return
code is not masked.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 8b7e7ae55d..8ddf89e550 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -668,7 +668,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 	(
 		cd corrupt &&
 		test_commit one &&
-		obj=$(git rev-parse --verify HEAD | sed "s#^..#&/#") &&
+		git rev-parse --verify HEAD >head &&
+		obj=$(sed "s#^..#&/#" head) &&
 		rm -f .git/objects/$obj &&
 		test_must_fail git pull --rebase
 	)
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 12/14] t5520: replace $(cat ...) comparison with test_cmp
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
                             ` (10 preceding siblings ...)
  2019-11-12 23:08           ` [PATCH v6 11/14] t5520: don't put git in upstream of pipe Denton Liu
@ 2019-11-12 23:08           ` Denton Liu
  2019-11-12 23:08           ` [PATCH v6 13/14] t5520: remove redundant lines in test cases Denton Liu
                             ` (2 subsequent siblings)
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:08 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

We currently have many instances of `test <line> = $(cat <file>)` and
`test $(cat <file>) = <line>`.  In the case where this fails, it will be
difficult for a developer to debug since the output will be masked.
Replace these instances with invocations of test_cmp().

This change was done with the following GNU sed expressions:

	s/\(\s*\)test \([^=]*\)= "$(cat \([^)]*\))"/\1echo \2>expect \&\&\n\1test_cmp expect \3/
	s/\(\s*\)test "$(cat \([^)]*\))" = \([^&]*\)\( &&\)\?$/\1echo \3 >expect \&\&\n\1test_cmp expect \2\4/

A future patch will clean up situations where we have multiple duplicate
statements within a test case. This is done to keep this patch purely
mechanical.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 105 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 70 insertions(+), 35 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 8ddf89e550..c9e4eec004 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -15,8 +15,10 @@ test_pull_autostash () {
 	git add new_file &&
 	git pull "$@" . copy &&
 	test_cmp_rev HEAD^ copy &&
-	test "$(cat new_file)" = dirty &&
-	test "$(cat file)" = "modified again"
+	echo dirty >expect &&
+	test_cmp expect new_file &&
+	echo "modified again" >expect &&
+	test_cmp expect file
 }
 
 test_pull_autostash_fail () {
@@ -110,9 +112,11 @@ test_expect_success 'test . as a remote' '
 	echo updated >file &&
 	git commit -a -m updated &&
 	git checkout copy &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull &&
-	test "$(cat file)" = updated &&
+	echo updated >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
@@ -125,9 +129,11 @@ test_expect_success 'the default remote . should not break explicit pull' '
 	git commit -a -m modified &&
 	git checkout copy &&
 	git reset --hard HEAD^ &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	git reflog -1 >reflog.actual &&
 	sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
 	echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
@@ -137,10 +143,12 @@ test_expect_success 'the default remote . should not break explicit pull' '
 test_expect_success 'fail if wildcard spec does not match any refs' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 	test_i18ngrep "no candidates for merging" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no branches specified with non-default remote' '
@@ -148,11 +156,13 @@ test_expect_success 'fail if no branches specified with non-default remote' '
 	test_when_finished "git remote remove test_remote" &&
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_config branch.test.remote origin &&
 	test_must_fail git pull test_remote 2>err &&
 	test_i18ngrep "specify a branch on the command line" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if not on a branch' '
@@ -160,10 +170,12 @@ test_expect_success 'fail if not on a branch' '
 	test_when_finished "git remote remove origin" &&
 	git checkout HEAD^ &&
 	test_when_finished "git checkout -f copy" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "not currently on a branch" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if no configuration for current branch' '
@@ -172,10 +184,12 @@ test_expect_success 'fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'pull --all: fail if no configuration for current branch' '
@@ -184,10 +198,12 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
 	git checkout -b test copy^ &&
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote test_remote &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull --all 2>err &&
 	test_i18ngrep "There is no tracking information" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if upstream branch does not exist' '
@@ -195,16 +211,19 @@ test_expect_success 'fail if upstream branch does not exist' '
 	test_when_finished "git checkout -f copy && git branch -D test" &&
 	test_config branch.test.remote . &&
 	test_config branch.test.merge refs/heads/nonexisting &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no such ref was fetched" err &&
-	test "$(cat file)" = file
+	echo file >expect &&
+	test_cmp expect file
 '
 
 test_expect_success 'fail if the index has unresolved entries' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	test_commit modified2 file &&
 	git ls-files -u >unmerged &&
 	test_must_be_empty unmerged &&
@@ -226,21 +245,25 @@ test_expect_success 'fail if the index has unresolved entries' '
 test_expect_success 'fast-forwards working tree if branch head is updated' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	git pull . second:third 2>err &&
 	test_i18ngrep "fetch updated the current branch head" err &&
-	test "$(cat file)" = modified &&
+	echo modified >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
 test_expect_success 'fast-forward fails with conflicting work tree' '
 	git checkout -b third second^ &&
 	test_when_finished "git checkout -f copy && git branch -D third" &&
-	test "$(cat file)" = file &&
+	echo file >expect &&
+	test_cmp expect file &&
 	echo conflict >file &&
 	test_must_fail git pull . second:third 2>err &&
 	test_i18ngrep "Cannot fast-forward your working tree" err &&
-	test "$(cat file)" = conflict &&
+	echo conflict >expect &&
+	test_cmp expect file &&
 	test_cmp_rev third second
 '
 
@@ -501,7 +524,8 @@ test_expect_success 'pull.rebase=interactive' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=interactive . copy &&
-	test "I was here" = "$(cat fake.out)"
+	echo "I was here" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull --rebase=i' '
@@ -512,7 +536,8 @@ test_expect_success 'pull --rebase=i' '
 	test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
 	test_when_finished "test_might_fail git rebase --abort" &&
 	test_must_fail git pull --rebase=i . copy &&
-	test "I was here, too" = "$(cat fake.out)"
+	echo "I was here, too" >expect &&
+	test_cmp expect fake.out
 '
 
 test_expect_success 'pull.rebase=invalid fails' '
@@ -578,16 +603,20 @@ test_expect_success '--rebase with rebased upstream' '
 	git commit -m to-rebase file2 &&
 	git tag to-rebase-orig &&
 	git pull --rebase me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase -f with rebased upstream' '
 	test_when_finished "test_might_fail git rebase --abort" &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase -f me copy &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success '--rebase with rebased default upstream' '
@@ -595,8 +624,10 @@ test_expect_success '--rebase with rebased default upstream' '
 	git checkout --track -b to-rebase2 me/copy &&
 	git reset --hard to-rebase-orig &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_expect_success 'rebased upstream + fetch + pull --rebase' '
@@ -607,8 +638,10 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
 	git reset --hard to-rebase-orig &&
 	git fetch &&
 	git pull --rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 
 '
 
@@ -744,8 +777,10 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
 test_expect_success 'git pull --rebase against local branch' '
 	git checkout -b copy2 to-rebase-orig &&
 	git pull --rebase . to-rebase &&
-	test "conflicting modification" = "$(cat file)" &&
-	test file = "$(cat file2)"
+	echo "conflicting modification" >expect &&
+	test_cmp expect file &&
+	echo file >expect &&
+	test_cmp expect file2
 '
 
 test_done
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 13/14] t5520: remove redundant lines in test cases
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
                             ` (11 preceding siblings ...)
  2019-11-12 23:08           ` [PATCH v6 12/14] t5520: replace $(cat ...) comparison with test_cmp Denton Liu
@ 2019-11-12 23:08           ` Denton Liu
  2019-11-12 23:08           ` [PATCH v6 14/14] t5520: replace `! git` with `test_must_fail git` Denton Liu
  2019-11-13  1:59           ` [PATCH v6 00/14] t5520: various test cleanup Junio C Hamano
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:08 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

In the previous patches, the mechanical application of changes left some
duplicate statements in the test case which were not strictly incorrect
but were redundant and possibly misleading. Remove these duplicate
statements so that it is clear that the intent behind the tests are that
the content of the file stays the same throughout the whole test case.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index c9e4eec004..ef3dbc201a 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -147,7 +147,6 @@ test_expect_success 'fail if wildcard spec does not match any refs' '
 	test_cmp expect file &&
 	test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
 	test_i18ngrep "no candidates for merging" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -161,7 +160,6 @@ test_expect_success 'fail if no branches specified with non-default remote' '
 	test_config branch.test.remote origin &&
 	test_must_fail git pull test_remote 2>err &&
 	test_i18ngrep "specify a branch on the command line" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -174,7 +172,6 @@ test_expect_success 'fail if not on a branch' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "not currently on a branch" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -188,7 +185,6 @@ test_expect_success 'fail if no configuration for current branch' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no tracking information" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -202,7 +198,6 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
 	test_cmp expect file &&
 	test_must_fail git pull --all 2>err &&
 	test_i18ngrep "There is no tracking information" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -215,7 +210,6 @@ test_expect_success 'fail if upstream branch does not exist' '
 	test_cmp expect file &&
 	test_must_fail git pull 2>err &&
 	test_i18ngrep "no such ref was fetched" err &&
-	echo file >expect &&
 	test_cmp expect file
 '
 
@@ -685,10 +679,8 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
 		git ls-files >actual &&
 		test_cmp expect actual &&
 		test_must_fail git pull --rebase .. master 2>err &&
-		echo staged-file >expect &&
 		git ls-files >actual &&
 		test_cmp expect actual &&
-		echo staged-file >expect &&
 		git show :staged-file >actual &&
 		test_cmp expect actual &&
 		test_i18ngrep "unborn branch with changes added to the index" err
-- 
2.24.0.346.gee0de6d492


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

* [PATCH v6 14/14] t5520: replace `! git` with `test_must_fail git`
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
                             ` (12 preceding siblings ...)
  2019-11-12 23:08           ` [PATCH v6 13/14] t5520: remove redundant lines in test cases Denton Liu
@ 2019-11-12 23:08           ` Denton Liu
  2019-11-13  1:59           ` [PATCH v6 00/14] t5520: various test cleanup Junio C Hamano
  14 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-12 23:08 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Eric Sunshine, Johannes Sixt, SZEDER Gábor, Junio C Hamano

Currently, if a git command fails in an unexpected way, such as a
segfault, it will be masked and ignored. Replace the ! with
test_must_fail so that only expected failures pass.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t5520-pull.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index ef3dbc201a..602d996a33 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -537,7 +537,7 @@ test_expect_success 'pull --rebase=i' '
 test_expect_success 'pull.rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase invalid &&
-	! git pull . copy
+	test_must_fail git pull . copy
 '
 
 test_expect_success '--rebase=false create a new merge commit' '
@@ -572,7 +572,7 @@ test_expect_success REBASE_P \
 
 test_expect_success '--rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
-	! git pull --rebase=invalid . copy
+	test_must_fail git pull --rebase=invalid . copy
 '
 
 test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
-- 
2.24.0.346.gee0de6d492


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

* Re: [PATCH v6 01/14] t: teach test_cmp_rev to accept ! for not-equals
  2019-11-12 23:07           ` [PATCH v6 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
@ 2019-11-13  1:57             ` Junio C Hamano
  2019-11-14  0:52               ` Denton Liu
  0 siblings, 1 reply; 116+ messages in thread
From: Junio C Hamano @ 2019-11-13  1:57 UTC (permalink / raw)
  To: Denton Liu
  Cc: Git Mailing List, Eric Sunshine, Johannes Sixt, SZEDER Gábor

Denton Liu <liu.denton@gmail.com> writes:

> +# Tests that its two parameters refer to the same revision, or if '!' is
> +# provided first, that its other two parameters refer to different
> +# revisions.
>  test_cmp_rev () {
> +	local op wrong_result
> +	op='='
> +	wrong_result='different'
> +	if test $# -ge 1 && test "x$1" = 'x!'
> +	then
> +	    op='!='
> +	    wrong_result='the same'
> +	    shift
> +	fi

I'd prefer

	local op wrong_result

	if test $# -ge 1 && test "x$1" = 'x!'
	then
	    op='!='
	    wrong_result='the same'
	    shift
	else
	    op='='
	    wrong_result='different'
	fi

that clarifies that the variants with and without '!' are equals, as
opposed to the form with '!' is an afterthought exception.

On the other hand, if we want to insist that the form without '!' is
the norm, then

	local op='=' wrong_result='different'

	if test $# -ge 1 && test "x$1" = 'x!'
	then
	    op='!='
	    wrong_result='the same'
	    shift
	fi

would be shorter (yes, I made sure we already use assignment to a
variable on the same line where it is declared "local"; we used to
avoid "local" that is outside POSIX so I want to make sure our use
is safe).

I'll queue the patches as-is, but if enough people agree with me (on
either variants), I'd locally amend to make it so (i.e. no need to
resend only for this change).

Thanks.

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

* Re: [PATCH v6 00/14] t5520: various test cleanup
  2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
                             ` (13 preceding siblings ...)
  2019-11-12 23:08           ` [PATCH v6 14/14] t5520: replace `! git` with `test_must_fail git` Denton Liu
@ 2019-11-13  1:59           ` Junio C Hamano
  14 siblings, 0 replies; 116+ messages in thread
From: Junio C Hamano @ 2019-11-13  1:59 UTC (permalink / raw)
  To: Denton Liu
  Cc: Git Mailing List, Eric Sunshine, Johannes Sixt, SZEDER Gábor

Denton Liu <liu.denton@gmail.com> writes:

> Like earlier patchsets, I want to implement a feature that involves
> modifications to the test suite. Since that feature will probably take a
> while to polish up, however, let's clean up the test suite in a separate
> patchset first so it's not blocked by the feature work.
>
> 1/15 is a general improvement to test_rev_cmp() that will be used later
> in the series.
>
> Changes since v5:
>
> * More test_cmp_rev() cleanup
>
> * Changed instances of "subshell" to "command substitution" where appropriate
>
> * Change instances of "Git" to "git" when we are referring to the command

Looked reasonable.  Will replace.

Thanks.

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

* Re: [PATCH v6 01/14] t: teach test_cmp_rev to accept ! for not-equals
  2019-11-13  1:57             ` Junio C Hamano
@ 2019-11-14  0:52               ` Denton Liu
  0 siblings, 0 replies; 116+ messages in thread
From: Denton Liu @ 2019-11-14  0:52 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Eric Sunshine, Johannes Sixt, SZEDER Gábor

Hi Junio,

On Wed, Nov 13, 2019 at 10:57:34AM +0900, Junio C Hamano wrote:
> Denton Liu <liu.denton@gmail.com> writes:
> 
> > +# Tests that its two parameters refer to the same revision, or if '!' is
> > +# provided first, that its other two parameters refer to different
> > +# revisions.
> >  test_cmp_rev () {
> > +	local op wrong_result
> > +	op='='
> > +	wrong_result='different'
> > +	if test $# -ge 1 && test "x$1" = 'x!'
> > +	then
> > +	    op='!='
> > +	    wrong_result='the same'
> > +	    shift
> > +	fi
> On the other hand, if we want to insist that the form without '!' is
> the norm, then
> 
> 	local op='=' wrong_result='different'
> 
> 	if test $# -ge 1 && test "x$1" = 'x!'
> 	then
> 	    op='!='
> 	    wrong_result='the same'
> 	    shift
> 	fi
> 
> would be shorter (yes, I made sure we already use assignment to a
> variable on the same line where it is declared "local"; we used to
> avoid "local" that is outside POSIX so I want to make sure our use
> is safe).

I'd prefer this form. Unless anyone else objects, you can squash it in.

You bring up a good point about us _already_ using inline assignments
with `local`, though. In fact, it looks like we already test for this in
the very first test case of t0000 so I comfortable with this change.

However, I'd feel _more_ comfortable with this change if we also queued
the following patch. (This change can either live on a separate branch
or become the first patch in this series.)

-- >8 --
Subject: [PATCH] t0000: test multiple local assignment

According to POSIX enhancement request '0000767: Add built-in
"local"'[1],

	dash only allows one variable in a local definition; it permits
	assignment though it doesn't document that clearly.

however, this isn't true since t0000 still passes with this patch
applied on dash 0.5.10.2. Needless to say, since `local` isn't POSIX
standardized, it is not exactly clear what `local` entails on different
versions of different shells.

We currently already have many instances of multiple local assignments
in our codebase. Ensure that this is actually supported by explicitly
testing that it is sane.

[1]: http://austingroupbugs.net/bug_view_page.php?bug_id=767

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 t/t0000-basic.sh | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 4d3f7ba295..a4af2342d1 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -20,9 +20,9 @@ modification *should* take notice and update the test vectors here.
 
 . ./test-lib.sh
 
-try_local_x () {
-	local x="local" &&
-	echo "$x"
+try_local_xy () {
+	local x="local" y="alsolocal" &&
+	echo "$x $y"
 }
 
 # Check whether the shell supports the "local" keyword. "local" is not
@@ -35,11 +35,12 @@ try_local_x () {
 # relying on "local".
 test_expect_success 'verify that the running shell supports "local"' '
 	x="notlocal" &&
-	echo "local" >expected1 &&
-	try_local_x >actual1 &&
+	y="alsonotlocal" &&
+	echo "local alsolocal" >expected1 &&
+	try_local_xy >actual1 &&
 	test_cmp expected1 actual1 &&
-	echo "notlocal" >expected2 &&
-	echo "$x" >actual2 &&
+	echo "notlocal alsonotlocal" >expected2 &&
+	echo "$x $y" >actual2 &&
 	test_cmp expected2 actual2
 '
 
-- 
2.24.0.346.gee0de6d492


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

end of thread, other threads:[~2019-11-14  0:52 UTC | newest]

Thread overview: 116+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-17 23:16 [PATCH 00/12] t5520: various test cleanup Denton Liu
2019-10-17 23:16 ` [PATCH 01/12] t5520: improve test style Denton Liu
2019-10-17 23:16 ` [PATCH 02/12] t5520: use sq for test case names Denton Liu
2019-10-17 23:17 ` [PATCH 03/12] t5520: let sed open its own input Denton Liu
2019-10-17 23:17 ` [PATCH 04/12] t5520: replace test -f with test_path_is_file Denton Liu
2019-10-17 23:26   ` Eric Sunshine
2019-10-17 23:35   ` [PATCH 4.5/12] t5520: replace test -f with test-lib functions Denton Liu
2019-10-18  0:11     ` Eric Sunshine
2019-10-17 23:17 ` [PATCH 05/12] t5520: remove spaces after redirect operator Denton Liu
2019-10-17 23:17 ` [PATCH 06/12] t5520: use test_line_count where possible Denton Liu
2019-10-17 23:17 ` [PATCH 07/12] t5520: replace test -{n,z} with test-lib functions Denton Liu
2019-10-17 23:31   ` Eric Sunshine
2019-10-17 23:17 ` [PATCH 08/12] t5520: use test_cmp_rev where possible Denton Liu
2019-10-17 23:41   ` Eric Sunshine
2019-10-18 18:52     ` Denton Liu
2019-10-23 13:53       ` Eric Sunshine
2019-10-17 23:17 ` [PATCH 09/12] t5520: test single-line files by git with test_cmp Denton Liu
2019-10-17 23:49   ` Eric Sunshine
2019-10-17 23:17 ` [PATCH 10/12] t5520: don't put git in upstream of pipe Denton Liu
2019-10-17 23:17 ` [PATCH 11/12] t5520: replace subshell cat comparison with test_cmp Denton Liu
2019-10-17 23:17 ` [PATCH 12/12] t5520: replace `! git` with `test_must_fail git` Denton Liu
2019-10-18 22:10 ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
2019-10-18 22:04   ` [PATCH v2 01/15] t7408: replace `test_must_fail test_path_is_file` Denton Liu
2019-10-19 11:58     ` Johannes Sixt
2019-10-18 22:04   ` [PATCH v2 09/15] t5520: replace test -{n,z} with test-lib functions Denton Liu
2019-10-18 22:04   ` [PATCH v2 11/15] t5520: test single-line files by git with test_cmp Denton Liu
2019-10-18 22:10   ` [PATCH v2 02/15] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
2019-10-18 22:45     ` SZEDER Gábor
2019-10-18 22:10   ` [PATCH v2 03/15] t5520: improve test style Denton Liu
2019-10-18 22:10   ` [PATCH v2 04/15] t5520: use sq for test case names Denton Liu
2019-10-18 22:10   ` [PATCH v2 05/15] t5520: let sed open its own input Denton Liu
2019-10-18 22:10   ` [PATCH v2 06/15] t5520: replace test -f with test-lib functions Denton Liu
2019-10-18 22:10   ` [PATCH v2 07/15] t5520: remove spaces after redirect operator Denton Liu
2019-10-18 22:10   ` [PATCH v2 08/15] t5520: use test_line_count where possible Denton Liu
2019-10-18 22:10   ` [PATCH v2 10/15] t5520: use test_cmp_rev " Denton Liu
2019-10-18 22:10   ` [PATCH v2 12/15] t5520: don't put git in upstream of pipe Denton Liu
2019-10-18 22:10   ` [PATCH v2 13/15] t5520: replace subshell cat comparison with test_cmp Denton Liu
2019-10-18 22:10   ` [PATCH v2 14/15] t5520: remove redundant lines in test cases Denton Liu
2019-10-18 22:10   ` [PATCH v2 15/15] t5520: replace `! git` with `test_must_fail git` Denton Liu
2019-10-18 22:14   ` [PATCH v2 00/15] t5520: various test cleanup Denton Liu
2019-10-22 10:19   ` [PATCH v3 00/14] " Denton Liu
2019-10-22 10:19     ` [PATCH v3 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
2019-10-22 10:19     ` [PATCH v3 02/14] t5520: improve test style Denton Liu
2019-10-22 10:19     ` [PATCH v3 03/14] t5520: use sq for test case names Denton Liu
2019-10-22 10:20     ` [PATCH v3 04/14] t5520: let sed open its own input Denton Liu
2019-10-22 10:20     ` [PATCH v3 05/14] t5520: replace test -f with test-lib functions Denton Liu
2019-10-22 10:20     ` [PATCH v3 06/14] t5520: remove spaces after redirect operator Denton Liu
2019-10-22 10:20     ` [PATCH v3 07/14] t5520: use test_line_count where possible Denton Liu
2019-10-22 10:20     ` [PATCH v3 08/14] t5520: replace test -{n,z} with test-lib functions Denton Liu
2019-10-22 10:20     ` [PATCH v3 09/14] t5520: use test_cmp_rev where possible Denton Liu
2019-10-22 10:20     ` [PATCH v3 10/14] t5520: test single-line files by git with test_cmp Denton Liu
2019-10-22 10:20     ` [PATCH v3 11/14] t5520: don't put git in upstream of pipe Denton Liu
2019-10-22 10:20     ` [PATCH v3 12/14] t5520: replace subshell cat comparison with test_cmp Denton Liu
2019-10-22 10:20     ` [PATCH v3 13/14] t5520: remove redundant lines in test cases Denton Liu
2019-10-22 10:20     ` [PATCH v3 14/14] t5520: replace `! git` with `test_must_fail git` Denton Liu
2019-10-24 23:21     ` [PATCH v3 00/14] t5520: various test cleanup Denton Liu
2019-10-25  3:44       ` Junio C Hamano
2019-11-04 19:17         ` Denton Liu
2019-11-06  2:37           ` Junio C Hamano
2019-11-07 18:51     ` [PATCH v4 " Denton Liu
2019-11-07 18:51       ` [PATCH v4 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
2019-11-08  3:24         ` Junio C Hamano
2019-11-08  8:23           ` Denton Liu
2019-11-08 12:49             ` Junio C Hamano
2019-11-08 21:19               ` Denton Liu
2019-11-10  6:58                 ` Junio C Hamano
2019-11-07 18:51       ` [PATCH v4 02/14] t5520: improve test style Denton Liu
2019-11-07 18:51       ` [PATCH v4 03/14] t5520: use sq for test case names Denton Liu
2019-11-07 18:51       ` [PATCH v4 04/14] t5520: let sed open its own input Denton Liu
2019-11-07 18:51       ` [PATCH v4 05/14] t5520: replace test -f with test-lib functions Denton Liu
2019-11-07 18:51       ` [PATCH v4 06/14] t5520: remove spaces after redirect operator Denton Liu
2019-11-07 18:51       ` [PATCH v4 07/14] t5520: use test_line_count where possible Denton Liu
2019-11-07 18:51       ` [PATCH v4 08/14] t5520: replace test -{n,z} with test-lib functions Denton Liu
2019-11-07 18:51       ` [PATCH v4 09/14] t5520: use test_cmp_rev where possible Denton Liu
2019-11-07 18:51       ` [PATCH v4 10/14] t5520: test single-line files by git with test_cmp Denton Liu
2019-11-07 18:51       ` [PATCH v4 11/14] t5520: don't put git in upstream of pipe Denton Liu
2019-11-07 18:51       ` [PATCH v4 12/14] t5520: replace subshell cat comparison with test_cmp Denton Liu
2019-11-07 18:51       ` [PATCH v4 13/14] t5520: remove redundant lines in test cases Denton Liu
2019-11-07 18:51       ` [PATCH v4 14/14] t5520: replace `! git` with `test_must_fail git` Denton Liu
2019-11-12  0:13       ` [PATCH v5 00/14] t5520: various test cleanup Denton Liu
2019-11-12  0:13         ` [PATCH v5 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
2019-11-12  6:52           ` Junio C Hamano
2019-11-12 19:38             ` [PATCH] fixup! " Denton Liu
2019-11-12  0:13         ` [PATCH v5 02/14] t5520: improve test style Denton Liu
2019-11-12  0:13         ` [PATCH v5 03/14] t5520: use sq for test case names Denton Liu
2019-11-12  0:13         ` [PATCH v5 04/14] t5520: let sed open its own input Denton Liu
2019-11-12  0:13         ` [PATCH v5 05/14] t5520: replace test -f with test-lib functions Denton Liu
2019-11-12  0:13         ` [PATCH v5 06/14] t5520: remove spaces after redirect operator Denton Liu
2019-11-12  0:13         ` [PATCH v5 07/14] t5520: use test_line_count where possible Denton Liu
2019-11-12  0:13         ` [PATCH v5 08/14] t5520: replace test -{n,z} with test-lib functions Denton Liu
2019-11-12  0:14         ` [PATCH v5 09/14] t5520: use test_cmp_rev where possible Denton Liu
2019-11-12  0:14         ` [PATCH v5 10/14] t5520: test single-line files by git with test_cmp Denton Liu
2019-11-12  5:17           ` Junio C Hamano
2019-11-12 23:06             ` Denton Liu
2019-11-12  0:14         ` [PATCH v5 11/14] t5520: don't put git in upstream of pipe Denton Liu
2019-11-12  0:14         ` [PATCH v5 12/14] t5520: replace subshell cat comparison with test_cmp Denton Liu
2019-11-12  0:14         ` [PATCH v5 13/14] t5520: remove redundant lines in test cases Denton Liu
2019-11-12  0:14         ` [PATCH v5 14/14] t5520: replace `! git` with `test_must_fail git` Denton Liu
2019-11-12 23:07         ` [PATCH v6 00/14] t5520: various test cleanup Denton Liu
2019-11-12 23:07           ` [PATCH v6 01/14] t: teach test_cmp_rev to accept ! for not-equals Denton Liu
2019-11-13  1:57             ` Junio C Hamano
2019-11-14  0:52               ` Denton Liu
2019-11-12 23:07           ` [PATCH v6 02/14] t5520: improve test style Denton Liu
2019-11-12 23:07           ` [PATCH v6 03/14] t5520: use sq for test case names Denton Liu
2019-11-12 23:07           ` [PATCH v6 04/14] t5520: let sed open its own input Denton Liu
2019-11-12 23:07           ` [PATCH v6 05/14] t5520: replace test -f with test-lib functions Denton Liu
2019-11-12 23:07           ` [PATCH v6 06/14] t5520: remove spaces after redirect operator Denton Liu
2019-11-12 23:08           ` [PATCH v6 07/14] t5520: use test_line_count where possible Denton Liu
2019-11-12 23:08           ` [PATCH v6 08/14] t5520: replace test -{n,z} with test-lib functions Denton Liu
2019-11-12 23:08           ` [PATCH v6 09/14] t5520: use test_cmp_rev where possible Denton Liu
2019-11-12 23:08           ` [PATCH v6 10/14] t5520: test single-line files by git with test_cmp Denton Liu
2019-11-12 23:08           ` [PATCH v6 11/14] t5520: don't put git in upstream of pipe Denton Liu
2019-11-12 23:08           ` [PATCH v6 12/14] t5520: replace $(cat ...) comparison with test_cmp Denton Liu
2019-11-12 23:08           ` [PATCH v6 13/14] t5520: remove redundant lines in test cases Denton Liu
2019-11-12 23:08           ` [PATCH v6 14/14] t5520: replace `! git` with `test_must_fail git` Denton Liu
2019-11-13  1:59           ` [PATCH v6 00/14] t5520: various test cleanup 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).