git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
Subject: [PATCH] t/test_lib: avoid naked bash arrays in file_lineno
Date: Thu,  7 May 2020 10:57:06 -0700	[thread overview]
Message-ID: <20200507175706.19986-1-carenas@gmail.com> (raw)
In-Reply-To: <20200507055118.69971-1-carenas@gmail.com>

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>
---
 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
+	'
 }
 
 GIT_EXIT_OK=
-- 
2.26.2.717.g5cccb0e1a8


  parent reply	other threads:[~2020-05-07 17:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07  5:51 [PATCH] t/test_lib: avoid naked bash arrays in file_lineno Carlo Marcelo Arenas Belón
2020-05-07 14:53 ` Junio C Hamano
2020-05-07 17:33   ` Carlo Arenas
2020-05-07 17:57 ` Carlo Marcelo Arenas Belón [this message]
2020-05-08 23:53   ` Johannes Schindelin
2020-05-07 19:52 ` Johannes Schindelin
2020-05-08  0:58   ` Carlo Marcelo Arenas Belón
2020-05-08  1:17     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200507175706.19986-1-carenas@gmail.com \
    --to=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).