git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/5] t6036: prefer test_when_finished to manual cleanup in following test

From
Elijah Newren <newren@gmail.com>
Date
May 24, 2018, 07:04 UTC
Message-ID
<20180524070439.6367-6-newren@gmail.com>
In-Reply-To
<20180524070439.6367-1-newren@gmail.com>

Manually cleaning up from former tests in subsequent ones breaks the ability to select which tests we want to run. Use test_when_finished to avoid this problem.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 t/t6036-recursive-corner-cases.sh | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/t/t6036-recursive-corner-cases.sh b/t/t6036-recursive-corner-cases.sh
index e5f167a06e..b5621303d6 100755
--- a/t/t6036-recursive-corner-cases.sh
+++ b/t/t6036-recursive-corner-cases.sh
@@ -4,12 +4,6 @@ test_description='recursive merge corner cases involving criss-cross merges'
 
 . ./test-lib.sh
 
-get_clean_checkout () {
-	git reset --hard &&
-	git clean -fdqx &&
-	git checkout "$1"
-}
-
 #
 #  L1  L2
 #   o---o
@@ -445,10 +439,12 @@ test_expect_success 'setup differently handled merges of directory/file conflict
 '
 
 test_expect_success 'merge of D & E1 fails but has appropriate contents' '
+	test_when_finished "git -C directory-file reset --hard" &&
+	test_when_finished "git -C directory-file clean -fdqx" &&
 	(
 		cd directory-file &&
 
-		get_clean_checkout D^0 &&
+		git checkout D^0 &&
 
 		test_must_fail git merge -s recursive E1^0 &&
 
@@ -468,10 +464,12 @@ test_expect_success 'merge of D & E1 fails but has appropriate contents' '
 '
 
 test_expect_success 'merge of E1 & D fails but has appropriate contents' '
+	test_when_finished "git -C directory-file reset --hard" &&
+	test_when_finished "git -C directory-file clean -fdqx" &&
 	(
 		cd directory-file &&
 
-		get_clean_checkout E1^0 &&
+		git checkout E1^0 &&
 
 		test_must_fail git merge -s recursive D^0 &&
 
@@ -491,10 +489,12 @@ test_expect_success 'merge of E1 & D fails but has appropriate contents' '
 '
 
 test_expect_success 'merge of D & E2 fails but has appropriate contents' '
+	test_when_finished "git -C directory-file reset --hard" &&
+	test_when_finished "git -C directory-file clean -fdqx" &&
 	(
 		cd directory-file &&
 
-		get_clean_checkout D^0 &&
+		git checkout D^0 &&
 
 		test_must_fail git merge -s recursive E2^0 &&
 
@@ -516,10 +516,12 @@ test_expect_success 'merge of D & E2 fails but has appropriate contents' '
 '
 
 test_expect_success 'merge of E2 & D fails but has appropriate contents' '
+	test_when_finished "git -C directory-file reset --hard" &&
+	test_when_finished "git -C directory-file clean -fdqx" &&
 	(
 		cd directory-file &&
 
-		get_clean_checkout E2^0 &&
+		git checkout E2^0 &&
 
 		test_must_fail git merge -s recursive D^0 &&
 
-- 
2.17.0.1.gda85003413
Previous: Elijah Newren
Message 11 of 11 in “Modernize some testcases for merge-recursive corner cases”
  1. 0/5 Modernize some testcases for merge-recursive corner casesElijah Newren, May 24, 2018
  2. 1/5 t6036, t6042: use test_create_repo to keep tests independentElijah Newren, May 24, 2018
  3. 2/5 t6036, t6042: use test_line_count instead of wc -lElijah Newren, May 24, 2018
  4. SZEDER GáborMay 24, 2018
  5. SZEDER GáborMay 24, 2018
  6. Elijah NewrenMay 24, 2018
  7. Junio C HamanoMay 25, 2018
  8. Elijah NewrenMay 26, 2018
  9. 4/5 t6036, t6042: prefer test_cmp to sequences of testElijah Newren, May 24, 2018
  10. 3/5 t6036, t6042: prefer test_path_is_file, test_path_is_missingElijah Newren, May 24, 2018
  11. 5/5 t6036: prefer test_when_finished to manual cleanup in following testElijah Newren, May 24, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.