git.vger.kernel.org archive mirror
 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 05/15] diff tests: don't ignore "git diff" exit code in "read" loop
Date: Mon,  7 Mar 2022 13:48:56 +0100	[thread overview]
Message-ID: <patch-v2-05.15-b1aeac3f68e-20220307T124817Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-v2-00.15-00000000000-20220307T124817Z-avarab@gmail.com>

Fix a test pattern that originated in f1af60bdba4 (Support 'diff=pgm'
attribute, 2007-04-22) so that we'll stop using "git diff" on the
left-hand-side of a pipe, and thus ignoring its exit code.

Rather than use intermediate files let's rewrite these tests to a much
simpler but more exhaustive "test_tmp" where we'll ignore certain
fields in the output.

Note that this is not a faithful conversion of the previous
"read/test" in some cases, as we were ignoring more fields there than
we strictly needed to. Now we'll "test_cmp" everything we can, and
only ignore the likes of paths to $TEMPDIR etc.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t4020-diff-external.sh | 104 ++++++++++++++++++++-------------------
 1 file changed, 53 insertions(+), 51 deletions(-)

diff --git a/t/t4020-diff-external.sh b/t/t4020-diff-external.sh
index 879ee04d291..1219f8bd4c0 100755
--- a/t/t4020-diff-external.sh
+++ b/t/t4020-diff-external.sh
@@ -24,16 +24,12 @@ test_expect_success setup '
 '
 
 test_expect_success 'GIT_EXTERNAL_DIFF environment' '
-
-	GIT_EXTERNAL_DIFF=echo git diff | {
-		read path oldfile oldhex oldmode newfile newhex newmode &&
-		test "z$path" = zfile &&
-		test "z$oldmode" = z100644 &&
-		test "z$newhex" = "z$ZERO_OID" &&
-		test "z$newmode" = z100644 &&
-		oh=$(git rev-parse --verify HEAD:file) &&
-		test "z$oh" = "z$oldhex"
-	}
+	cat >expect <<-EOF &&
+	file $(git rev-parse --verify HEAD:file) 100644 file $(test_oid zero) 100644
+	EOF
+	GIT_EXTERNAL_DIFF=echo git diff >out &&
+	cut -d" " -f1,3- <out >actual &&
+	test_cmp expect actual
 
 '
 
@@ -52,15 +48,14 @@ test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
 test_expect_success SYMLINKS 'typechange diff' '
 	rm -f file &&
 	ln -s elif file &&
-	GIT_EXTERNAL_DIFF=echo git diff  | {
-		read path oldfile oldhex oldmode newfile newhex newmode &&
-		test "z$path" = zfile &&
-		test "z$oldmode" = z100644 &&
-		test "z$newhex" = "z$ZERO_OID" &&
-		test "z$newmode" = z120000 &&
-		oh=$(git rev-parse --verify HEAD:file) &&
-		test "z$oh" = "z$oldhex"
-	} &&
+
+	cat >expect <<-EOF &&
+	file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 120000
+	EOF
+	GIT_EXTERNAL_DIFF=echo git diff >out &&
+	cut -d" " -f1,3-4,6- <out >actual &&
+	test_cmp expect actual &&
+
 	GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >actual &&
 	git diff >expect &&
 	test_cmp expect actual
@@ -70,15 +65,13 @@ test_expect_success 'diff.external' '
 	git reset --hard &&
 	echo third >file &&
 	test_config diff.external echo &&
-	git diff | {
-		read path oldfile oldhex oldmode newfile newhex newmode &&
-		test "z$path" = zfile &&
-		test "z$oldmode" = z100644 &&
-		test "z$newhex" = "z$ZERO_OID" &&
-		test "z$newmode" = z100644 &&
-		oh=$(git rev-parse --verify HEAD:file) &&
-		test "z$oh" = "z$oldhex"
-	}
+
+	cat >expect <<-EOF &&
+	file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 100644
+	EOF
+	git diff >out &&
+	cut -d" " -f1,3-4,6- <out >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success !SANITIZE_LEAK 'diff.external should apply only to diff' '
@@ -101,16 +94,12 @@ test_expect_success 'diff attribute' '
 
 	echo >.gitattributes "file diff=parrot" &&
 
