Skip to content

Commit 3f824e9

Browse files
peffgitster
authored andcommitted
t/Makefile: introduce TEST_SHELL_PATH
You may want to run the test suite with a different shell than you use to build Git. For instance, you may build with SHELL_PATH=/bin/sh (because it's faster, or it's what you expect to exist on systems where the build will be used) but want to run the test suite with bash (e.g., since that allows using "-x" reliably across the whole test suite). There's currently no good way to do this. You might think that doing two separate make invocations, like: make && make -C t SHELL_PATH=/bin/bash would work. And it _almost_ does. The second make will see our bash SHELL_PATH, and we'll use that to run the individual test scripts (or tell prove to use it to do so). So far so good. But this breaks down when "--tee" or "--verbose-log" is used. Those options cause the test script to actually re-exec itself using $SHELL_PATH. But wait, wouldn't our second make invocation have set SHELL_PATH correctly in the environment? Yes, but test-lib.sh sources GIT-BUILD-OPTIONS, which we built during the first "make". And that overrides the environment, giving us the original SHELL_PATH again. Let's introduce a new variable that lets you specify a specific shell to be run for the test scripts. Note that we have to touch both the main and t/ Makefiles, since we have to record it in GIT-BUILD-OPTIONS in one, and use it in the latter. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f5ba2de commit 3f824e9

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ all::
425425
#
426426
# to say "export LESS=FRX (and LV=-c) if the environment variable
427427
# LESS (and LV) is not set, respectively".
428+
#
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).
428432

429433
GIT-VERSION-FILE: FORCE
430434
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -727,6 +731,8 @@ endif
727731
export PERL_PATH
728732
export PYTHON_PATH
729733

734+
TEST_SHELL_PATH = $(SHELL_PATH)
735+
730736
LIB_FILE = libgit.a
731737
XDIFF_LIB = xdiff/lib.a
732738
VCSSVN_LIB = vcs-svn/lib.a
@@ -1721,6 +1727,7 @@ prefix_SQ = $(subst ','\'',$(prefix))
17211727
gitwebdir_SQ = $(subst ','\'',$(gitwebdir))
17221728

17231729
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
1730+
TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
17241731
PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
17251732
PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
17261733
TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
@@ -2351,6 +2358,7 @@ GIT-LDFLAGS: FORCE
23512358
# and the first level quoting from the shell that runs "echo".
23522359
GIT-BUILD-OPTIONS: FORCE
23532360
@echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@+
2361+
@echo TEST_SHELL_PATH=\''$(subst ','\'',$(TEST_SHELL_PATH_SQ))'\' >>$@+
23542362
@echo PERL_PATH=\''$(subst ','\'',$(PERL_PATH_SQ))'\' >>$@+
23552363
@echo DIFF=\''$(subst ','\'',$(subst ','\'',$(DIFF)))'\' >>$@+
23562364
@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/test-lib.sh

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)