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

Re: [PATCH 02/10] describe tests: refactor away from glob matching

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 1, 2021, 21:26 UTC
Message-ID
<xmqq1rcypnua.fsf@gitster.c.googlers.com>
In-Reply-To
<20210228195414.21372-3-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 8 quoted lines
> Change the glob matching via a "case" statement to a "test_cmp" after
> we've stripped out the hash-specific g<hash-abbrev>
> suffix. 5312ab11fbf (Add describe test., 2007-01-13).
>
> This means that we can use test_cmp to compare the output. I could
> omit the "-8" change of e.g. "A-*" to "A-8-gHASH", but I think it
> makes sense to test that here explicitly. It means you need to add new
> tests to the bottom of the file, but that's not a burden in this case.

I think the point in these tests are that they consider "which tip the tested commit is the closest" is the only piece of information that matter, and allows the numbers ("number of commits on top of") to be redefined in the future without having to change the tests, but I tend to agree that such a change should be accompanied by and documented with changes to these tests.

Show 12 quoted lines
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/t6120-describe.sh | 78 ++++++++++++++++++++++-----------------------
>  1 file changed, 38 insertions(+), 40 deletions(-)
>
> diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
> index 7bc2aaa46e..e4fd5d567f 100755
> --- a/t/t6120-describe.sh
> +++ b/t/t6120-describe.sh
> @@ -21,12 +21,10 @@ check_describe () {
>  	shift
>  	describe_opts="$@"

Just a style thing, when we are not invoking the "each positional arg is double-quoted individually against being split at $IFS" magic, we prefer to spell this as "$*".

>  	test_expect_success "describe $describe_opts" '
> +		git describe $describe_opts 2>err.actual >raw &&
> +		sed -e "s/-g[0-9a-f]*\$/-gHASH/" <raw >actual &&

The exact ones would be passed as-is (i.e. "test_cmp raw actual" could pass), which is what we want anyway.

If we are planning to further extend this helper to make it more capable, we might want to consider quoting $describe to be evaled properly so that we can do an equivalent of

	check_describe A-8-gHASH --dirty='.d i r t y' HEAD

when we gain new option that is more intresting than --dirty=<mark> that legitimately would benefit from being able to pass arguments with $IFS whitespace in them.

But that is outside the scope of this step. I haven't seen the overall topic yet, so it may or may not be within the scope of this series. We'll see.

> +		echo $expect >expect &&

Let's double-quote to relieve readers from having to wonder if you are expecting the callers to feed crazy things like "a b" and this echo to normalize it to "a b".

> +		test_cmp expect actual
>  	'
>  }
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 19 of 34 in “describe: dont abort too early when searching tags”
  1. describe: dont abort too early when searching tagsBenno Evers, Feb 23, 2020
  2. Junio C HamanoFeb 24, 2020
  3. benno@bmevers.deFeb 25, 2020
  4. Junio C HamanoFeb 25, 2020
  5. 00/10 describe tests: refactor & fix recent broken testsÆvar Arnfjörð Bjarmason, Feb 28, 2021
  6. Junio C HamanoMar 9, 2021
  7. Junio C HamanoMar 12, 2021
  8. 0/5 describe test fixesÆvar Arnfjörð Bjarmason, Apr 12, 2021
  9. 1/5 describe tests: improve test for --work-tree & --dirtyÆvar Arnfjörð Bjarmason, Apr 12, 2021
  10. 3/5 describe tests: don't rely on err.actual from "check_describe"Ævar Arnfjörð Bjarmason, Apr 12, 2021
  11. 2/5 describe tests: refactor away from glob matchingÆvar Arnfjörð Bjarmason, Apr 12, 2021
  12. 4/5 describe tests: fix nested "test_expect_success" callÆvar Arnfjörð Bjarmason, Apr 12, 2021
  13. 5/5 describe tests: support -C in "check_describe"Ævar Arnfjörð Bjarmason, Apr 12, 2021
  14. 0/2 svn tests: trivial "set -e" in main body of test fixesÆvar Arnfjörð Bjarmason, Apr 12, 2021
  15. 1/2 svn tests: remove legacy re-setup from init-clone testÆvar Arnfjörð Bjarmason, Apr 12, 2021
  16. 2/2 svn tests: refactor away a "set -e" in test bodyÆvar Arnfjörð Bjarmason, Apr 12, 2021
  17. 01/10 describe tests: improve test for --work-tree & --dirtyÆvar Arnfjörð Bjarmason, Feb 28, 2021
  18. 02/10 describe tests: refactor away from glob matchingÆvar Arnfjörð Bjarmason, Feb 28, 2021
  19. Junio C HamanoMar 1, 2021
  20. 04/10 test-lib functions: add an --annotated-tag option to "test_commit"Ævar Arnfjörð Bjarmason, Feb 28, 2021
  21. Junio C HamanoMar 1, 2021
  22. Ævar Arnfjörð BjarmasonMar 2, 2021
  23. Junio C HamanoMar 3, 2021
  24. 03/10 describe tests: always assert empty stderr from "describe"Ævar Arnfjörð Bjarmason, Feb 28, 2021
  25. Junio C HamanoMar 1, 2021
  26. 05/10 describe tests: convert setup to use test_commitÆvar Arnfjörð Bjarmason, Feb 28, 2021
  27. Junio C HamanoMar 1, 2021
  28. 06/10 describe tests: fix nested "test_expect_success" callÆvar Arnfjörð Bjarmason, Feb 28, 2021
  29. 08/10 svn tests: remove legacy re-setup from init-clone testÆvar Arnfjörð Bjarmason, Feb 28, 2021
  30. 07/10 describe tests: support -C in "check_describe"Ævar Arnfjörð Bjarmason, Feb 28, 2021
  31. 09/10 svn tests: refactor away a "set -e" in test bodyÆvar Arnfjörð Bjarmason, Feb 28, 2021
  32. Eric WongFeb 28, 2021
  33. 10/10 test-lib: return 1 from test_expect_{success,failure}Ævar Arnfjörð Bjarmason, Feb 28, 2021
  34. Junio C HamanoMar 1, 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.