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

Re: [PATCH 2/5] config tests: test for --bool-or-str

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 8, 2021, 18:21 UTC
Message-ID
<xmqqim4wtz5k.fsf@gitster.g>
In-Reply-To
<patch-2.6-2f6c2de050-20210408T133125Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 42 quoted lines
> Add the missing tests for the --bool-or-str code added in
> dbd8c09bfe (mergetool: allow auto-merge for meld to follow the
> vim-diff behavior, 2020-05-07).
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/t1300-config.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 72 insertions(+)
>
> diff --git a/t/t1300-config.sh b/t/t1300-config.sh
> index e0dd5d65ce..a002ec5644 100755
> --- a/t/t1300-config.sh
> +++ b/t/t1300-config.sh
> @@ -802,6 +802,78 @@ test_expect_success 'get --bool-or-int' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'get --bool-or-str' '
> +	cat >.git/config <<-\EOF &&
> +	[bool]
> +	true1
> +	true2 = true
> +	true3 = TRUE
> +	true4 = yes
> +	true5 = YES
> +	true6 = on
> +	true7 = ON
> +	false1 =
> +	false2 = false
> +	false3 = FALSE
> +	false4 = no
> +	false5 = NO
> +	false6 = off
> +	false7 = OFF
> +	[int]
> +	int1 = 0
> +	int2 = 1
> +	int3 = -1
> +	[string]
> +	string1 = hello
> +	string2 = there you
> +	EOF

That's fairly complete set (but misses common permutations like "Yes"). I am not sure, if we try "true" and "TRUE", if it is worth to check yes/YES and others, but at the same time, I do not know if reducing the permutations tested would improve the readability, runtime and/or maintainability of the test.

Show 22 quoted lines
> +	cat >expect <<-\EOF &&
> +	true
> +	true
> +	true
> +	true
> +	true
> +	true
> +	true
> +	false
> +	false
> +	false
> +	false
> +	false
> +	false
> +	false
> +	false
> +	false
> +	true
> +	true
> +	hello
> +	there you
> +	EOF

The "right answer" is hard to read and maintain. Can we immediately spot what happened to int.int3 in this output, for example?

Perhaps with something like
	inspect_config () {
		name=$1
		shift
		printf "%s %s\n" $(git config "$@" "$name") "$name"
	}
we can make these lines to say
	int.int1 false
	int.int2 true
	int.int3 true
	string.string1 hello
	string.string2 there you

to make them easier to follow? Without such a hint, I would expect that a failure output from test_cmp at the end would be very hard to grok, especially with so many permutations tested that produces runs of "true" and "false".

> +	{
> +		git config --type=bool-or-str bool.true1 &&
> +		git config --bool-or-str bool.true2 &&

This is a bit curious. We do not do full permutation between --type=bool-or-str and --bool-or-str here. We just check both would work only once. Feels a bit inconsistent.

My gut-feeling vote is to just try true/TRUE for case insensitivity and try all the other variants in lowercase, but I can go with the full permutation if you strongly prefer it.

Show 9 quoted lines
> ...
> +		git config --bool-or-str int.int1 &&
> +		git config --bool-or-str int.int2 &&
> +		git config --bool-or-str int.int3 &&
> +		git config --bool-or-str string.string1 &&
> +		git config --bool-or-str string.string2
> +	} >actual &&
> +	test_cmp expect actual
> +'
Thanks.
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 5 of 21 in “config: support --type=bool-or-auto for "tristate" parsing”
  1. 0/5 config: support --type=bool-or-auto for "tristate" parsingÆvar Arnfjörð Bjarmason, Apr 8, 2021
  2. 1/5 config.c: add a comment about why value=NULL is trueÆvar Arnfjörð Bjarmason, Apr 8, 2021
  3. Junio C HamanoApr 8, 2021
  4. 2/5 config tests: test for --bool-or-strÆvar Arnfjörð Bjarmason, Apr 8, 2021
  5. Junio C HamanoApr 8, 2021
  6. Ævar Arnfjörð BjarmasonApr 8, 2021
  7. 3/5 git-config: document --bool-or-str and --type=bool-or-strÆvar Arnfjörð Bjarmason, Apr 8, 2021
  8. Junio C HamanoApr 8, 2021
  9. 4/5 config.c: add a "tristate" helperÆvar Arnfjörð Bjarmason, Apr 8, 2021
  10. Junio C HamanoApr 8, 2021
  11. Ævar Arnfjörð BjarmasonApr 8, 2021
  12. Junio C HamanoApr 8, 2021
  13. Ævar Arnfjörð BjarmasonApr 9, 2021
  14. Junio C HamanoApr 9, 2021
  15. Junio C HamanoApr 8, 2021
  16. Jeff KingApr 9, 2021
  17. Junio C HamanoApr 9, 2021
  18. Jeff KingApr 10, 2021
  19. Junio C HamanoApr 10, 2021
  20. 5/5 config: add --type=bool-or-auto switchÆvar Arnfjörð Bjarmason, Apr 8, 2021
  21. Junio C HamanoApr 8, 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.