1 # The default target of this Makefile is...
4 # Import tree-wide shared Makefile behavior and libraries
9 # Copyright (c) 2005 Junio C Hamano
12 -include ..
/config.mak.uname
13 -include ..
/config.mak.autogen
14 -include ..
/config.mak
16 #GIT_TEST_OPTS = --verbose --debug
17 SHELL_PATH ?
= $(SHELL
)
18 TEST_SHELL_PATH ?
= $(SHELL_PATH
)
19 PERL_PATH ?
= /usr
/bin
/perl
23 DEFAULT_TEST_TARGET ?
= test
24 DEFAULT_UNIT_TEST_TARGET ?
= unit-tests-raw
25 TEST_LINT ?
= test-lint
27 ifdef TEST_OUTPUT_DIRECTORY
28 TEST_RESULTS_DIRECTORY
= $(TEST_OUTPUT_DIRECTORY
)/test-results
29 CHAINLINTTMP
= $(TEST_OUTPUT_DIRECTORY
)/chainlinttmp
31 TEST_RESULTS_DIRECTORY
= test-results
32 CHAINLINTTMP
= chainlinttmp
36 SHELL_PATH_SQ
= $(subst ','\'',$(SHELL_PATH))
37 TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH
))
38 PERL_PATH_SQ
= $(subst ','\'',$(PERL_PATH))
39 TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY
))
40 CHAINLINTTMP_SQ
= $(subst ','\'',$(CHAINLINTTMP))
42 T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
43 THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh)))
44 TLIBS = $(sort $(wildcard lib-*.sh)) annotate-tests.sh
45 TPERF = $(sort $(wildcard perf/p[0-9][0-9][0-9][0-9]-*.sh))
46 TINTEROP = $(sort $(wildcard interop/i[0-9][0-9][0-9][0-9]-*.sh))
47 CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test)))
48 CHAINLINT = '$(PERL_PATH_SQ
)' chainlint.pl
49 UNIT_TEST_SOURCES = $(wildcard unit-tests/t-*.c)
50 UNIT_TEST_PROGRAMS = $(patsubst unit-tests/%.c,unit-tests/bin/%$(X),$(UNIT_TEST_SOURCES))
51 UNIT_TEST_PROGRAMS += unit-tests/bin/unit-tests$(X)
52 UNIT_TESTS = $(sort $(UNIT_TEST_PROGRAMS))
53 UNIT_TESTS_NO_DIR = $(notdir $(UNIT_TESTS))
55 # `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`)
56 # checks all tests in all scripts via a single invocation, so tell individual
57 # scripts not to run the external "chainlint.pl" script themselves
58 CHAINLINTSUPPRESS = GIT_TEST_EXT_CHAIN_LINT=0 && export GIT_TEST_EXT_CHAIN_LINT &&
60 all:: $(DEFAULT_TEST_TARGET)
62 test: pre-clean check-chainlint $(TEST_LINT)
63 $(CHAINLINTSUPPRESS) $(MAKE) aggregate-results-and-cleanup
66 @failed=$$(cd '$(TEST_RESULTS_DIRECTORY_SQ
)' && \
67 grep -l '^failed
[1-9]' *.counts | \
68 sed -n 's
/\.counts
$$/.sh
/p
') && \
69 test -z "$$failed" || $(MAKE) $$failed
71 prove: pre-clean check-chainlint $(TEST_LINT)
72 @echo "*** prove (shell & unit tests) ***"
73 @$(CHAINLINTSUPPRESS) TEST_OPTIONS='$(GIT_TEST_OPTS
)' TEST_SHELL_PATH='$(TEST_SHELL_PATH_SQ
)' $(PROVE) --exec ./run-test.sh $(GIT_PROVE_OPTS) $(T) $(UNIT_TESTS)
74 $(MAKE) clean-except-prove-cache
77 @echo "*** $@ ***"; '$(TEST_SHELL_PATH_SQ
)' $@ $(GIT_TEST_OPTS)
80 @echo "*** $@ ***"; $@
82 .PHONY: unit-tests unit-tests-raw unit-tests-prove unit-tests-test-tool
83 unit-tests: $(DEFAULT_UNIT_TEST_TARGET)
85 unit-tests-raw: $(UNIT_TESTS)
88 @echo "*** prove - unit tests ***"; $(PROVE) $(GIT_PROVE_OPTS) $(UNIT_TESTS)
91 @echo "*** test-tool - unit tests **"
93 cd unit-tests/bin && \
94 ../../helper/test-tool$X run-command testsuite $(UNIT_TESTS_NO_DIR)\
98 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ
)'
100 clean-except-prove-cache: clean-chainlint
101 $(RM) -r 'trash directory
'.*
102 $(RM) -r valgrind/bin
104 clean: clean-except-prove-cache
105 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ
)'
109 $(RM) -r '$(CHAINLINTTMP_SQ
)'
112 @mkdir -p '$(CHAINLINTTMP_SQ
)' && \
113 '$(PERL_PATH_SQ
)' chainlint-cat.pl '$(CHAINLINTTMP_SQ
)' $(CHAINLINTTESTS) && \
114 { $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ
)'/tests >'$(CHAINLINTTMP_SQ
)'/actual || true; } && \
115 diff -u '$(CHAINLINTTMP_SQ
)'/expect '$(CHAINLINTTMP_SQ
)'/actual
117 test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
119 ifneq ($(GIT_TEST_CHAIN_LINT),0)
120 test-lint: test-chainlint
123 test-lint-duplicates:
124 @dups=`echo $(T) $(TPERF) | tr ' ' '\n' | sed 's
/-.
*//' | sort | uniq -d` && \
125 test -z "$$dups" || { \
126 echo >&2 "duplicate test numbers:" $$dups; exit 1; }
128 test-lint-executable:
129 @bad=`for i in $(T) $(TPERF); do test -x "$$i" || echo $$i; done` && \
130 test -z "$$bad" || { \
131 echo >&2 "non-executable tests:" $$bad; exit 1; }
133 test-lint-shell-syntax:
134 @'$(PERL_PATH_SQ
)' check-non-portable-shell.pl $(T) $(THELPERS) $(TPERF)
137 @# We do *not* pass a glob to ls-files but use grep instead, to catch
138 @# non-ASCII characters (which are quoted within double-quotes)
139 @bad="$$(git -c core.quotepath=true ls-files 2>/dev/null | \
140 grep '["*:<>?\\|]')"; \
141 test -z
"$$bad" ||
{ \
142 echo
>&2 "non-portable file name(s): $$bad"; exit
1; }
145 @
$(CHAINLINT
) $(T
) $(TLIBS
) $(TPERF
) $(TINTEROP
)
147 aggregate-results-and-cleanup
: $(T
)
148 $(MAKE
) aggregate-results
152 @
'$(SHELL_PATH_SQ)' .
/aggregate-results.sh
'$(TEST_RESULTS_DIRECTORY_SQ)'
155 $(MAKE
) GIT_TEST_OPTS
="$(GIT_TEST_OPTS) --valgrind"
160 .PHONY
: pre-clean
$(T
) aggregate-results
clean valgrind perf \
161 check-chainlint clean-chainlint test-chainlint
$(UNIT_TESTS
)