git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/2] hook tests: pre-push test style & test accurace
@ 2022-02-18 20:52 Ævar Arnfjörð Bjarmason
  2022-02-18 20:52 ` [PATCH 1/2] hook tests: test for exact "pre-push" hook input Ævar Arnfjörð Bjarmason
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-18 20:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Bagas Sanjaya, Emily Shaffer, Aaron Schrab,
	Ævar Arnfjörð Bjarmason

A trivial topic to fix a blind spot in the test coverage for pre-push
hooks, and to fix miscellaneous issues in that test while we're at it.

These patches have been on-list before as part of a much bigger topic
submission. I opted to split these out to make the continuation of
these larger hook topics easier to digest.

The last iteration was at [1] and [2]. As the range-diff to those
patches below shows there's been no change since then.

1. https://lore.kernel.org/git/patch-v5-28.36-957691f0b6d-20210902T125111Z-avarab@gmail.com
2. https://lore.kernel.org/git/patch-v5-29.36-88fe2621549-20210902T125111Z-avarab@gmail.com

Ævar Arnfjörð Bjarmason (2):
  hook tests: test for exact "pre-push" hook input
  hook tests: use a modern style for "pre-push" tests

 t/t5571-pre-push-hook.sh | 94 ++++++++++++++++++++++------------------
 1 file changed, 53 insertions(+), 41 deletions(-)

Range-diff:
1:  957691f0b6d = 1:  7cf279205eb hook tests: test for exact "pre-push" hook input
2:  88fe2621549 = 2:  8035594be8b hook tests: use a modern style for "pre-push" tests
-- 
2.35.1.1031.g277d4562d2e


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] hook tests: test for exact "pre-push" hook input
  2022-02-18 20:52 [PATCH 0/2] hook tests: pre-push test style & test accurace Ævar Arnfjörð Bjarmason
@ 2022-02-18 20:52 ` Ævar Arnfjörð Bjarmason
  2022-02-18 20:52 ` [PATCH 2/2] hook tests: use a modern style for "pre-push" tests Ævar Arnfjörð Bjarmason
  2022-02-19  4:16 ` [PATCH 0/2] hook tests: pre-push test style & test accurace Taylor Blau
  2 siblings, 0 replies; 4+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-18 20:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Bagas Sanjaya, Emily Shaffer, Aaron Schrab,
	Ævar Arnfjörð Bjarmason

Extend the tests added in ec55559f937 (push: Add support for pre-push
hooks, 2013-01-13) to exhaustively test for the exact input we're
expecting. This ensures that we e.g. don't miss a trailing newline.

Appending to a file called "actual" is the established convention in
this test for hooks, see the rest of the tests added in
ec55559f937 (push: Add support for pre-push hooks, 2013-01-13). Let's
follow that convention here.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t5571-pre-push-hook.sh | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/t/t5571-pre-push-hook.sh b/t/t5571-pre-push-hook.sh
index 660f876eec2..47f6eb509d6 100755
--- a/t/t5571-pre-push-hook.sh
+++ b/t/t5571-pre-push-hook.sh
@@ -11,7 +11,7 @@ HOOKDIR="$(git rev-parse --git-dir)/hooks"
 HOOK="$HOOKDIR/pre-push"
 mkdir -p "$HOOKDIR"
 write_script "$HOOK" <<EOF
-cat >/dev/null
+cat >actual
 exit 0
 EOF
 
@@ -20,10 +20,16 @@ test_expect_success 'setup' '
 	git init --bare repo1 &&
 	git remote add parent1 repo1 &&
 	test_commit one &&
-	git push parent1 HEAD:foreign
+	cat >expect <<-EOF &&
+	HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero)
+	EOF
+
+	test_when_finished "rm actual" &&
+	git push parent1 HEAD:foreign &&
+	test_cmp expect actual
 '
 write_script "$HOOK" <<EOF
-cat >/dev/null
+cat >actual
 exit 1
 EOF
 
@@ -32,11 +38,18 @@ export COMMIT1
 
 test_expect_success 'push with failing hook' '
 	test_commit two &&
-	test_must_fail git push parent1 HEAD
+	cat >expect <<-EOF &&
+	HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero)
+	EOF
+
+	test_when_finished "rm actual" &&
+	test_must_fail git push parent1 HEAD &&
+	test_cmp expect actual
 '
 
 test_expect_success '--no-verify bypasses hook' '
-	git push --no-verify parent1 HEAD
+	git push --no-verify parent1 HEAD &&
+	test_path_is_missing actual
 '
 
 COMMIT2="$(git rev-parse HEAD)"
