All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Shubham Mishra" <shivam828787@gmail.com>,
	"Christian Couder" <christian.couder@gmail.com>,
	"Taylor Blau" <me@ttaylorr.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 14/15] checkout tests: don't ignore "git <cmd>" exit code
Date: Mon,  7 Mar 2022 13:49:05 +0100	[thread overview]
Message-ID: <patch-v2-14.15-22b81d7f93a-20220307T124817Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-v2-00.15-00000000000-20220307T124817Z-avarab@gmail.com>

Change a fragile pattern introduced in 696acf45f96 (checkout:
implement "-" abbreviation, add docs and tests, 2009-01-17) to check
the exit code of both "git symbolic-ref" and "git rev-parse".

Without this change this test will become flaky e.g. under
SANITIZE=leak if some (but not all) memory leaks revealed by these
commands are fixed.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t2012-checkout-last.sh | 51 +++++++++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 16 deletions(-)

diff --git a/t/t2012-checkout-last.sh b/t/t2012-checkout-last.sh
index 42601d5a310..1f6c4ed0428 100755
--- a/t/t2012-checkout-last.sh
+++ b/t/t2012-checkout-last.sh
@@ -21,14 +21,20 @@ test_expect_success 'first branch switch' '
 	git checkout other
 '
 
+test_cmp_symbolic_HEAD_ref () {
+	echo refs/heads/"$1" >expect &&
+	git symbolic-ref HEAD >actual &&
+	test_cmp expect actual
+}
+
 test_expect_success '"checkout -" switches back' '
 	git checkout - &&
-	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
+	test_cmp_symbolic_HEAD_ref main
 '
 
 test_expect_success '"checkout -" switches forth' '
 	git checkout - &&
-	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
+	test_cmp_symbolic_HEAD_ref other
 '
 
 test_expect_success 'detach HEAD' '
@@ -37,12 +43,16 @@ test_expect_success 'detach HEAD' '
 
 test_expect_success '"checkout -" attaches again' '
 	git checkout - &&
-	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
+	test_cmp_symbolic_HEAD_ref other
 '
 
 test_expect_success '"checkout -" detaches again' '
 	git checkout - &&
-	test "z$(git rev-parse HEAD)" = "z$(git rev-parse other)" &&
+
+	git rev-parse other >expect &&
+	git rev-parse HEAD >actual &&
+	test_cmp expect actual &&
+
 	test_must_fail git symbolic-ref HEAD
 '
 
