git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 10/25] t: use test_expect_code instead of hand-rolled comparison
Date: Fri, 20 Mar 2015 06:11:46 -0400	[thread overview]
Message-ID: <20150320101146.GJ12543@peff.net> (raw)
In-Reply-To: <20150320100429.GA17354@peff.net>

This makes our output in the event of a failure slightly
nicer, and it means that we do not break the &&-chain.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/t0040-parse-options.sh | 12 +++------
 t/t4035-diff-quiet.sh    | 66 +++++++++++++++++++++++-------------------------
 t/t4053-diff-no-index.sh |  4 +--
 3 files changed, 38 insertions(+), 44 deletions(-)

diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index a90c86b..b044785 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -172,12 +172,9 @@ test_expect_success 'long options' '
 '
 
 test_expect_success 'missing required value' '
-	test-parse-options -s;
-	test $? = 129 &&
-	test-parse-options --string;
-	test $? = 129 &&
-	test-parse-options --file;
-	test $? = 129
+	test_expect_code 129 test-parse-options -s &&
+	test_expect_code 129 test-parse-options --string &&
+	test_expect_code 129 test-parse-options --file
 '
 
 cat > expect << EOF
@@ -227,8 +224,7 @@ test_expect_success 'unambiguously abbreviated option with "="' '
 '
 
 test_expect_success 'ambiguously abbreviated option' '
-	test-parse-options --strin 123;
-	test $? = 129
+	test_expect_code 129 test-parse-options --strin 123
 '
 
 cat > expect << EOF
diff --git a/t/t4035-diff-quiet.sh b/t/t4035-diff-quiet.sh
index e8ae2a0..461f4bb 100755
--- a/t/t4035-diff-quiet.sh
+++ b/t/t4035-diff-quiet.sh
@@ -29,67 +29,65 @@ test_expect_success 'setup' '
 '
 
 test_expect_success 'git diff-tree HEAD^ HEAD' '
-	git diff-tree --quiet HEAD^ HEAD >cnt
-	test $? = 1 && test_line_count = 0 cnt
+	test_expect_code 1 git diff-tree --quiet HEAD^ HEAD >cnt &&
+	test_line_count = 0 cnt
 '
 test_expect_success 'git diff-tree HEAD^ HEAD -- a' '
-	git diff-tree --quiet HEAD^ HEAD -- a >cnt
-	test $? = 0 && test_line_count = 0 cnt
+	test_expect_code 0 git diff-tree --quiet HEAD^ HEAD -- a >cnt &&
+	test_line_count = 0 cnt
 '
 test_expect_success 'git diff-tree HEAD^ HEAD -- b' '
-	git diff-tree --quiet HEAD^ HEAD -- b >cnt
-	test $? = 1 && test_line_count = 0 cnt
+	test_expect_code 1 git diff-tree --quiet HEAD^ HEAD -- b >cnt &&
+	test_line_count = 0 cnt
 '
 # this diff outputs one line: sha1 of the given head
 test_expect_success 'echo HEAD | git diff-tree --stdin' '
-	echo $(git rev-parse HEAD) | git diff-tree --quiet --stdin >cnt
-	test $? = 1 && test_line_count = 1 cnt
+	echo $(git rev-parse HEAD) |
+	test_expect_code 1 git diff-tree --quiet --stdin >cnt &&
+	test_line_count = 1 cnt
 '
 test_expect_success 'git diff-tree HEAD HEAD' '
-	git diff-tree --quiet HEAD HEAD >cnt
-	test $? = 0 && test_line_count = 0 cnt
+	test_expect_code 0 git diff-tree --quiet HEAD HEAD >cnt &&
+	test_line_count = 0 cnt
 '
 test_expect_success 'git diff-files' '
-	git diff-files --quiet >cnt
-	test $? = 0 && test_line_count = 0 cnt
+	test_expect_code 0 git diff-files --quiet >cnt &&
+	test_line_count = 0 cnt
 '
 test_expect_success 'git diff-index --cached HEAD' '
-	git diff-index --quiet --cached HEAD >cnt
-	test $? = 0 && test_line_count = 0 cnt
+	test_expect_code 0 git diff-index --quiet --cached HEAD >cnt &&
+	test_line_count = 0 cnt
 '
 test_expect_success 'git diff-index --cached HEAD^' '
