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] 5827506928 (t1510-repo-setup: mark as untraceable with '-x', 2018-02-24) [2] 5fc98e79fc (t: add means to disable '-x' tracing for individual test scripts, 2018-02-24) Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Jan 5, 2019 at 02:08 UTC 0a97e86e9a28746604f38eacb11119aadbadb9c8
1 file changed +19 -18
t/test-lib.sh
+19 -18
@@ -317,24 +317,7 @@ do
317 GIT_TEST_CHAIN_LINT=0
318 shift ;;
319 -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
321 shift ;;
322 -V|--verbose-log)
323 verbose_log=t
@@ -353,6 +336,24 @@ then
336 test -z "$verbose_log" && verbose=t
337 fi
338
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
357 if test -n "$trace" && test -z "$verbose_log"
358 then
359 verbose=t