Skip to content

Commit 07b747d

Browse files
committed
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
2 parents 1eaabe3 + 3f824e9 commit 07b747d

File tree

4 files changed

+48
-18
lines changed

4 files changed

+48
-18
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ all::
426426
# to say "export LESS=FRX (and LV=-c) if the environment variable
427427
# LESS (and LV) is not set, respectively".
428428
#
429+
# Define TEST_SHELL_PATH if you want to use a shell besides SHELL_PATH for
430+
# running the test scripts (e.g., bash has better support for "set -x"
431+
# tracing).
432+
#
429433
# When cross-compiling, define HOST_CPU as the canonical name of the CPU on
430434
# which the built Git will run (for instance "x86_64").
431435

@@ -733,6 +737,8 @@ endif
733737
export PERL_PATH
734738
export PYTHON_PATH
735739

740+
TEST_SHELL_PATH = $(SHELL_PATH)
741+
736742
LIB_FILE = libgit.a
737743
XDIFF_LIB = xdiff/lib.a
738744
VCSSVN_LIB = vcs-svn/lib.a
@@ -1738,6 +1744,7 @@ prefix_SQ = $(subst ','\'',$(prefix))
17381744
gitwebdir_SQ = $(subst ','\'',$(gitwebdir))
17391745

17401746
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
1747+
TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
17411748
PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
17421749
PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
17431750
TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
@@ -2370,6 +2377,7 @@ GIT-LDFLAGS: FORCE
23702377
# and the first level quoting from the shell that runs "echo".
23712378
GIT-BUILD-OPTIONS: FORCE
23722379
@echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@+
2380+
@echo TEST_SHELL_PATH=\''$(subst ','\'',$(TEST_SHELL_PATH_SQ))'\' >>$@+
23732381
@echo PERL_PATH=\''$(subst ','\'',$(PERL_PATH_SQ))'\' >>$@+
23742382
@echo DIFF=\''$(subst ','\'',$(subst ','\'',$(DIFF)))'\' >>$@+
23752383
@echo PYTHON_PATH=\''$(subst ','\'',$(PYTHON_PATH_SQ))'\' >>$@+

t/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#GIT_TEST_OPTS = --verbose --debug
1010
SHELL_PATH ?= $(SHELL)
11+
TEST_SHELL_PATH ?= $(SHELL_PATH)
1112
PERL_PATH ?= /usr/bin/perl
1213
TAR ?= $(TAR)
1314
RM ?= rm -f
@@ -23,6 +24,7 @@ endif
2324

2425
# Shell quote;
2526
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
27+
TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
2628
PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
2729
TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
2830

@@ -42,11 +44,11 @@ failed:
4244
test -z "$$failed" || $(MAKE) $$failed
4345

4446
prove: pre-clean $(TEST_LINT)
45-
@echo "*** prove ***"; $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
47+
@echo "*** prove ***"; $(PROVE) --exec '$(TEST_SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
4648
$(MAKE) clean-except-prove-cache
4749

4850
$(T):
49-
@echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
51+
@echo "*** $@ ***"; '$(TEST_SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
5052

5153
pre-clean:
5254
$(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'

t/t5615-alternate-env.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ check_obj () {
77
alt=$1; shift
88
while read obj expect
99
do
10-
echo "$obj" >&3 &&
11-
echo "$obj $expect" >&4
12-
done 3>input 4>expect &&
10+
echo "$obj" >&5 &&
11+
echo "$obj $expect" >&6
12+
done 5>input 6>expect &&
1313
GIT_ALTERNATE_OBJECT_DIRECTORIES=$alt \
1414
git "$@" cat-file --batch-check='%(objectname) %(objecttype)' \
1515
<input >actual &&

t/test-lib.sh

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ done,*)
8080
# from any previous runs.
8181
>"$GIT_TEST_TEE_OUTPUT_FILE"
8282

83-
(GIT_TEST_TEE_STARTED=done ${SHELL_PATH} "$0" "$@" 2>&1;
83+
(GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1;
8484
echo $? >"$BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
8585
test "$(cat "$BASE.exit")" = 0
8686
exit
@@ -264,7 +264,6 @@ do
264264
shift ;;
265265
-x)
266266
trace=t
267-
verbose=t
268267
shift ;;
269268
--verbose-log)
270269
verbose_log=t
@@ -283,6 +282,11 @@ then
283282
test -z "$verbose_log" && verbose=t
284283
fi
285284

285+
if test -n "$trace" && test -z "$verbose_log"
286+
then
287+
verbose=t
288+
fi
289+
286290
if test -n "$color"
287291
then
288292
# Save the color control sequences now rather than run tput
@@ -586,7 +590,9 @@ maybe_setup_valgrind () {
586590
}
587591

588592
want_trace () {
589-
test "$trace" = t && test "$verbose" = t
593+
test "$trace" = t && {
594+
test "$verbose" = t || test "$verbose_log" = t
595+
}
590596
}
591597

592598
# This is a separate function because some tests use
@@ -601,26 +607,40 @@ test_eval_inner_ () {
601607
}
602608

603609
test_eval_ () {
604-
# We run this block with stderr redirected to avoid extra cruft
605-
# during a "-x" trace. Once in "set -x" mode, we cannot prevent
610+
# If "-x" tracing is in effect, then we want to avoid polluting stderr
611+
# with non-test commands. But once in "set -x" mode, we cannot prevent
606612
# the shell from printing the "set +x" to turn it off (nor the saving
607613
# of $? before that). But we can make sure that the output goes to
608614
# /dev/null.
609615
#
610-
# The test itself is run with stderr put back to &4 (so either to
611-
# /dev/null, or to the original stderr if --verbose was used).
616+
# There are a few subtleties here:
617+
#
618+
# - we have to redirect descriptor 4 in addition to 2, to cover
619+
# BASH_XTRACEFD
620+
#
621+
# - the actual eval has to come before the redirection block (since
622+
# it needs to see descriptor 4 to set up its stderr)
623+
#
624+
# - likewise, any error message we print must be outside the block to
625+
# access descriptor 4
626+
#
627+
# - checking $? has to come immediately after the eval, but it must
628+
# be _inside_ the block to avoid polluting the "set -x" output
629+
#
630+
631+
test_eval_inner_ "$@" </dev/null >&3 2>&4
612632
{
613-
test_eval_inner_ "$@" </dev/null >&3 2>&4
614633
test_eval_ret_=$?
615634
if want_trace
616635
then
617636
set +x
618-
if test "$test_eval_ret_" != 0
619-
then
620-
say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
621-
fi
622637
fi
623-
} 2>/dev/null
638+
} 2>/dev/null 4>&2
639+
640+
if test "$test_eval_ret_" != 0 && want_trace
641+
then
642+
say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
643+
fi
624644
return $test_eval_ret_
625645
}
626646

0 commit comments

Comments
 (0)