summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-01-05 21:28:09 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-01-05 21:28:09 (GMT)
commit07b747d32467a34768f6a95571266d98ad22b1dc (patch)
treeae9329036c98cfdad926cb61ec0ba1068ed200d7 /t
parent1eaabe34fc6f486367a176207420378f587d3b48 (diff)
parent3f824e91c8480f7a236331096d2c4d969f013a83 (diff)
downloadgit-07b747d32467a34768f6a95571266d98ad22b1dc.zip
git-07b747d32467a34768f6a95571266d98ad22b1dc.tar.gz
git-07b747d32467a34768f6a95571266d98ad22b1dc.tar.bz2
Merge branch 'jk/test-suite-tracing'
Assorted fixes around running tests with "-x" tracing option. * jk/test-suite-tracing: t/Makefile: introduce TEST_SHELL_PATH test-lib: make "-x" work with "--verbose-log" t5615: avoid re-using descriptor 4 test-lib: silence "-x" cleanup under bash
Diffstat (limited to 't')
-rw-r--r--t/Makefile6
-rwxr-xr-xt/t5615-alternate-env.sh6
-rw-r--r--t/test-lib.sh46
3 files changed, 40 insertions, 18 deletions
diff --git a/t/Makefile b/t/Makefile
index 1bb06c3..96317a3 100644
--- a/t/Makefile
+++ b/t/Makefile
@@ -8,6 +8,7 @@
#GIT_TEST_OPTS = --verbose --debug
SHELL_PATH ?= $(SHELL)
+TEST_SHELL_PATH ?= $(SHELL_PATH)
PERL_PATH ?= /usr/bin/perl
TAR ?= $(TAR)
RM ?= rm -f
@@ -23,6 +24,7 @@ endif
# Shell quote;
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
+TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
@@ -42,11 +44,11 @@ failed:
test -z "$$failed" || $(MAKE) $$failed
prove: pre-clean $(TEST_LINT)
- @echo "*** prove ***"; $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
+ @echo "*** prove ***"; $(PROVE) --exec '$(TEST_SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
$(MAKE) clean-except-prove-cache
$(T):
- @echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
+ @echo "*** $@ ***"; '$(TEST_SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
pre-clean:
$(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
diff --git a/t/t5615-alternate-env.sh b/t/t5615-alternate-env.sh
index d2d883f..b4905b8 100755
--- a/t/t5615-alternate-env.sh
+++ b/t/t5615-alternate-env.sh
@@ -7,9 +7,9 @@ check_obj () {
alt=$1; shift
while read obj expect
do
- echo "$obj" >&3 &&
- echo "$obj $expect" >&4
- done 3>input 4>expect &&
+ echo "$obj" >&5 &&
+ echo "$obj $expect" >&6
+ done 5>input 6>expect &&
GIT_ALTERNATE_OBJECT_DIRECTORIES=$alt \
git "$@" cat-file --batch-check='%(objectname) %(objecttype)' \
<input >actual &&
diff --git a/t/test-lib.sh b/t/test-lib.sh
index e7065df..9a0a21f 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -80,7 +80,7 @@ done,*)
# from any previous runs.
>"$GIT_TEST_TEE_OUTPUT_FILE"
- (GIT_TEST_TEE_STARTED=done ${SHELL_PATH} "$0" "$@" 2>&1;
+ (GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1;
echo $? >"$BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
test "$(cat "$BASE.exit")" = 0
exit
@@ -264,7 +264,6 @@ do
shift ;;
-x)
trace=t
- verbose=t
shift ;;
--verbose-log)
verbose_log=t
@@ -283,6 +282,11 @@ then
test -z "$verbose_log" && verbose=t
fi
+if test -n "$trace" && test -z "$verbose_log"
+then
+ verbose=t
+fi
+
if test -n "$color"
then
# Save the color control sequences now rather than run tput
@@ -586,7 +590,9 @@ maybe_setup_valgrind () {
}
want_trace () {
- test "$trace" = t && test "$verbose" = t
+ test "$trace" = t && {
+ test "$verbose" = t || test "$verbose_log" = t
+ }
}
# This is a separate function because some tests use
@@ -601,26 +607,40 @@ test_eval_inner_ () {
}
test_eval_ () {
- # We run this block with stderr redirected to avoid extra cruft
- # during a "-x" trace. Once in "set -x" mode, we cannot prevent
+ # If "-x" tracing is in effect, then we want to avoid polluting stderr
+ # with non-test commands. But once in "set -x" mode, we cannot prevent
# the shell from printing the "set +x" to turn it off (nor the saving
# of $? before that). But we can make sure that the output goes to
# /dev/null.
#
- # The test itself is run with stderr put back to &4 (so either to
- # /dev/null, or to the original stderr if --verbose was used).
+ # There are a few subtleties here:
+ #
+ # - we have to redirect descriptor 4 in addition to 2, to cover
+ # BASH_XTRACEFD
+ #
+ # - the actual eval has to come before the redirection block (since
+ # it needs to see descriptor 4 to set up its stderr)
+ #
+ # - likewise, any error message we print must be outside the block to
+ # access descriptor 4
+ #
+ # - checking $? has to come immediately after the eval, but it must
+ # be _inside_ the block to avoid polluting the "set -x" output
+ #
+
+ test_eval_inner_ "$@" </dev/null >&3 2>&4
{
- test_eval_inner_ "$@" </dev/null >&3 2>&4
test_eval_ret_=$?
if want_trace
then
set +x
- if test "$test_eval_ret_" != 0
- then
- say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
- fi
fi
- } 2>/dev/null
+ } 2>/dev/null 4>&2
+
+ if test "$test_eval_ret_" != 0 && want_trace
+ then
+ say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
+ fi
return $test_eval_ret_
}