git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Denton Liu <liu.denton@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: Eric Sunshine <sunshine@sunshineco.com>,
	Jakub Narebski <jnareb@gmail.com>, Johannes Sixt <j6t@kdbg.org>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v3] t2018: be more discerning when checking for expected exit codes
Date: Sun, 26 Jan 2020 15:23:05 -0500	[thread overview]
Message-ID: <4af0c20e2981ed7e361083a71cb25b9f4a55fa4f.1580069736.git.liu.denton@gmail.com> (raw)
In-Reply-To: <587e53053f02ad0867dc903688c8887602950bd3.1578372682.git.liu.denton@gmail.com>

Functions test_dirty_unmergeable() and test_dirty_mergeable()
expect git-diff to exit with the specific code 1. However, rather
than checking for that value explicitly, they instead negate the
exit code. Unfortunately, this negation makes it impossible to
distinguish the expected code from some other unexpected non-zero
code, for instance, from a segmentation fault. Therefore, be more
discerning by checking the exit code explicitly using
test_expect_code().

Furthermore, some callers of those functions want to negate the
result again, and do so with test_must_fail(). However,
test_must_fail() should only be used with git commands. Address
this by introducing a couple new tiny helper functions which test
the exact condition expected (without the unnecessarily confusing
double-negation).

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
This patch is a complete replacement for 4/16: "t2018: use
test_expect_code for failing git commands"[1] in
"dl/test-must-fail-fixes-2". It replaces the commit message with a
much-improved version from Eric. Other than that, no code changes are
made.

[1]: https://lore.kernel.org/git/587e53053f02ad0867dc903688c8887602950bd3.1578372682.git.liu.denton@gmail.com/

 t/t2018-checkout-branch.sh | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh
