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

[PATCH v3 2/3] t6019: modernize tests with helper

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 19, 2022, 04:28 UTC
Message-ID
<5226da2123ee58992b0e723665c8d9c52d3a9544.1660883290.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1303.v3.git.1660883290.gitgitgadget@gmail.com>
From: Derrick Stolee <derrickstolee@github.com>

The tests in t6019 are repetitive, so create a helper that greatly simplifies the test script.

In addition, update the common pattern that places 'git rev-list' on the left side of a pipe, which can hide some exit codes. Send the output to a 'raw' file that is then consumed by other tools so the Git exit code is verified as zero. And since we're using --format anyway, switch to `git log`, so that we get the desired format and can avoid using sed.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 t/t6019-rev-list-ancestry-path.sh | 87 +++++++++----------------------
 1 file changed, 25 insertions(+), 62 deletions(-)
diff --git a/t/t6019-rev-list-ancestry-path.sh b/t/t6019-rev-list-ancestry-path.sh
index af57a04b7ff..5bd787a3c0a 100755
--- a/t/t6019-rev-list-ancestry-path.sh
+++ b/t/t6019-rev-list-ancestry-path.sh
@@ -50,73 +50,36 @@ test_expect_success setup '
 	test_commit M
 '
 
-test_expect_success 'rev-list D..M' '
-	test_write_lines E F G H I J K L M >expect &&
-	git rev-list --format=%s D..M |
-	sed -e "/^commit /d" |
-	sort >actual &&
-	test_cmp expect actual
-'
-
-test_expect_success 'rev-list --ancestry-path D..M' '
-	test_write_lines E F H I J L M >expect &&
-	git rev-list --ancestry-path --format=%s D..M |
-	sed -e "/^commit /d" |
-	sort >actual &&
-	test_cmp expect actual
-'
-
-test_expect_success 'rev-list D..M -- M.t' '
-	echo M >expect &&
-	git rev-list --format=%s D..M -- M.t |
-	sed -e "/^commit /d" >actual &&
-	test_cmp expect actual
-'
-
-test_expect_success 'rev-list --ancestry-path D..M -- M.t' '
-	echo M >expect &&
-	git rev-list --ancestry-path --format=%s D..M -- M.t |
-	sed -e "/^commit /d" >actual &&
-	test_cmp expect actual
-'
+test_ancestry () {
+	args=$1
+	expected=$2
+	test_expect_success "log $args" "
+		test_write_lines $expected >expect &&
+		git log --format=%s $args >raw &&
+
+		if test -n \"$expected\"
+		then
+			sort raw >actual &&
+			test_cmp expect actual
+		else
+			test_must_be_empty raw
+		fi
+	"
+}
 
-test_expect_success 'rev-list F...I' '
-	test_write_lines F G H I >expect &&
-	git rev-list --format=%s F...I |
-	sed -e "/^commit /d" |
-	sort >actual &&
-	test_cmp expect actual
-'
+test_ancestry "D..M" "E F G H I J K L M"
 
-test_expect_success 'rev-list --ancestry-path F...I' '
-	test_write_lines F H I >expect &&
-	git rev-list --ancestry-path --format=%s F...I |
-	sed -e "/^commit /d" |
-	sort >actual &&
-	test_cmp expect actual
-'
+test_ancestry "--ancestry-path D..M" "E F H I J L M"
 
-# G.t is dropped in an "-s ours" merge
-test_expect_success 'rev-list G..M -- G.t' '
-	git rev-list --format=%s G..M -- G.t |
-	sed -e "/^commit /d" >actual &&
-	test_must_be_empty actual
-'
+test_ancestry "D..M -- M.t" "M"
+test_ancestry "--ancestry-path D..M -- M.t" "M"
 
-test_expect_success 'rev-list --ancestry-path G..M -- G.t' '
-	echo L >expect &&
-	git rev-list --ancestry-path --format=%s G..M -- G.t |
-	sed -e "/^commit /d" >actual &&
-	test_cmp expect actual
-'
+test_ancestry "F...I" "F G H I"
+test_ancestry "--ancestry-path F...I" "F H I"
 
-test_expect_success 'rev-list --ancestry-path --simplify-merges G^..M -- G.t' '
-	test_write_lines G L >expect &&
-	git rev-list --ancestry-path --simplify-merges --format=%s G^..M -- G.t |
-	sed -e "/^commit /d" |
-	sort >actual &&
-	test_cmp expect actual
-'
+test_ancestry "G..M -- G.t" ""
+test_ancestry "--ancestry-path G..M -- G.t" "L"
+test_ancestry "--ancestry-path --simplify-merges G^..M -- G.t" "G L"
 
 #   b---bc
 #  / \ /
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 23 of 29 in “Allow --ancestry-path to take an argument”
  1. 0/2 Allow --ancestry-path to take an argumentElijah Newren via GitGitGadget, Aug 17, 2022
  2. 1/2 rev-list-options.txt: fix simple typoElijah Newren via GitGitGadget, Aug 17, 2022
  3. 2/2 revision: allow --ancestry-path to take an argumentElijah Newren via GitGitGadget, Aug 17, 2022
  4. Junio C HamanoAug 17, 2022
  5. Elijah NewrenAug 18, 2022
  6. 0/2 Allow --ancestry-path to take an argumentElijah Newren via GitGitGadget, Aug 18, 2022
  7. 1/2 rev-list-options.txt: fix simple typoElijah Newren via GitGitGadget, Aug 18, 2022
  8. 2/2 revision: allow --ancestry-path to take an argumentElijah Newren via GitGitGadget, Aug 18, 2022
  9. Derrick StoleeAug 18, 2022
  10. Ævar Arnfjörð BjarmasonAug 18, 2022
  11. Derrick StoleeAug 18, 2022
  12. Eric SunshineAug 18, 2022
  13. Elijah NewrenAug 19, 2022
  14. Ævar Arnfjörð BjarmasonAug 19, 2022
  15. Eric SunshineAug 18, 2022
  16. Elijah NewrenAug 19, 2022
  17. Jonathan TanAug 18, 2022
  18. Elijah NewrenAug 19, 2022
  19. Jonathan TanAug 19, 2022
  20. Junio C HamanoAug 18, 2022
  21. 0/3 Allow --ancestry-path to take an argumentElijah Newren via GitGitGadget, Aug 19, 2022
  22. 1/3 rev-list-options.txt: fix simple typoElijah Newren via GitGitGadget, Aug 19, 2022
  23. 2/3 t6019: modernize tests with helperDerrick Stolee via GitGitGadget, Aug 19, 2022
  24. 3/3 revision: allow --ancestry-path to take an argumentElijah Newren via GitGitGadget, Aug 19, 2022
  25. Junio C HamanoAug 19, 2022
  26. Elijah NewrenAug 20, 2022
  27. Derrick StoleeAug 19, 2022
  28. Junio C HamanoAug 19, 2022
  29. Elijah NewrenAug 20, 2022

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.