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>,
	"Emily Shaffer" <emilyshaffer@google.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 07/10] fetch+push tests: have tests clean up their own mess
Date: Wed,  2 Mar 2022 14:22:26 +0100	[thread overview]
Message-ID: <patch-07.10-7ce22dbe738-20220302T131859Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-00.10-00000000000-20220302T131859Z-avarab@gmail.com>

Change the "t5516-fetch-push.sh" test code to make use of
"test_when_finished" to remove data instead of having tests clean up
leftover data from earlier tests, which may or may not be
there (e.g. depending on the --run=* option).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t5516-fetch-push.sh | 50 +++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index e4bb7581568..fbe0a72b0b2 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -23,7 +23,8 @@ D=$(pwd)
 
 mk_empty () {
 	repo_name="$1"
-	rm -fr "$repo_name" &&
+	test_when_finished "rm -rf \"$repo_name\"" &&
+	test_path_is_missing "$repo_name" &&
 	git init "$repo_name" &&
 	git -C "$repo_name" config receive.denyCurrentBranch warn
 }
@@ -86,7 +87,7 @@ mk_test_with_hooks() {
 }
 
 mk_child() {
-	rm -rf "$2" &&
+	test_when_finished "rm -rf \"$2\"" &&
 	git clone "$1" "$2"
 }
 
@@ -191,32 +192,32 @@ grep_wrote () {
 	grep 'write_pack_file/wrote.*"value":"'$1'"' $2
 }
 
-test_expect_success 'push with negotiation' '
-	# Without negotiation
+test_expect_success 'push without negotiation' '
 	mk_empty testrepo &&
 	git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
 	test_commit -C testrepo unrelated_commit &&
 	git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
-	echo now pushing without negotiation &&
+	test_when_finished "rm event" &&
 	GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main &&
-	grep_wrote 5 event && # 2 commits, 2 trees, 1 blob
+	grep_wrote 5 event # 2 commits, 2 trees, 1 blob
+'
 
-	# Same commands, but with negotiation
-	rm event &&
+test_expect_success 'push with negotiation' '
 	mk_empty testrepo &&
 	git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
 	test_commit -C testrepo unrelated_commit &&
 	git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
+	test_when_finished "rm event" &&
 	GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main &&
 	grep_wrote 2 event # 1 commit, 1 tree
 '
 
 test_expect_success 'push with negotiation proceeds anyway even if negotiation fails' '
-	rm event &&
 	mk_empty testrepo &&
 	git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
 	test_commit -C testrepo unrelated_commit &&
 	git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
+	test_when_finished "rm event" &&
 	GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \
 		git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
 	grep_wrote 5 event && # 2 commits, 2 trees, 1 blob
@@ -1323,7 +1324,7 @@ done
 
 test_expect_success 'fetch follows tags by default' '
 	mk_test testrepo heads/main &&
-	rm -fr src dst &&
+	test_when_finished "rm -rf src" &&
 	git init src &&
 	(
 		cd src &&
@@ -1333,6 +1334,7 @@ test_expect_success 'fetch follows tags by default' '
 		sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 |
 		sort -k 3 >../expect
 	) &&
