Skip to content

Commit 3727318

Browse files
committed
Merge branch 'jk/test-send-sh-x-trace-elsewhere'
Running tests with '-x' option to trace the individual command executions is a useful way to debug test scripts, but some tests that capture the standard error stream and check what the command said can be broken with the trace output mixed in. When running our tests under "bash", however, we can redirect the trace output to another file descriptor to keep the standard error of programs being tested intact. * jk/test-send-sh-x-trace-elsewhere: test-lib: set BASH_XTRACEFD automatically
2 parents 848b99b + d88785e commit 3727318

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

t/README

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ appropriately before running "make".
8484

8585
-x::
8686
Turn on shell tracing (i.e., `set -x`) during the tests
87-
themselves. Implies `--verbose`. Note that this can cause
88-
failures in some tests which redirect and test the
89-
output of shell functions. Use with caution.
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.
9090

9191
-d::
9292
--debug::

t/test-lib.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,19 @@ else
322322
exec 4>/dev/null 3>/dev/null
323323
fi
324324

325+
# Send any "-x" output directly to stderr to avoid polluting tests
326+
# which capture stderr. We can do this unconditionally since it
327+
# has no effect if tracing isn't turned on.
328+
#
329+
# Note that this sets up the trace fd as soon as we assign the variable, so it
330+
# must come after the creation of descriptor 4 above. Likewise, we must never
331+
# unset this, as it has the side effect of closing descriptor 4, which we
332+
# use to show verbose tests to the user.
333+
#
334+
# Note also that we don't need or want to export it. The tracing is local to
335+
# this shell, and we would not want to influence any shells we exec.
336+
BASH_XTRACEFD=4
337+
325338
test_failure=0
326339
test_count=0
327340
test_fixed=0

0 commit comments

Comments
 (0)