Skip to content

Commit 303775a

Browse files
carenasgitster
authored andcommitted
t/test_lib: avoid naked bash arrays in file_lineno
662f9cf (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 5826b7b (test-lib: check Bash version for '-x' without using shell arrays, 2019-01-03) Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 07d8ea5 commit 303775a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

t/test-lib.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -677,14 +677,16 @@ die () {
677677

678678
file_lineno () {
679679
test -z "$GIT_TEST_FRAMEWORK_SELFTEST" && test -n "$BASH" || return 0
680-
local i
681-
for i in ${!BASH_SOURCE[*]}
682-
do
683-
case $i,"${BASH_SOURCE[$i]##*/}" in
684-
0,t[0-9]*.sh) echo "t/${BASH_SOURCE[$i]}:$LINENO: ${1+$1: }"; return;;
685-
*,t[0-9]*.sh) echo "t/${BASH_SOURCE[$i]}:${BASH_LINENO[$(($i-1))]}: ${1+$1: }"; return;;
686-
esac
687-
done
680+
eval '
681+
local i
682+
for i in ${!BASH_SOURCE[*]}
683+
do
684+
case $i,"${BASH_SOURCE[$i]##*/}" in
685+
0,t[0-9]*.sh) echo "t/${BASH_SOURCE[$i]}:$LINENO: ${1+$1: }"; return;;
686+
*,t[0-9]*.sh) echo "t/${BASH_SOURCE[$i]}:${BASH_LINENO[$(($i-1))]}: ${1+$1: }"; return;;
687+
esac
688+
done
689+
'
688690
}
689691

690692
GIT_EXIT_OK=

0 commit comments

Comments
 (0)