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 7, 2020, 19:52 UTC
Message-ID
<nycvar.QRO.7.76.6.2005072139300.56@tvgsbejvaqbjf.bet>
In-Reply-To
<20200507055118.69971-1-carenas@gmail.com>
Hi Carlo,
On Wed, 6 May 2020, Carlo Marcelo Arenas Belón wrote:
Show 14 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 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
> and while at it, simplify the logic so that instead of traversing the
> callstack just pop the two topmost entries that are required.
I would be okay with that, but that's not what the patch does:
Show 22 quoted lines
> Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
> ---
>  t/test-lib.sh | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 1b221951a8..60b8e70678 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -677,14 +677,13 @@ 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

Note how this `for` loop stops as soon as it finds a `t/[0-9]*.sh` in the backtrace?

Show 6 quoted lines
> +	eval '
> +		local n=$(echo ${#BASH_SOURCE[*]})
> +		if test $n -ge 2
> +		then
> +			echo "${BASH_SOURCE[$n - 1]}:${BASH_LINENO[$n - 2]}: $1: "
> +		fi
This loop is completely lost here.

Now, you could argue that your version is better because it avoids the loop and always shows the ultimate caller in the backtrace.

However, I would then immediately point you to `t/t0027-auto-crlf.sh` and ask whether it is all that useful to the `commit_chk_wrnNNO` call rather than one of the five `test_expect_success` calls contained in that function.

Besides, you simply replaces `${1+$1: }` by `$1: `.

Again, you could argue that your version is better because there is now only one caller, and it always passes `error` as first parameter.

I would not be _too_ happy about losing the logic that allows calling `file_lineno` in other circumstances (I found it valuable for debugging), but _in the least_ you need to talk about this change in the commit message. Just changing the behavior without even describing, let alone justifying, it in the commit message is a bad idea.

Ciao, Dscho

Show 8 quoted lines
> +	'
>  }
>
>  GIT_EXIT_OK=
> --
> 2.26.2.686.gfaf46a9ccd
>
>
Previous: Johannes SchindelinNext: Carlo Marcelo Arenas Belón
Message 6 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.