-	git diff-index --quiet --cached HEAD^ >cnt
-	test $? = 1 && test_line_count = 0 cnt
+	test_expect_code 1 git diff-index --quiet --cached HEAD^ >cnt &&
+	test_line_count = 0 cnt
 '
 test_expect_success 'git diff-index --cached HEAD^' '
 	echo text >>b &&
 	echo 3 >c &&
-	git add . && {
-		git diff-index --quiet --cached HEAD^ >cnt
-		test $? = 1 && test_line_count = 0 cnt
-	}
+	git add . &&
+	test_expect_code 1 git diff-index --quiet --cached HEAD^ >cnt &&
+	test_line_count = 0 cnt
 '
 test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' '
-	git commit -m "text in b" && {
-		git diff-tree --quiet -Stext HEAD^ HEAD -- b >cnt
-		test $? = 1 && test_line_count = 0 cnt
-	}
+	git commit -m "text in b" &&
+	test_expect_code 1 git diff-tree --quiet -Stext HEAD^ HEAD -- b >cnt &&
+	test_line_count = 0 cnt
 '
 test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' '
-	git diff-tree --quiet -Snot-found HEAD^ HEAD -- b >cnt
-	test $? = 0 && test_line_count = 0 cnt
+	test_expect_code 0 git diff-tree --quiet -Snot-found HEAD^ HEAD -- b >cnt &&
+	test_line_count = 0 cnt
 '
 test_expect_success 'git diff-files' '
-	echo 3 >>c && {
-		git diff-files --quiet >cnt
-		test $? = 1 && test_line_count = 0 cnt
-	}
+	echo 3 >>c &&
+	test_expect_code 1 git diff-files --quiet >cnt &&
+	test_line_count = 0 cnt
 '
+
 test_expect_success 'git diff-index --cached HEAD' '
-	git update-index c && {
-		git diff-index --quiet --cached HEAD >cnt
-		test $? = 1 && test_line_count = 0 cnt
-	}
+	git update-index c &&
+	test_expect_code 1 git diff-index --quiet --cached HEAD >cnt &&
+	test_line_count = 0 cnt
 '
 
 test_expect_success 'git diff, one file outside repo' '
diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh
index 2ab3c48..075ece6 100755
--- a/t/t4053-diff-no-index.sh
+++ b/t/t4053-diff-no-index.sh
@@ -17,8 +17,8 @@ test_expect_success 'setup' '
 '
 
 test_expect_success 'git diff --no-index directories' '
-	git diff --no-index a b >cnt
-	test $? = 1 && test_line_count = 14 cnt
+	test_expect_code 1 git diff --no-index a b >cnt &&
+	test_line_count = 14 cnt
 '
 
 test_expect_success 'git diff --no-index relative path outside repo' '
