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

[PATCH v4 1/4] t6300: use function to test trailer options

From
HGHariom Verma via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 13, 2021, 01:52 UTC
Message-ID
<410b02dbad20c77662dd4581f9985783ca08fc70.1613181163.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.726.v4.git.1613181163.gitgitgadget@gmail.com>
From: Hariom Verma <hariom18599@gmail.com>

Add a function to test trailer options. This will make tests look cleaner, as well as will make it easier to add new tests for trailers in the future.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Heba Waly <heba.waly@gmail.com>
Signed-off-by: Hariom Verma <hariom18599@gmail.com>
---
 t/t6300-for-each-ref.sh | 90 +++++++++++++++++++++--------------------
 1 file changed, 47 insertions(+), 43 deletions(-)
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index ca62e764b586..a8faddd18a9b 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -814,53 +814,57 @@ test_expect_success 'set up trailers for next test' '
 	EOF
 '
 
-test_expect_success '%(trailers:unfold) unfolds trailers' '
-	{
-		unfold <trailers
-		echo
-	} >expect &&
-	git for-each-ref --format="%(trailers:unfold)" refs/heads/main >actual &&
-	test_cmp expect actual &&
-	git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/main >actual &&
-	test_cmp expect actual
-'
+test_trailer_option () {
+	title=$1 option=$2
+	cat >expect
+	test_expect_success "$title" '
+		git for-each-ref --format="%($option)" refs/heads/main >actual &&
+		test_cmp expect actual &&
+		git for-each-ref --format="%(contents:$option)" refs/heads/main >actual &&
+		test_cmp expect actual
+	'
+}
 
-test_expect_success '%(trailers:only) shows only "key: value" trailers' '
-	{
-		grep -v patch.description <trailers &&
-		echo
-	} >expect &&
-	git for-each-ref --format="%(trailers:only)" refs/heads/main >actual &&
-	test_cmp expect actual &&
-	git for-each-ref --format="%(contents:trailers:only)" refs/heads/main >actual &&
-	test_cmp expect actual
-'
+test_trailer_option '%(trailers:unfold) unfolds trailers' \
+	'trailers:unfold' <<-EOF
+	$(unfold <trailers)
 
-test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
-	{
-		grep -v patch.description <trailers | unfold &&
-		echo
-	} >expect &&
-	git for-each-ref --format="%(trailers:only,unfold)" refs/heads/main >actual &&
-	test_cmp expect actual &&
-	git for-each-ref --format="%(trailers:unfold,only)" refs/heads/main >actual &&
-	test_cmp actual actual &&
-	git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/main >actual &&
-	test_cmp expect actual &&
-	git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/main >actual &&
-	test_cmp actual actual
-'
-
-test_expect_success '%(trailers) rejects unknown trailers arguments' '
-	# error message cannot be checked under i18n
-	cat >expect <<-EOF &&
+	EOF
+
+test_trailer_option '%(trailers:only) shows only "key: value" trailers' \
+	'trailers:only' <<-EOF
+	$(grep -v patch.description <trailers)
+
+	EOF
+
+test_trailer_option '%(trailers:only) and %(trailers:unfold) work together' \
+	'trailers:only,unfold' <<-EOF
+	$(grep -v patch.description <trailers | unfold)
+
+	EOF
+
+test_trailer_option '%(trailers:unfold) and %(trailers:only) work together' \
+	'trailers:unfold,only' <<-EOF
+	$(grep -v patch.description <trailers | unfold)
+
+	EOF
+
+test_failing_trailer_option () {
+	title=$1 option=$2
+	cat >expect
+	test_expect_success "$title" '
+		# error message cannot be checked under i18n
+		test_must_fail git for-each-ref --format="%($option)" refs/heads/main 2>actual &&
+		test_i18ncmp expect actual &&
+		test_must_fail git for-each-ref --format="%(contents:$option)" refs/heads/main 2>actual &&
+		test_i18ncmp expect actual
+	'
+}
+
+test_failing_trailer_option '%(trailers) rejects unknown trailers arguments' \
+	'trailers:unsupported' <<-\EOF
 	fatal: unknown %(trailers) argument: unsupported
 	EOF