-	git diff | {
-		read path oldfile oldhex oldmode newfile newhex newmode &&
-		test "z$path" = zfile &&
-		test "z$oldmode" = z100644 &&
-		test "z$newhex" = "z$ZERO_OID" &&
-		test "z$newmode" = z100644 &&
-		oh=$(git rev-parse --verify HEAD:file) &&
-		test "z$oh" = "z$oldhex"
-	}
-
+	cat >expect <<-EOF &&
+	file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 100644
+	EOF
+	git diff >out &&
+	cut -d" " -f1,3-4,6- <out >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success !SANITIZE_LEAK 'diff attribute should apply only to diff' '
@@ -132,16 +121,12 @@ test_expect_success 'diff attribute' '
 
 	echo >.gitattributes "file diff=color" &&
 
-	git diff | {
-		read path oldfile oldhex oldmode newfile newhex newmode &&
-		test "z$path" = zfile &&
-		test "z$oldmode" = z100644 &&
-		test "z$newhex" = "z$ZERO_OID" &&
-		test "z$newmode" = z100644 &&
-		oh=$(git rev-parse --verify HEAD:file) &&
-		test "z$oh" = "z$oldhex"
-	}
-
+	cat >expect <<-EOF &&
+	file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 100644
+	EOF
+	git diff >out &&
+	cut -d" " -f1,3-4,6- <out >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success !SANITIZE_LEAK 'diff attribute should apply only to diff' '
@@ -159,14 +144,26 @@ test_expect_success 'diff attribute and --no-ext-diff' '
 test_expect_success 'GIT_EXTERNAL_DIFF trumps diff.external' '
 	>.gitattributes &&
 	test_config diff.external "echo ext-global" &&
-	GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-env
+
+	cat >expect <<-EOF &&
+	ext-env file $(git rev-parse --verify HEAD:file) 100644 file $(test_oid zero) 100644
+	EOF
+	GIT_EXTERNAL_DIFF="echo ext-env" git diff >out &&
+	cut -d" " -f1-2,4- <out >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'attributes trump GIT_EXTERNAL_DIFF and diff.external' '
 	test_config diff.foo.command "echo ext-attribute" &&
 	test_config diff.external "echo ext-global" &&
 	echo "file diff=foo" >.gitattributes &&
-	GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-attribute
+
+	cat >expect <<-EOF &&
+	ext-attribute file $(git rev-parse --verify HEAD:file) 100644 file $(test_oid zero) 100644
+	EOF
+	GIT_EXTERNAL_DIFF="echo ext-env" git diff >out &&
+	cut -d" " -f1-2,4- <out >actual &&
+	test_cmp expect actual
 '
 
 test_expect_success 'no diff with -diff' '
@@ -212,7 +209,12 @@ test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
 	touch file.ext &&
 	git add file.ext &&
 	echo with extension > file.ext &&
-	GIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\.ext &&
+
+	cat >expect <<-EOF &&
+	file.ext file $(git rev-parse --verify HEAD:file) 100644 file.ext $(test_oid zero) 100644
+	EOF
+	GIT_EXTERNAL_DIFF=echo git diff file.ext >out &&
+	cut -d" " -f1,3- <out >actual &&
 	git update-index --force-remove file.ext &&
 	rm file.ext
 '
-- 
2.35.1.1242.gfeba0eae32b


  parent reply	other threads:[~2022-03-07 12:49 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   ` Ævar Arnfjörð Bjarmason [this message]
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   ` [PATCH v2 14/15] checkout tests: don't ignore "git <cmd>" exit code Ævar Arnfjörð Bjarmason
2022-03-07 12:49   ` [PATCH v2 15/15] rev-list simplify tests: don't ignore "git" " Æ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-05.15-b1aeac3f68e-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 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).