@@ -63,31 +73,31 @@ more_switches () {
 test_expect_success 'switch to the last' '
 	more_switches &&
 	git checkout @{-1} &&
-	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch2"
+	test_cmp_symbolic_HEAD_ref branch2
 '
 
 test_expect_success 'switch to second from the last' '
 	more_switches &&
 	git checkout @{-2} &&
-	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch3"
+	test_cmp_symbolic_HEAD_ref branch3
 '
 
 test_expect_success 'switch to third from the last' '
 	more_switches &&
 	git checkout @{-3} &&
-	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch4"
+	test_cmp_symbolic_HEAD_ref branch4
 '
 
 test_expect_success 'switch to fourth from the last' '
 	more_switches &&
 	git checkout @{-4} &&
-	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch5"
+	test_cmp_symbolic_HEAD_ref branch5
 '
 
 test_expect_success 'switch to twelfth from the last' '
 	more_switches &&
 	git checkout @{-12} &&
-	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch13"
+	test_cmp_symbolic_HEAD_ref branch13
 '
 
 test_expect_success 'merge base test setup' '
@@ -98,19 +108,28 @@ test_expect_success 'merge base test setup' '
 test_expect_success 'another...main' '
 	git checkout another &&
 	git checkout another...main &&
-	test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
+
+	git rev-parse --verify main^ >expect &&
+	git rev-parse --verify HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '...main' '
 	git checkout another &&
 	git checkout ...main &&
-	test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
+
+	git rev-parse --verify main^ >expect &&
+	git rev-parse --verify HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'main...' '
 	git checkout another &&
 	git checkout main... &&
-	test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
+
+	git rev-parse --verify main^ >expect &&
+	git rev-parse --verify HEAD >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success '"checkout -" works after a rebase A' '
@@ -118,7 +137,7 @@ test_expect_success '"checkout -" works after a rebase A' '
 	git checkout other &&
 	git rebase main &&
 	git checkout - &&
-	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
+	test_cmp_symbolic_HEAD_ref main
 '
 
 test_expect_success '"checkout -" works after a rebase A B' '
@@ -127,7 +146,7 @@ test_expect_success '"checkout -" works after a rebase A B' '
 	git checkout other &&
 	git rebase main moodle &&
 	git checkout - &&
-	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
+	test_cmp_symbolic_HEAD_ref main
 '
 
 test_expect_success '"checkout -" works after a rebase -i A' '
@@ -135,7 +154,7 @@ test_expect_success '"checkout -" works after a rebase -i A' '
 	git checkout other &&
 	git rebase -i main &&
 	git checkout - &&
-	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
+	test_cmp_symbolic_HEAD_ref main
 '
 
 test_expect_success '"checkout -" works after a rebase -i A B' '
@@ -144,7 +163,7 @@ test_expect_success '"checkout -" works after a rebase -i A B' '
 	git checkout other &&
 	git rebase main foodle &&
 	git checkout - &&
-	test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
+	test_cmp_symbolic_HEAD_ref main
 '
 
 test_done
-- 
2.35.1.1242.gfeba0eae32b


  parent reply	other threads:[~2022-03-07 12:50 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02 17:27 [PATCH 00/15] tests: don't ignore "git" exit codes Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 01/15] tests: change some 'test $(git) = "x"' to test_cmp Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 02/15] tests: use "test_stdout_line_count", not "test $(git [...] | wc -l)" Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 03/15] read-tree tests: check "diff-files" exit code on failure Ævar Arnfjörð Bjarmason
2022-03-02 23:06   ` Junio C Hamano
2022-03-02 17:27 ` [PATCH 04/15] diff tests: don't ignore "git diff" exit code Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 05/15] diff tests: don't ignore "git diff" exit code in "read" loop Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 06/15] apply tests: use "test_must_fail" instead of ad-hoc pattern Ævar Arnfjörð Bjarmason
2022-03-02 23:09   ` Junio C Hamano
2022-03-02 17:27 ` [PATCH 07/15] merge " Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 08/15] rev-parse tests: don't ignore "git reflog" exit code Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 09/15] notes tests: don't ignore "git" " Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 10/15] diff tests: don't ignore "git rev-list" " Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 11/15] rev-list tests: don't hide abort() in "test_expect_failure" Ævar Arnfjörð Bjarmason
2022-03-02 23:16   ` Junio C Hamano
2022-03-03 10:10     ` Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 12/15] gettext tests: don't ignore "test-tool regex" exit code Ævar Arnfjörð Bjarmason
2022-03-02 23:20   ` Junio C Hamano
2022-03-03 15:46     ` Ævar Arnfjörð Bjarmason
2022-03-03 20:58       ` Junio C Hamano
2022-03-02 17:27 ` [PATCH 13/15] apply tests: don't ignore "git ls-files" exit code, drop sub-shell Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 14/15] checkout tests: don't ignore "git <cmd>" exit code Ævar Arnfjörð Bjarmason
2022-03-02 17:27 ` [PATCH 15/15] rev-list simplify tests: don't ignore "git" " Ævar Arnfjörð Bjarmason
2022-03-02 23:23 ` [PATCH 00/15] tests: don't ignore "git" exit codes Junio C Hamano
2022-03-03  2:02 ` Derrick Stolee
2022-03-03 10:13   ` Ævar Arnfjörð Bjarmason
2022-03-03 14:06   ` Phillip Wood
2022-03-03 15:35     ` Ævar Arnfjörð Bjarmason
2022-03-04  2:44       ` Junio C Hamano
2022-03-04  6:57         ` Ævar Arnfjörð Bjarmason
2022-03-03  5:09 ` Shubham Mishra
2022-03-03  9:53   ` Ævar Arnfjörð Bjarmason
2022-03-07 12:48 ` [PATCH v2 " Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 01/15] tests: change some 'test $(git) = "x"' to test_cmp Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 02/15] tests: use "test_stdout_line_count", not "test $(git [...] | wc -l)" Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 03/15] read-tree tests: check "diff-files" exit code on failure Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 04/15] diff tests: don't ignore "git diff" exit code Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 05/15] diff tests: don't ignore "git diff" exit code in "read" loop Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 06/15] apply tests: use "test_must_fail" instead of ad-hoc pattern Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 07/15] merge " Ævar Arnfjörð Bjarmason
2022-03-07 12:48   ` [PATCH v2 08/15] rev-parse tests: don't ignore "git reflog" exit code Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 09/15] notes tests: don't ignore "git" " Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 10/15] diff tests: don't ignore "git rev-list" " Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 11/15] rev-list tests: don't hide abort() in "test_expect_failure" Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 12/15] gettext tests: don't ignore "test-tool regex" exit code Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 13/15] apply tests: don't ignore "git ls-files" exit code, drop sub-shell Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` Ævar Arnfjörð Bjarmason [this message]
2022-03-07 12:49   ` [PATCH v2 15/15] rev-list simplify tests: don't ignore "git" exit code Ævar Arnfjörð Bjarmason

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

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

  git send-email \
    --in-reply-to=patch-v2-14.15-22b81d7f93a-20220307T124817Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.com \
    --cc=shivam828787@gmail.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.