t: add means to disable '-x' tracing for individual test scripts

The previous patch resolved most of the test failures caused by running our test suite with '-x' tracing and /bin/sh, and the following patches in this series will resolve almost all of the remaining failures. Unfortunately, not yet all. Add means to disable '-x' tracing for individual test scripts by setting the $test_untraceable variable to a non-empty value in the test script before sourcing 'test-lib.sh'. However, since '-x' tracing is not an issue with recent Bash versions supporting BASH_XTRACEFD, i.e. v4.1 and later, don't disable tracing when the test script is run with such a Bash version even when $test_untraceable is set. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Feb 24, 2018 at 00:39 UTC 5fc98e79fc0c40a5d25cb988d3948c0c0ec9f8b8
2 files changed +21 -1
t/README
+3
@@ -87,6 +87,9 @@ appropriately before running "make".
87 themselves. Implies `--verbose`. Note that in non-bash shells,
88 this can cause failures in some tests which redirect and test
89 the output of shell functions. Use with caution.
90 + Ignored in test scripts that set the variable 'test_untraceable'
91 + to a non-empty value, unless it's run with a Bash version
92 + supporting BASH_XTRACEFD, i.e. v4.1 or later.
93
94 -d::
95 --debug::
t/test-lib.sh
+18 -1
@@ -263,7 +263,24 @@ do
263 GIT_TEST_CHAIN_LINT=0
264 shift ;;
265 -x)
266 - trace=t
266 + # Some test scripts can't be reliably traced with '-x',
267 + # unless the test is run with a Bash version supporting
268 + # BASH_XTRACEFD (introduced in Bash v4.1). Check whether
269 + # this test is marked as such, and ignore '-x' if it
270 + # isn't executed with a suitable Bash version.
271 + if test -z "$test_untraceable" || {
272 + test -n "$BASH_VERSION" && {
273 + test ${BASH_VERSINFO[0]} -gt 4 || {
274 + test ${BASH_VERSINFO[0]} -eq 4 &&
275 + test ${BASH_VERSINFO[1]} -ge 1
276 + }
277 + }
278 + }
279 + then
280 + trace=t
281 + else
282 + echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD"
283 + fi
284 shift ;;
285 --verbose-log)
286 verbose_log=t