index 61206a90fb..7ca55efc6b 100755
--- a/t/t2018-checkout-branch.sh
+++ b/t/t2018-checkout-branch.sh
@@ -34,7 +34,11 @@ do_checkout () {
 }
 
 test_dirty_unmergeable () {
-	! git diff --exit-code >/dev/null
+	test_expect_code 1 git diff --exit-code
+}
+
+test_dirty_unmergeable_discards_changes () {
+	git diff --exit-code
 }
 
 setup_dirty_unmergeable () {
@@ -42,7 +46,11 @@ setup_dirty_unmergeable () {
 }
 
 test_dirty_mergeable () {
-	! git diff --cached --exit-code >/dev/null
+	test_expect_code 1 git diff --cached --exit-code
+}
+
+test_dirty_mergeable_discards_changes () {
+	git diff --cached --exit-code
 }
 
 setup_dirty_mergeable () {
@@ -94,7 +102,7 @@ test_expect_success 'checkout -f -b to a new branch with unmergeable changes dis
 
 	# still dirty and on branch1
 	do_checkout branch2 $HEAD1 "-f -b" &&
-	test_must_fail test_dirty_unmergeable
+	test_dirty_unmergeable_discards_changes
 '
 
 test_expect_success 'checkout -b to a new branch preserves mergeable changes' '
@@ -112,7 +120,7 @@ test_expect_success 'checkout -f -b to a new branch with mergeable changes disca
 	test_when_finished git reset --hard HEAD &&
 	setup_dirty_mergeable &&
 	do_checkout branch2 $HEAD1 "-f -b" &&
-	test_must_fail test_dirty_mergeable
+	test_dirty_mergeable_discards_changes
 '
 
 test_expect_success 'checkout -b to an existing branch fails' '
@@ -163,7 +171,7 @@ test_expect_success 'checkout -B to an existing branch with unmergeable changes
 test_expect_success 'checkout -f -B to an existing branch with unmergeable changes discards changes' '
 	# still dirty and on branch1
 	do_checkout branch2 $HEAD1 "-f -B" &&
-	test_must_fail test_dirty_unmergeable
+	test_dirty_unmergeable_discards_changes
 '
 
 test_expect_success 'checkout -B to an existing branch preserves mergeable changes' '
@@ -180,7 +188,7 @@ test_expect_success 'checkout -f -B to an existing branch with mergeable changes
 
 	setup_dirty_mergeable &&
 	do_checkout branch2 $HEAD1 "-f -B" &&
-	test_must_fail test_dirty_mergeable
+	test_dirty_mergeable_discards_changes
 '
 
 test_expect_success 'checkout -b <describe>' '
-- 
2.25.0.rc1.180.g49a268d3eb


  parent reply	other threads:[~2020-01-26 20:23 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-27 13:47 [PATCH 00/16] t: replace incorrect test_must_fail usage (part 2) Denton Liu
2019-12-27 13:47 ` [PATCH 01/16] t2018: remove trailing space from test description Denton Liu
2019-12-27 13:47 ` [PATCH 02/16] t2018: add space between function name and () Denton Liu
2019-12-27 21:03   ` Eric Sunshine
2019-12-27 13:47 ` [PATCH 03/16] t2018: use test_must_fail for failing git commands Denton Liu
2019-12-28  7:55   ` Eric Sunshine
2019-12-30 20:30   ` Jakub Narebski
2019-12-27 13:47 ` [PATCH 04/16] t2018: teach do_checkout() to accept `!` arg Denton Liu
2019-12-28  8:34   ` Eric Sunshine
2019-12-27 13:47 ` [PATCH 05/16] t2018: don't lose return code of git commands Denton Liu
2019-12-27 21:42   ` Eric Sunshine
2020-01-01  8:48     ` Denton Liu
2020-01-01  9:21       ` Eric Sunshine
2020-01-02 18:26       ` Junio C Hamano
2019-12-27 13:47 ` [PATCH 06/16] t2018: replace "sha" with "oid" Denton Liu
2019-12-27 13:47 ` [PATCH 07/16] t3030: use test_path_is_missing() Denton Liu
2019-12-27 13:47 ` [PATCH 08/16] t3310: extract common no_notes_merge_left() Denton Liu
2019-12-28  7:20   ` Eric Sunshine
2019-12-30 20:38     ` Jakub Narebski
2019-12-27 13:47 ` [PATCH 09/16] t3415: stop losing return codes of git commands Denton Liu
2019-12-27 13:47 ` [PATCH 10/16] t3415: increase granularity of test_auto_{fixup,squash}() Denton Liu
2019-12-27 13:47 ` [PATCH 11/16] t3419: stop losing return code of git command Denton Liu
2019-12-27 13:47 ` [PATCH 12/16] t3504: don't use `test_must_fail test_cmp` Denton Liu
2019-12-27 20:39   ` Johannes Sixt
2019-12-27 22:48     ` Junio C Hamano
2019-12-27 13:47 ` [PATCH 13/16] t3507: fix indentation Denton Liu
2019-12-27 13:47 ` [PATCH 14/16] t3507: use test_path_is_missing() Denton Liu
2019-12-27 13:47 ` [PATCH 15/16] t4124: only mark git command with test_must_fail Denton Liu
2019-12-27 13:47 ` [PATCH 16/16] t4124: let sed open its own files Denton Liu
2019-12-30 22:52   ` Jakub Narebski
2019-12-30 23:27     ` Junio C Hamano
2020-01-01  8:24       ` Denton Liu
2020-01-01  8:33         ` Eric Sunshine
2020-01-01  8:53           ` Denton Liu
2020-01-07  4:52 ` [PATCH v2 00/16] t: replace incorrect test_must_fail usage (part 2) Denton Liu
2020-01-07  4:52   ` [PATCH v2 01/16] t2018: remove trailing space from test description Denton Liu
2020-01-07  4:52   ` [PATCH v2 02/16] t2018: add space between function name and () Denton Liu
2020-01-07  4:53   ` [PATCH v2 03/16] t2018: improve style of if-statement Denton Liu
2020-01-07  4:53   ` [PATCH v2 04/16] t2018: use test_expect_code for failing git commands Denton Liu
2020-01-12 10:50     ` Eric Sunshine
2020-01-26 20:23     ` Denton Liu [this message]
2020-01-07  4:53   ` [PATCH v2 05/16] t2018: teach do_checkout() to accept `!` arg Denton Liu
2020-01-07  4:53   ` [PATCH v2 06/16] t2018: don't lose return code of git commands Denton Liu
2020-01-07  4:53   ` [PATCH v2 07/16] t2018: replace "sha" with "oid" Denton Liu
2020-01-07  4:53   ` [PATCH v2 08/16] t3030: use test_path_is_missing() Denton Liu
2020-01-07  4:53   ` [PATCH v2 09/16] t3310: extract common notes_merge_files_gone() Denton Liu
2020-01-07  4:53   ` [PATCH v2 10/16] t3415: stop losing return codes of git commands Denton Liu
2020-01-07  4:53   ` [PATCH v2 11/16] t3415: increase granularity of test_auto_{fixup,squash}() Denton Liu
2020-01-07  4:53   ` [PATCH v2 12/16] t3419: stop losing return code of git command Denton Liu
2020-01-07  4:53   ` [PATCH v2 13/16] t3504: do check for conflict marker after failed cherry-pick Denton Liu
2020-01-07  4:53   ` [PATCH v2 14/16] t3507: fix indentation Denton Liu
2020-01-07  4:53   ` [PATCH v2 15/16] t3507: use test_path_is_missing() Denton Liu
2020-01-07  4:53   ` [PATCH v2 16/16] t4124: only mark git command with test_must_fail Denton Liu
2020-01-10 21:45   ` [PATCH v2 00/16] t: replace incorrect test_must_fail usage (part 2) Eric Sunshine

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=4af0c20e2981ed7e361083a71cb25b9f4a55fa4f.1580069736.git.liu.denton@gmail.com \
    --to=liu.denton@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=jnareb@gmail.com \
    --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.
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).