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

Re: [PATCH 1/2] test-lib.sh: de-duplicate error() teardown code

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 14, 2021, 16:26 UTC
Message-ID
<xmqqzgrbd12r.fsf@gitster.g>
In-Reply-To
<patch-1.2-d4c67829076-20211014T004542Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 8 quoted lines
> De-duplicate the "finalize_junit_xml; GIT_EXIT_OK=t; exit 1" code
> shared between the "error()" and "--immediate on failure" code paths,
> in preparation for adding a third user in a subsequent commit.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/test-lib.sh | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)

Nice. I do recall seeing the duplication when these finalize-junit calls were introduced and thought about marking it as a leftover clean-up candidate. Nice to see it done here.

Thanks.
Show 34 quoted lines
>
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 8361b5c1c57..c610f09ddb1 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -589,13 +589,17 @@ USER_TERM="$TERM"
>  TERM=dumb
>  export TERM USER_TERM
>  
> -error () {
> -	say_color error "error: $*"
> +_error_exit () {
>  	finalize_junit_xml
>  	GIT_EXIT_OK=t
>  	exit 1
>  }
>  
> +error () {
> +	say_color error "error: $*"
> +	_error_exit
> +}
> +
>  BUG () {
>  	error >&7 "bug in the test script: $*"
>  }
> @@ -720,7 +724,7 @@ test_failure_ () {
>  	say_color error "not ok $test_count - $1"
>  	shift
>  	printf '%s\n' "$*" | sed -e 's/^/#	/'
> -	test "$immediate" = "" || { finalize_junit_xml; GIT_EXIT_OK=t; exit 1; }
> +	test "$immediate" = "" || _error_exit
>  }
>  
>  test_known_broken_ok_ () {
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 3 of 6 in “test-lib.sh: add BAIL_OUT function, use it for SANITIZE=leak”
  1. 0/2 test-lib.sh: add BAIL_OUT function, use it for SANITIZE=leakÆvar Arnfjörð Bjarmason, Oct 14, 2021
  2. 1/2 test-lib.sh: de-duplicate error() teardown codeÆvar Arnfjörð Bjarmason, Oct 14, 2021
  3. Junio C HamanoOct 14, 2021
  4. 2/2 test-lib.sh: use "Bail out!" syntax on bad SANITIZE=leak useÆvar Arnfjörð Bjarmason, Oct 14, 2021
  5. Junio C HamanoOct 14, 2021
  6. Ævar Arnfjörð BjarmasonOct 14, 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.