-	test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
-	test_i18ncmp expect actual &&
-	test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
-	test_i18ncmp expect actual
-'
 
 test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
 	cat >expect <<-EOF &&
-- 
gitgitgadget
Previous: Hariom Verma via GitGitGadgetNext: Hariom Verma via GitGitGadget
Message 37 of 43 in “Unify trailers formatting logic for pretty.c and ref-filter.c”
  1. 0/2 Unify trailers formatting logic for pretty.c and ref-filter.cHariom Verma via GitGitGadget, Sep 5, 2020
  2. 1/2 pretty.c: refactor trailer logic to `format_set_trailers_options()`Hariom Verma via GitGitGadget, Sep 5, 2020
  3. René ScharfeSep 5, 2020
  4. 2/2 ref-filter: using pretty.c logic for trailersHariom Verma via GitGitGadget, Sep 5, 2020
  5. 0/3 Unify trailers formatting logic for pretty.c and ref-filter.cHariom Verma via GitGitGadget, Jan 29, 2021
  6. 1/3 pretty.c: refactor trailer logic to `format_set_trailers_options()`Hariom Verma via GitGitGadget, Jan 29, 2021
  7. Junio C HamanoJan 29, 2021
  8. 2/3 pretty.c: capture invalid trailer argumentHariom Verma via GitGitGadget, Jan 29, 2021
  9. Christian CouderJan 29, 2021
  10. Hariom vermaJan 30, 2021
  11. Junio C HamanoJan 30, 2021
  12. Hariom vermaJan 30, 2021
  13. Junio C HamanoJan 30, 2021
  14. Hariom vermaJan 30, 2021
  15. 3/3 ref-filter: use pretty.c logic for trailersHariom Verma via GitGitGadget, Jan 29, 2021
  16. Ævar Arnfjörð BjarmasonJan 30, 2021
  17. Hariom vermaFeb 4, 2021
  18. Ævar Arnfjörð BjarmasonFeb 4, 2021
  19. Junio C HamanoJan 30, 2021
  20. Junio C HamanoJan 30, 2021
  21. Hariom vermaJan 30, 2021
  22. Junio C HamanoJan 30, 2021
  23. 0/3 Unify trailers formatting logic for pretty.c and ref-filter.cHariom Verma via GitGitGadget, Feb 6, 2021
  24. 1/3 pretty.c: refactor trailer logic to `format_set_trailers_options()`Hariom Verma via GitGitGadget, Feb 6, 2021
  25. 2/3 pretty.c: capture invalid trailer argumentHariom Verma via GitGitGadget, Feb 6, 2021
  26. 3/3 ref-filter: use pretty.c logic for trailersHariom Verma via GitGitGadget, Feb 6, 2021
  27. Junio C HamanoFeb 7, 2021
  28. Hariom vermaFeb 7, 2021
  29. Junio C HamanoFeb 7, 2021
  30. Hariom vermaFeb 7, 2021
  31. Junio C HamanoFeb 7, 2021
  32. Hariom vermaFeb 8, 2021
  33. Junio C HamanoFeb 8, 2021
  34. Junio C HamanoFeb 7, 2021
  35. Junio C HamanoFeb 7, 2021
  36. 0/4 Unify trailers formatting logic for pretty.c and ref-filter.cHariom Verma via GitGitGadget, Feb 13, 2021
  37. 1/4 t6300: use function to test trailer optionsHariom Verma via GitGitGadget, Feb 13, 2021
  38. 2/4 pretty.c: refactor trailer logic to `format_set_trailers_options()`Hariom Verma via GitGitGadget, Feb 13, 2021
  39. 3/4 pretty.c: capture invalid trailer argumentHariom Verma via GitGitGadget, Feb 13, 2021
  40. 4/4 ref-filter: use pretty.c logic for trailersHariom Verma via GitGitGadget, Feb 13, 2021
  41. brian m. carlsonFeb 8, 2021
  42. brian m. carlsonFeb 9, 2021
  43. Junio C HamanoFeb 9, 2021

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.