-- 
2.3.3.520.g3cfbb5d

  parent reply	other threads:[~2015-03-20 10:11 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-20 10:04 [PATCH 0/25] detecting &&-chain breakage Jeff King
2015-03-20 10:05 ` [PATCH 01/25] t/test-lib: introduce --chain-lint option Jeff King
2015-03-25  2:53   ` SZEDER Gábor
2015-03-25  3:05     ` Jeff King
2015-03-20 10:06 ` [PATCH 02/25] t: fix severe &&-chain breakage Jeff King
2015-03-20 10:06 ` [PATCH 03/25] t: fix moderate " Jeff King
2015-03-20 10:07 ` [PATCH 04/25] t: fix trivial " Jeff King
2015-03-20 10:07 ` [PATCH 05/25] t: assume test_cmp produces verbose output Jeff King
2015-03-20 10:09 ` [PATCH 06/25] t: use verbose instead of hand-rolled errors Jeff King
2015-03-20 10:09 ` [PATCH 07/25] t: use test_must_fail instead of hand-rolled blocks Jeff King
2015-03-20 10:10 ` [PATCH 08/25] t: fix &&-chaining issues around setup which might fail Jeff King
2015-03-20 10:11 ` [PATCH 09/25] t: use test_might_fail for diff and grep Jeff King
2015-03-20 10:11 ` Jeff King [this message]
2015-03-20 10:12 ` [PATCH 11/25] t: wrap complicated expect_code users in a block Jeff King
2015-03-20 10:12 ` [PATCH 12/25] t: avoid using ":" for comments Jeff King
2015-03-20 10:12 ` [PATCH 13/25] t3600: fix &&-chain breakage for setup commands Jeff King
2015-03-20 10:12 ` [PATCH 14/25] t7201: fix &&-chain breakage Jeff King
2015-03-20 10:13 ` [PATCH 15/25] t9502: " Jeff King
2015-03-20 17:48   ` Johannes Sixt
2015-03-20 18:03     ` Jeff King
2015-03-20 10:13 ` [PATCH 16/25] t6030: use modern test_* helpers Jeff King
2015-03-20 10:13 ` [PATCH 17/25] t0020: " Jeff King
2015-03-25  0:23   ` SZEDER Gábor
2015-03-25  2:56     ` Jeff King
2015-03-25  5:24       ` [PATCH 0/8] more &&-chaining test fixups Jeff King
2015-03-25  5:25         ` [PATCH 1/8] perf-lib: fix ignored exit code inside loop Jeff King
2015-03-25  5:28         ` [PATCH 2/8] t0020: fix ignored exit code inside loops Jeff King
2015-03-25  5:28         ` [PATCH 3/8] t3305: fix ignored exit code inside loop Jeff King
2015-03-25  8:40           ` Johan Herland
2015-03-25  5:29         ` [PATCH 4/8] t7701: " Jeff King
2015-03-25  5:29         ` [PATCH 5/8] t: fix some trivial cases of ignored exit codes in loops Jeff King
2015-03-25  5:30         ` [PATCH 6/8] t: simplify loop exit-code status variables Jeff King
2015-03-25 17:27           ` Junio C Hamano
2015-03-25 17:43             ` Jeff King
2015-03-25  5:31         ` [PATCH 7/8] t0020: use test_* helpers instead of hand-rolled messages Jeff King
2015-03-25  5:32         ` [PATCH 8/8] t9001: drop save_confirm helper Jeff King
2015-03-25 17:29         ` [PATCH 0/8] more &&-chaining test fixups Junio C Hamano
2015-03-20 10:13 ` [PATCH 18/25] t1301: use modern test_* helpers Jeff King
2015-03-24 23:51   ` SZEDER Gábor
2015-03-25  2:45     ` Jeff King
2015-03-20 10:13 ` [PATCH 19/25] t6034: " Jeff King
2015-03-24 23:43   ` SZEDER Gábor
2015-03-20 10:13 ` [PATCH 20/25] t4117: " Jeff King
2015-03-20 10:13 ` [PATCH 21/25] t9001: use test_when_finished Jeff King
2015-03-25  2:00   ` SZEDER Gábor
2015-03-25  2:47     ` Jeff King
2015-03-20 10:13 ` [PATCH 22/25] t0050: appease --chain-lint Jeff King
2015-03-20 10:13 ` [PATCH 23/25] t7004: fix embedded single-quotes Jeff King
2015-03-20 10:13 ` [PATCH 24/25] t0005: fix broken &&-chains Jeff King
2015-03-20 10:13 ` [PATCH 25/25] t4104: drop hand-rolled error reporting Jeff King
2015-03-20 10:23 ` [PATCH 0/25] detecting &&-chain breakage Jeff King
2015-03-20 14:28 ` Michael J Gruber
2015-03-20 14:32   ` [PATCH 26/27] t/*svn*: fix moderate " Michael J Gruber
2015-03-20 14:32     ` [PATCH 27/27] t9104: fix test for following larger parents Michael J Gruber
2015-03-20 18:04     ` [PATCH 26/27] t/*svn*: fix moderate &&-chain breakage Junio C Hamano
2015-03-20 19:35       ` Junio C Hamano
2015-03-20 20:02         ` Jeff King
2015-03-20 20:13           ` Jeff King
2015-03-23  9:36             ` Michael J Gruber
2015-03-20 17:57   ` [PATCH 0/25] detecting " Jeff King
2015-03-20 17:44 ` Junio C Hamano
2015-03-20 18:00   ` Junio C Hamano
2015-03-20 18:04     ` Jeff King
2015-03-20 18:33       ` Junio C Hamano
2015-03-20 23:18 ` Eric Sunshine
2015-03-21  8:19   ` Jeff King
2015-03-21 18:01     ` Junio C Hamano
2015-03-21 22:23       ` Jeff King

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=20150320101146.GJ12543@peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    /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).