+	test_when_finished "rm -rf dst" &&
 	git init dst &&
 	(
 		cd dst &&
@@ -1358,8 +1360,9 @@ test_expect_success 'peeled advertisements are not considered ref tips' '
 
 test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' '
 	mk_test testrepo heads/main &&
-	rm -fr src dst &&
+	test_when_finished "rm -rf src" &&
 	git init src &&
+	test_when_finished "rm -rf dst" &&
 	git init --bare dst &&
 	(
 		cd src &&
@@ -1382,8 +1385,9 @@ test_expect_success 'pushing a specific ref applies remote.$name.push as refmap'
 
 test_expect_success 'with no remote.$name.push, it is not used as refmap' '
 	mk_test testrepo heads/main &&
-	rm -fr src dst &&
+	test_when_finished "rm -rf src" &&
 	git init src &&
+	test_when_finished "rm -rf dst" &&
 	git init --bare dst &&
 	(
 		cd src &&
@@ -1404,8 +1408,9 @@ test_expect_success 'with no remote.$name.push, it is not used as refmap' '
 
 test_expect_success 'with no remote.$name.push, upstream mapping is used' '
 	mk_test testrepo heads/main &&
-	rm -fr src dst &&
+	test_when_finished "rm -rf src" &&
 	git init src &&
+	test_when_finished "rm -rf dst" &&
 	git init --bare dst &&
 	(
 		cd src &&
@@ -1433,8 +1438,9 @@ test_expect_success 'with no remote.$name.push, upstream mapping is used' '
 
 test_expect_success 'push does not follow tags by default' '
 	mk_test testrepo heads/main &&
-	rm -fr src dst &&
+	test_when_finished "rm -rf src" &&
 	git init src &&
+	test_when_finished "rm -rf dst" &&
 	git init --bare dst &&
 	(
 		cd src &&
@@ -1456,8 +1462,9 @@ test_expect_success 'push does not follow tags by default' '
 
 test_expect_success 'push --follow-tags only pushes relevant tags' '
 	mk_test testrepo heads/main &&
-	rm -fr src dst &&
+	test_when_finished "rm -rf src" &&
 	git init src &&
+	test_when_finished "rm -rf dst" &&
 	git init --bare dst &&
 	(
 		cd src &&
@@ -1495,9 +1502,9 @@ EOF
 '
 
 test_expect_success 'pushing a tag pushes the tagged object' '
-	rm -rf dst.git &&
 	blob=$(echo unreferenced | git hash-object -w --stdin) &&
 	git tag -m foo tag-of-blob $blob &&
+	test_when_finished "rm -rf dst.git" &&
 	git init --bare dst.git &&
 	git push dst.git tag-of-blob &&
 	# the receiving index-pack should have noticed
@@ -1508,7 +1515,7 @@ test_expect_success 'pushing a tag pushes the tagged object' '
 '
 
 test_expect_success 'push into bare respects core.logallrefupdates' '
-	rm -rf dst.git &&
+	test_when_finished "rm -rf dst.git" &&
 	git init --bare dst.git &&
 	git -C dst.git config core.logallrefupdates true &&
 
@@ -1526,7 +1533,7 @@ test_expect_success 'push into bare respects core.logallrefupdates' '
 '
 
 test_expect_success 'fetch into bare respects core.logallrefupdates' '
-	rm -rf dst.git &&
+	test_when_finished "rm -rf dst.git" &&
 	git init --bare dst.git &&
 	(
 		cd dst.git &&
@@ -1547,6 +1554,7 @@ test_expect_success 'fetch into bare respects core.logallrefupdates' '
 '
 
 test_expect_success 'receive.denyCurrentBranch = updateInstead' '
+	mk_empty testrepo &&
 	git push testrepo main &&
 	(
 		cd testrepo &&
@@ -1649,7 +1657,7 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' '
 	) &&
 
 	# (5) push into void
-	rm -fr void &&
+	test_when_finished "rm -rf void" &&
 	git init void &&
 	(
 		cd void &&
@@ -1671,7 +1679,7 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' '
 '
 
 test_expect_success 'updateInstead with push-to-checkout hook' '
-	rm -fr testrepo &&
+	test_when_finished "rm -rf testrepo" &&
 	git init testrepo &&
 	git -C testrepo pull .. main &&
 	git -C testrepo reset --hard HEAD^^ &&
@@ -1730,7 +1738,7 @@ test_expect_success 'updateInstead with push-to-checkout hook' '
 	) &&
 
 	# push into void
-	rm -fr void &&
+	test_when_finished "rm -rf void" &&
 	git init void &&
 	git -C void config receive.denyCurrentBranch updateInstead &&
 	write_script void/.git/hooks/push-to-checkout <<-\EOF &&
-- 
2.35.1.1228.g56895c6ee86


  parent reply	other threads:[~2022-03-02 13:23 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02 13:22 [PATCH 00/10] tests: add and use a "test_hook" wrapper + hook fixes Ævar Arnfjörð Bjarmason
2022-03-02 13:22 ` [PATCH 01/10] hook tests: turn exit code assertions into a loop Ævar Arnfjörð Bjarmason
2022-03-02 20:55   ` Junio C Hamano
2022-03-02 13:22 ` [PATCH 02/10] t5540: don't rely on "hook/post-update.sample" Ævar Arnfjörð Bjarmason
2022-03-02 21:06   ` Junio C Hamano
2022-03-02 13:22 ` [PATCH 03/10] tests: assume the hooks are disabled by default Ævar Arnfjörð Bjarmason
2022-03-02 21:13   ` Junio C Hamano
2022-03-02 13:22 ` [PATCH 04/10] bugreport tests: tighten up "git bugreport -s hooks" test Ævar Arnfjörð Bjarmason
2022-03-02 21:22   ` Junio C Hamano
2022-03-02 13:22 ` [PATCH 05/10] tests: indent and add hook setup to "test_expect_success" Ævar Arnfjörð Bjarmason
2022-03-02 21:27   ` Junio C Hamano
2022-03-02 13:22 ` [PATCH 06/10] hook tests: get rid of unnecessary sub-shells Ævar Arnfjörð Bjarmason
2022-03-02 21:31   ` Junio C Hamano
2022-03-02 13:22 ` Ævar Arnfjörð Bjarmason [this message]
2022-03-02 21:44   ` [PATCH 07/10] fetch+push tests: have tests clean up their own mess Junio C Hamano
2022-03-02 13:22 ` [PATCH 08/10] test-lib-functions: add and use a "test_hook" wrapper Ævar Arnfjörð Bjarmason
2022-03-02 21:59   ` Junio C Hamano
2022-03-02 13:22 ` [PATCH 09/10] tests: change "mkdir -p && write_script" to use "test_hook" Ævar Arnfjörð Bjarmason
2022-03-02 22:06   ` Junio C Hamano
2022-03-02 13:22 ` [PATCH 10/10] tests: change "cat && chmod +x" " Ævar Arnfjörð Bjarmason
2022-03-03  5:46   ` Eric Sunshine
2022-03-02 22:38 ` [PATCH 00/10] tests: add and use a "test_hook" wrapper + hook fixes Junio C Hamano
2022-03-07 12:43 ` [PATCH v2 " Ævar Arnfjörð Bjarmason
2022-03-07 12:43   ` [PATCH v2 01/10] hook tests: turn exit code assertions into a loop Ævar Arnfjörð Bjarmason
2022-03-07 12:43   ` [PATCH v2 02/10] t5540: don't rely on "hook/post-update.sample" Ævar Arnfjörð Bjarmason
2022-03-07 12:43   ` [PATCH v2 03/10] tests: assume the hooks are disabled by default Ævar Arnfjörð Bjarmason
2022-03-07 12:43   ` [PATCH v2 04/10] bugreport tests: tighten up "git bugreport -s hooks" test Ævar Arnfjörð Bjarmason
2022-03-07 12:43   ` [PATCH v2 05/10] tests: indent and add hook setup to "test_expect_success" Ævar Arnfjörð Bjarmason
2022-03-07 12:43   ` [PATCH v2 06/10] hook tests: get rid of unnecessary sub-shells Ævar Arnfjörð Bjarmason
2022-03-07 12:43   ` [PATCH v2 07/10] fetch+push tests: have tests clean up their own mess Ævar Arnfjörð Bjarmason
2022-03-07 12:43   ` [PATCH v2 08/10] test-lib-functions: add and use a "test_hook" wrapper Ævar Arnfjörð Bjarmason
2022-03-07 12:43   ` [PATCH v2 09/10] tests: change "mkdir -p && write_script" to use "test_hook" Ævar Arnfjörð Bjarmason
2022-03-07 12:43   ` [PATCH v2 10/10] tests: change "cat && chmod +x" " Ævar Arnfjörð Bjarmason
2022-03-07 21:26   ` [PATCH v2 00/10] tests: add and use a "test_hook" wrapper + hook fixes Junio C Hamano
2022-03-17 10:13   ` [PATCH v3 00/13] " Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 01/13] test-lib-functions: add and use a "test_hook" wrapper Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 02/13] hook tests: turn exit code assertions into a loop Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 03/13] http tests: don't rely on "hook/post-update.sample" Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 04/13] tests: assume the hooks are disabled by default Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 05/13] bugreport tests: tighten up "git bugreport -s hooks" test Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 06/13] fetch+push tests: use "test_hook" and "test_when_finished" pattern Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 07/13] gc + p4 tests: use "test_hook", remove sub-shells Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 08/13] tests: change "cat && chmod +x" to use "test_hook" Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 09/13] tests: change "mkdir -p && write_script" " Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 10/13] tests: use "test_hook" for misc "mkdir -p" and "chmod" cases Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 11/13] tests: extend "test_hook" for "rm" and "chmod -x", convert "$HOOK" Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 12/13] proc-receive hook tests: use "test_hook" instead of "write_script" Ævar Arnfjörð Bjarmason
2022-03-17 10:13     ` [PATCH v3 13/13] http tests: use "test_hook" for "smart" and "dumb" http tests Ævar Arnfjörð Bjarmason
2022-03-17 16:31     ` [PATCH v3 00/13] tests: add and use a "test_hook" wrapper + hook fixes Junio C Hamano
2022-03-17 21:04       ` Ævar Arnfjörð Bjarmason
2022-03-17 21:40         ` Junio C Hamano

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-07.10-7ce22dbe738-20220302T131859Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=emilyshaffer@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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 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.