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

Re: [PATCH v3 03/13] trailer: add tests to check defaulting behavior with --no-* flags

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 8, 2023, 21:52 UTC
Message-ID
<xmqqfs3os574.fsf@gitster.g>
In-Reply-To
<4b5c458ef436c2d208e6d6d0a1f99c65e9a11125.1694125210.git.gitgitgadget@gmail.com>
"Linus Arver via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 12 quoted lines
> From: Linus Arver <linusa@google.com>
>
> While the "--no-where" flag is tested, the "--no-if-exists" and
> "--no-if-missing" flags are not, so add tests for them. But also add
> tests for all "--no-*" flags to check their effects, both when (1) there
> are relevant configuration variables set, and (2) they are not set.
>
> Signed-off-by: Linus Arver <linusa@google.com>
> ---
>  Documentation/git-interpret-trailers.txt |  14 ++-
>  t/t7513-interpret-trailers.sh            | 130 +++++++++++++++++++++++
>  2 files changed, 140 insertions(+), 4 deletions(-)

The commentary before each test_expect_success makes it quite a pleasant read.

Show 155 quoted lines
> diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh
> index ed0fc04bd95..832aff06167 100755
> --- a/t/t7513-interpret-trailers.sh
> +++ b/t/t7513-interpret-trailers.sh
> @@ -812,6 +812,53 @@ test_expect_success 'using "--where after" with "--no-where"' '
>  	test_cmp expected actual
>  '
>  
> +# Check whether using "--no-where" clears out only the "--where after", such
> +# that we still use the configuration in trailer.where (which is different from
> +# the hardcoded default (in WHERE_END) assuming the absence of .gitconfig).
> +# Here, the "start" setting of trailer.where is respected, so the new "Acked-by"
> +# and "Bug" trailers are placed at the beginning, and not at the end which is
> +# the harcoded default.
> +test_expect_success 'using "--where after" with "--no-where" defaults to configuration' '
> +	test_config trailer.ack.key "Acked-by= " &&
> +	test_config trailer.bug.key "Bug #" &&
> +	test_config trailer.separators ":=#" &&
> +	test_config trailer.where "start" &&
> +	cat complex_message_body >expected &&
> +	sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
> +		Bug #42
> +		Acked-by= Peff
> +		Fixes: Z
> +		Acked-by= Z
> +		Reviewed-by: Z
> +		Signed-off-by: Z
> +	EOF
> +	git interpret-trailers --where after --no-where --trailer "ack: Peff" \
> +		--trailer "bug: 42" complex_message >actual &&
> +	test_cmp expected actual
> +'
> +
> +# The "--where after" will only get respected for the trailer that came
> +# immediately after it. For the next trailer (Bug #42), we default to using the
> +# hardcoded WHERE_END because we don't have any "trailer.where" or
> +# "trailer.bug.where" configured.
> +test_expect_success 'using "--no-where" defaults to harcoded default if nothing configured' '
> +	test_config trailer.ack.key "Acked-by= " &&
> +	test_config trailer.bug.key "Bug #" &&
> +	test_config trailer.separators ":=#" &&
> +	cat complex_message_body >expected &&
> +	sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
> +		Fixes: Z
> +		Acked-by= Z
> +		Acked-by= Peff
> +		Reviewed-by: Z
> +		Signed-off-by: Z
> +		Bug #42
> +	EOF
> +	git interpret-trailers --where after --trailer "ack: Peff" --no-where \
> +		--trailer "bug: 42" complex_message >actual &&
> +	test_cmp expected actual
> +'
> +
>  test_expect_success 'using "where = after"' '
>  	test_config trailer.ack.key "Acked-by= " &&
>  	test_config trailer.ack.where "after" &&
> @@ -1176,6 +1223,56 @@ test_expect_success 'overriding configuration with "--if-exists replace"' '
>  	test_cmp expected actual
>  '
>  
> +# "trailer.ifexists" is set to "doNothing", so using "--no-if-exists" defaults
> +# to this "doNothing" behavior. So the "Fixes: 53" trailer does not get added.
> +test_expect_success 'using "--if-exists replace" with "--no-if-exists" defaults to configuration' '
> +	test_config trailer.ifexists "doNothing" &&
> +	cat complex_message_body >expected &&
> +	sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
> +		Fixes: Z
> +		Acked-by: Z
> +		Reviewed-by: Z
> +		Signed-off-by: Z
> +	EOF
> +	git interpret-trailers --if-exists replace --no-if-exists --trailer "Fixes: 53" \
> +		<complex_message >actual &&
> +	test_cmp expected actual
> +'
> +
> +# No "ifexists" configuration is set, so using "--no-if-exists" makes it default
> +# to addIfDifferentNeighbor. Because we do have a different neighbor "Fixes: 53"
> +# (because it got added by overriding with "--if-exists replace" earlier in the
> +# arguments list), we add "Signed-off-by: addme".
> +test_expect_success 'using "--no-if-exists" defaults to hardcoded default if nothing configured' '
> +	cat complex_message_body >expected &&
> +	sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
> +		Acked-by: Z
> +		Reviewed-by: Z
> +		Signed-off-by: Z
> +		Fixes: 53
> +		Signed-off-by: addme
> +	EOF
> +	git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \
> +		--trailer "Signed-off-by: addme" <complex_message >actual &&
> +	test_cmp expected actual
> +'
> +
> +# The second "Fixes: 53" trailer is discarded, because the "--no-if-exists" here
> +# makes us default to addIfDifferentNeighbor, and we already added the "Fixes:
> +# 53" trailer earlier in the argument list.
> +test_expect_success 'using "--no-if-exists" defaults to hardcoded default if nothing configured (no addition)' '
> +	cat complex_message_body >expected &&
> +	sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
> +		Acked-by: Z
> +		Reviewed-by: Z
> +		Signed-off-by: Z
> +		Fixes: 53
> +	EOF
> +	git interpret-trailers --if-exists replace --trailer "Fixes: 53" --no-if-exists \
> +		--trailer "Fixes: 53" <complex_message >actual &&
> +	test_cmp expected actual
> +'
> +
>  test_expect_success 'using "ifExists = replace"' '
>  	test_config trailer.fix.key "Fixes: " &&
>  	test_config trailer.fix.ifExists "replace" &&
> @@ -1425,6 +1522,39 @@ test_expect_success 'using "ifMissing = doNothing"' '
>  	test_cmp expected actual
>  '
>  
> +# Ignore the "IgnoredTrailer" because of "--if-missing doNothing", but also
> +# ignore the "StillIgnoredTrailer" because we set "trailer.ifMissing" to
> +# "doNothing" in configuration.
> +test_expect_success 'using "--no-if-missing" defaults to configuration' '
> +	test_config trailer.ifMissing "doNothing" &&
> +	cat complex_message_body >expected &&
> +	sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
> +			Fixes: Z
> +			Acked-by: Z
> +			Reviewed-by: Z
> +			Signed-off-by: Z
> +	EOF
> +	git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \
> +			--trailer "StillIgnoredTrailer: ignoreme" <complex_message >actual &&
> +	test_cmp expected actual
> +'
> +
> +# Add the "AddedTrailer" because the "--no-if-missing" clears the "--if-missing
> +# doNothing" from earlier in the argument list.
> +test_expect_success 'using "--no-if-missing" defaults to hardcoded default if nothing configured' '
> +	cat complex_message_body >expected &&
> +	sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
> +			Fixes: Z
> +			Acked-by: Z
> +			Reviewed-by: Z
> +			Signed-off-by: Z
> +			AddedTrailer: addme
> +	EOF
> +	git interpret-trailers --if-missing doNothing --trailer "IgnoredTrailer: ignoreme" --no-if-missing \
> +			--trailer "AddedTrailer: addme" <complex_message >actual &&
> +	test_cmp expected actual
> +'
> +
>  test_expect_success 'default "where" is now "after"' '
>  	git config trailer.where "after" &&
>  	test_config trailer.ack.ifExists "add" &&
Previous: Linus Arver via GitGitGadgetNext: Linus Arver via GitGitGadget
Message 32 of 52 in “Fixes to trailer test script, help text, and documentation”
  1. 0/5 Fixes to trailer test script, help text, and documentationLinus Arver via GitGitGadget, Aug 5, 2023
  2. 2/5 trailer test description: this tests --where=after, not --where=beforeLinus Arver via GitGitGadget, Aug 5, 2023
  3. 5/5 trailer --no-divider help: describe usual "---" meaningLinus Arver via GitGitGadget, Aug 5, 2023
  4. 1/5 trailer tests: make test cases self-containedLinus Arver via GitGitGadget, Aug 5, 2023
  5. Linus ArverAug 7, 2023
  6. 4/5 trailer: trailer location is a place, not an actionLinus Arver via GitGitGadget, Aug 5, 2023
  7. 3/5 trailer: add tests to check defaulting behavior with --no-* flagsLinus Arver via GitGitGadget, Aug 5, 2023
  8. Junio C HamanoAug 7, 2023
  9. Linus ArverAug 7, 2023
  10. Linus ArverAug 7, 2023
  11. Linus ArverAug 7, 2023
  12. Junio C HamanoAug 7, 2023
  13. 00/13 Fixes to trailer test script, help text, and documentationLinus Arver via GitGitGadget, Aug 10, 2023
  14. 02/13 trailer test description: this tests --where=after, not --where=beforeLinus Arver via GitGitGadget, Aug 10, 2023
  15. 01/13 trailer tests: make test cases self-containedLinus Arver via GitGitGadget, Aug 10, 2023
  16. 04/13 trailer doc: narrow down scope of --where and related flagsLinus Arver via GitGitGadget, Aug 10, 2023
  17. 03/13 trailer: add tests to check defaulting behavior with --no-* flagsLinus Arver via GitGitGadget, Aug 10, 2023
  18. 05/13 trailer: trailer location is a place, not an actionLinus Arver via GitGitGadget, Aug 10, 2023
  19. 06/13 trailer --no-divider help: describe usual "---" meaningLinus Arver via GitGitGadget, Aug 10, 2023
  20. 07/13 trailer --parse help: expose aliased optionsLinus Arver via GitGitGadget, Aug 10, 2023
  21. 09/13 trailer --parse docs: add explanation for its usefulnessLinus Arver via GitGitGadget, Aug 10, 2023
  22. 10/13 trailer --unfold help: prefer "reformat" over "join"Linus Arver via GitGitGadget, Aug 10, 2023
  23. 08/13 trailer --only-input: prefer "configuration variables" over "rules"Linus Arver via GitGitGadget, Aug 10, 2023
  24. 11/13 trailer doc: emphasize the effect of configuration variablesLinus Arver via GitGitGadget, Aug 10, 2023
  25. 12/13 trailer doc: separator within key suppresses default separatorLinus Arver via GitGitGadget, Aug 10, 2023
  26. 13/13 trailer doc: <token> is a <key> or <keyAlias>, not bothLinus Arver via GitGitGadget, Aug 10, 2023
  27. Junio C HamanoAug 11, 2023
  28. Linus ArverAug 11, 2023
  29. 00/13 Fixes to trailer test script, help text, and documentationLinus Arver via GitGitGadget, Sep 7, 2023
  30. 02/13 trailer test description: this tests --where=after, not --where=beforeLinus Arver via GitGitGadget, Sep 7, 2023
  31. 03/13 trailer: add tests to check defaulting behavior with --no-* flagsLinus Arver via GitGitGadget, Sep 7, 2023
  32. Junio C HamanoSep 8, 2023
  33. 01/13 trailer tests: make test cases self-containedLinus Arver via GitGitGadget, Sep 7, 2023
  34. 04/13 trailer doc: narrow down scope of --where and related flagsLinus Arver via GitGitGadget, Sep 7, 2023
  35. 06/13 trailer --no-divider help: describe usual "---" meaningLinus Arver via GitGitGadget, Sep 7, 2023
  36. Junio C HamanoSep 8, 2023
  37. 05/13 trailer: trailer location is a place, not an actionLinus Arver via GitGitGadget, Sep 7, 2023
  38. Jonathan TanSep 19, 2023
  39. 08/13 trailer --only-input: prefer "configuration variables" over "rules"Linus Arver via GitGitGadget, Sep 7, 2023
  40. 10/13 trailer --unfold help: prefer "reformat" over "join"Linus Arver via GitGitGadget, Sep 7, 2023
  41. 09/13 trailer --parse docs: add explanation for its usefulnessLinus Arver via GitGitGadget, Sep 7, 2023
  42. Junio C HamanoSep 8, 2023
  43. 07/13 trailer --parse help: expose aliased optionsLinus Arver via GitGitGadget, Sep 7, 2023
  44. Jonathan TanSep 19, 2023
  45. 12/13 trailer doc: separator within key suppresses default separatorLinus Arver via GitGitGadget, Sep 7, 2023
  46. 11/13 trailer doc: emphasize the effect of configuration variablesLinus Arver via GitGitGadget, Sep 7, 2023
  47. 13/13 trailer doc: <token> is a <key> or <keyAlias>, not bothLinus Arver via GitGitGadget, Sep 7, 2023
  48. Jonathan TanSep 19, 2023
  49. Linus ArverSep 20, 2023
  50. Junio C HamanoSep 20, 2023
  51. Linus ArverSep 22, 2023
  52. 13/13 trailer doc: <token> is a <key> or <keyAlias>, not bothTeng Long, Nov 10, 2023

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.