-- 
2.35.1.1031.g277d4562d2e


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] hook tests: use a modern style for "pre-push" tests
  2022-02-18 20:52 [PATCH 0/2] hook tests: pre-push test style & test accurace Ævar Arnfjörð Bjarmason
  2022-02-18 20:52 ` [PATCH 1/2] hook tests: test for exact "pre-push" hook input Ævar Arnfjörð Bjarmason
@ 2022-02-18 20:52 ` Ævar Arnfjörð Bjarmason
  2022-02-19  4:16 ` [PATCH 0/2] hook tests: pre-push test style & test accurace Taylor Blau
  2 siblings, 0 replies; 4+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-18 20:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Bagas Sanjaya, Emily Shaffer, Aaron Schrab,
	Ævar Arnfjörð Bjarmason

Indent the here-docs and use "test_cmp" instead of "diff" in tests
added in ec55559f937 (push: Add support for pre-push hooks,
2013-01-13). Let's also use the more typical "expect" instead of
"expected" to be consistent with the rest of the test file.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t5571-pre-push-hook.sh | 71 ++++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 36 deletions(-)

diff --git a/t/t5571-pre-push-hook.sh b/t/t5571-pre-push-hook.sh
index 47f6eb509d6..96d6ecc0af7 100755
--- a/t/t5571-pre-push-hook.sh
+++ b/t/t5571-pre-push-hook.sh
@@ -61,15 +61,15 @@ echo "$2" >>actual
 cat >>actual
 EOF
 
-cat >expected <<EOF
-parent1
-repo1
-refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
-EOF
-
 test_expect_success 'push with hook' '
+	cat >expect <<-EOF &&
+	parent1
+	repo1
+	refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
+	EOF
+
 	git push parent1 main:foreign &&
-	diff expected actual
+	test_cmp expect actual
 '
 
 test_expect_success 'add a branch' '
@@ -80,49 +80,48 @@ test_expect_success 'add a branch' '
 COMMIT3="$(git rev-parse HEAD)"
 export COMMIT3
 
-cat >expected <<EOF
-parent1
-repo1
-refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
-EOF
-
 test_expect_success 'push to default' '
+	cat >expect <<-EOF &&
+	parent1
+	repo1
+	refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
+	EOF
 	git push &&
-	diff expected actual
+	test_cmp expect actual
 '
 
-cat >expected <<EOF
-parent1
-repo1
-refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
-HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
-EOF
-
 test_expect_success 'push non-branches' '
+	cat >expect <<-EOF &&
+	parent1
+	repo1
+	refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
+	HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
+	EOF
+
 	git push parent1 one:tag1 HEAD~:refs/heads/prev &&
-	diff expected actual
+	test_cmp expect actual
 '
 
-cat >expected <<EOF
-parent1
-repo1
-(delete) $ZERO_OID refs/heads/prev $COMMIT2
-EOF
-
 test_expect_success 'push delete' '
+	cat >expect <<-EOF &&
+	parent1
+	repo1
+	(delete) $ZERO_OID refs/heads/prev $COMMIT2
+	EOF
+
 	git push parent1 :prev &&
-	diff expected actual
+	test_cmp expect actual
 '
 
-cat >expected <<EOF
-repo1
-repo1
-HEAD $COMMIT3 refs/heads/other $ZERO_OID
-EOF
-
 test_expect_success 'push to URL' '
+	cat >expect <<-EOF &&
+	repo1
+	repo1
+	HEAD $COMMIT3 refs/heads/other $ZERO_OID
+	EOF
+
 	git push repo1 HEAD &&
-	diff expected actual
+	test_cmp expect actual
 '
 
 test_expect_success 'set up many-ref tests' '
-- 
2.35.1.1031.g277d4562d2e


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] hook tests: pre-push test style & test accurace
  2022-02-18 20:52 [PATCH 0/2] hook tests: pre-push test style & test accurace Ævar Arnfjörð Bjarmason
  2022-02-18 20:52 ` [PATCH 1/2] hook tests: test for exact "pre-push" hook input Ævar Arnfjörð Bjarmason
  2022-02-18 20:52 ` [PATCH 2/2] hook tests: use a modern style for "pre-push" tests Ævar Arnfjörð Bjarmason
@ 2022-02-19  4:16 ` Taylor Blau
  2 siblings, 0 replies; 4+ messages in thread
From: Taylor Blau @ 2022-02-19  4:16 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Bagas Sanjaya, Emily Shaffer, Aaron Schrab

On Fri, Feb 18, 2022 at 09:52:57PM +0100, Ævar Arnfjörð Bjarmason wrote:
> A trivial topic to fix a blind spot in the test coverage for pre-push
> hooks, and to fix miscellaneous issues in that test while we're at it.

Indeed; both look good to me.

Thanks,
Taylor

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-19  4:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-18 20:52 [PATCH 0/2] hook tests: pre-push test style & test accurace Ævar Arnfjörð Bjarmason
2022-02-18 20:52 ` [PATCH 1/2] hook tests: test for exact "pre-push" hook input Ævar Arnfjörð Bjarmason
2022-02-18 20:52 ` [PATCH 2/2] hook tests: use a modern style for "pre-push" tests Ævar Arnfjörð Bjarmason
2022-02-19  4:16 ` [PATCH 0/2] hook tests: pre-push test style & test accurace Taylor Blau

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).