git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Denton Liu <liu.denton@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH v2 02/15] t: teach test_cmp_rev to accept ! for not-equals
Date: Fri, 18 Oct 2019 15:10:21 -0700	[thread overview]
Message-ID: <417e808466ee3e61a1719faa319fe0e796d5d271.1571435195.git.liu.denton@gmail.com> (raw)
In-Reply-To: <cover.1571435195.git.liu.denton@gmail.com>

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


  parent reply	other threads:[~2019-10-18 22:12 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` Denton Liu [this message]
2019-10-18 22:45     ` [PATCH v2 02/15] t: teach test_cmp_rev to accept ! for not-equals 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=417e808466ee3e61a1719faa319fe0e796d5d271.1571435195.git.liu.denton@gmail.com \
    --to=liu.denton@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).