Skip to content

Commit 0a97e86

Browse files
szedergitster
authored andcommitted
test-lib: extract Bash version check for '-x' tracing
One of our test scripts, 't1510-repo-setup.sh' [1], still can't be reliably run with '-x' tracing enabled, unless it's executed with a Bash version supporting BASH_XTRACEFD (since v4.1). We have a lengthy condition to check the version of the shell running the test script, and disable tracing if it's not executed with a suitable Bash version [2]. Move this check out from the option parsing loop, so other options can imply '-x' by setting 'trace=t', without missing this Bash version check. [1] 5827506 (t1510-repo-setup: mark as untraceable with '-x', 2018-02-24) [2] 5fc98e7 (t: add means to disable '-x' tracing for individual test scripts, 2018-02-24) Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d45cec4 commit 0a97e86

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

t/test-lib.sh

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -317,24 +317,7 @@ do
317317
GIT_TEST_CHAIN_LINT=0
318318
shift ;;
319319
-x)
320-
# Some test scripts can't be reliably traced with '-x',
321-
# unless the test is run with a Bash version supporting
322-
# BASH_XTRACEFD (introduced in Bash v4.1). Check whether
323-
# this test is marked as such, and ignore '-x' if it
324-
# isn't executed with a suitable Bash version.
325-
if test -z "$test_untraceable" || {
326-
test -n "$BASH_VERSION" && eval '
327-
test ${BASH_VERSINFO[0]} -gt 4 || {
328-
test ${BASH_VERSINFO[0]} -eq 4 &&
329-
test ${BASH_VERSINFO[1]} -ge 1
330-
}
331-
'
332-
}
333-
then
334-
trace=t
335-
else
336-
echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD"
337-
fi
320+
trace=t
338321
shift ;;
339322
-V|--verbose-log)
340323
verbose_log=t
@@ -353,6 +336,24 @@ then
353336
test -z "$verbose_log" && verbose=t
354337
fi
355338

339+
if test -n "$trace" && test -n "$test_untraceable"
340+
then
341+
# '-x' tracing requested, but this test script can't be reliably
342+
# traced, unless it is run with a Bash version supporting
343+
# BASH_XTRACEFD (introduced in Bash v4.1).
344+
if test -n "$BASH_VERSION" && eval '
345+
test ${BASH_VERSINFO[0]} -gt 4 || {
346+
test ${BASH_VERSINFO[0]} -eq 4 &&
347+
test ${BASH_VERSINFO[1]} -ge 1
348+
}
349+
'
350+
then
351+
: Executed by a Bash version supporting BASH_XTRACEFD. Good.
352+
else
353+
echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD"
354+
trace=
355+
fi
356+
fi
356357
if test -n "$trace" && test -z "$verbose_log"
357358
then
358359
verbose=t

0 commit comments

Comments
 (0)