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

Re: [PATCH] t/test_lib: avoid naked bash arrays in file_lineno

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
May 8, 2020, 23:53 UTC
Message-ID
<nycvar.QRO.7.76.6.2005090151350.56@tvgsbejvaqbjf.bet>
In-Reply-To
<20200507175706.19986-1-carenas@gmail.com>
Hi Carlo,

this is v2, right? The subject says `[PATCH]`, not `[PATCH v2]`, so I am just trying to make sure.

It's things like this why I never use `git send-email` manually anymore. Yes, sure, GitGitGadget helps others, too, but its initial primary goal was to help me not botch my patch submissions.

On Thu, 7 May 2020, Carlo Marcelo Arenas Belón wrote:
Show 16 quoted lines
> 662f9cf154 (tests: when run in Bash, annotate test failures with file
> name/line number, 2020-04-11), introduces a way to report the location
> (file:lineno) of a failed test case by traversing the bash callstack.
>
> The implementation requires bash and uses shell arrays and is therefore
> protected by a guard but NetBSD sh will still have to parse the function
> and therefore will result in:
>
>   ** t0000-basic.sh ***
>   ./test-lib.sh: 681: Syntax error: Bad substitution
>
> Enclose the bash specific code inside an eval to avoid parsing errors in
> the same way than 5826b7b595 (test-lib: check Bash version for '-x'
> without using shell arrays, 2019-01-03)
>
> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
I still provided help, I hope?
Show 30 quoted lines
> ---
>  t/test-lib.sh | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 1b221951a8..baf94546da 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -677,14 +677,16 @@ die () {
>
>  file_lineno () {
>  	test -z "$GIT_TEST_FRAMEWORK_SELFTEST" && test -n "$BASH" || return 0
> -	local i
> -	for i in ${!BASH_SOURCE[*]}
> -	do
> -		case $i,"${BASH_SOURCE[$i]##*/}" in
> -		0,t[0-9]*.sh) echo "t/${BASH_SOURCE[$i]}:$LINENO: ${1+$1: }"; return;;
> -		*,t[0-9]*.sh) echo "t/${BASH_SOURCE[$i]}:${BASH_LINENO[$(($i-1))]}: ${1+$1: }"; return;;
> -		esac
> -	done
> +	eval '
> +		local i
> +		for i in ${!BASH_SOURCE[*]}
> +		do
> +			case $i,"${BASH_SOURCE[$i]##*/}" in
> +			0,t[0-9]*.sh) echo "t/${BASH_SOURCE[$i]}:$LINENO: ${1+$1: }"; return;;
> +			*,t[0-9]*.sh) echo "t/${BASH_SOURCE[$i]}:${BASH_LINENO[$(($i-1))]}: ${1+$1: }"; return;;
> +			esac
> +		done
> +	'
This one looks correct to me.

Ciao, Dscho

Show 7 quoted lines
>  }
>
>  GIT_EXIT_OK=
> --
> 2.26.2.717.g5cccb0e1a8
>
>
Previous: Carlo Marcelo Arenas BelónNext: Johannes Schindelin
Message 5 of 8 in “t/test_lib: avoid naked bash arrays in file_lineno”
  1. t/test_lib: avoid naked bash arrays in file_linenoCarlo Marcelo Arenas Belón, May 7, 2020
  2. Junio C HamanoMay 7, 2020
  3. Carlo ArenasMay 7, 2020
  4. t/test_lib: avoid naked bash arrays in file_linenoCarlo Marcelo Arenas Belón, May 7, 2020
  5. Johannes SchindelinMay 8, 2020
  6. Johannes SchindelinMay 7, 2020
  7. Carlo Marcelo Arenas BelónMay 8, 2020
  8. Junio C HamanoMay 8, 2020

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.