]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t/test_lib: avoid naked bash arrays in file_lineno
authorCarlo Marcelo Arenas Belón <carenas@gmail.com>
Thu, 7 May 2020 17:57:06 +0000 (10:57 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 May 2020 20:04:26 +0000 (13:04 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/test-lib.sh

index 1b221951a8e78da99dbec41047a6d9274d686f76..baf94546da10b369ba1f96d5d40b8ae43dfafe57 100644 (file)
@@ -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
+       '
 }
 
 GIT_EXIT_OK=