]>
Commit | Line | Data |
---|---|---|
8df786d2 ÆAB |
1 | # Import tree-wide shared Makefile behavior and libraries |
2 | include ../shared.mak | |
3 | ||
e1970ce4 JH |
4 | # Run tests |
5 | # | |
6 | # Copyright (c) 2005 Junio C Hamano | |
7 | # | |
d6928ebd | 8 | |
b2b0026e | 9 | -include ../config.mak.autogen |
c14417c4 JK |
10 | -include ../config.mak |
11 | ||
dd6fc7ca | 12 | #GIT_TEST_OPTS = --verbose --debug |
edde7a8b | 13 | SHELL_PATH ?= $(SHELL) |
3f824e91 | 14 | TEST_SHELL_PATH ?= $(SHELL_PATH) |
4678a5cd | 15 | PERL_PATH ?= /usr/bin/perl |
455a7f32 | 16 | TAR ?= $(TAR) |
4cb08df5 | 17 | RM ?= rm -f |
28d836c8 MG |
18 | PROVE ?= prove |
19 | DEFAULT_TEST_TARGET ?= test | |
e137fe3b | 20 | DEFAULT_UNIT_TEST_TARGET ?= unit-tests-raw |
00f6991d | 21 | TEST_LINT ?= test-lint |
e1970ce4 | 22 | |
54bb9015 | 23 | ifdef TEST_OUTPUT_DIRECTORY |
b3e0c4ed | 24 | TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results |
80339445 | 25 | CHAINLINTTMP = $(TEST_OUTPUT_DIRECTORY)/chainlinttmp |
54bb9015 JK |
26 | else |
27 | TEST_RESULTS_DIRECTORY = test-results | |
80339445 | 28 | CHAINLINTTMP = chainlinttmp |
54bb9015 JK |
29 | endif |
30 | ||
4769948a | 31 | # Shell quote; |
39c015c5 | 32 | SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) |
3f824e91 | 33 | TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH)) |
c7ce70ac | 34 | PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH)) |
54bb9015 | 35 | TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY)) |
80339445 | 36 | CHAINLINTTMP_SQ = $(subst ','\'',$(CHAINLINTTMP)) |
4769948a | 37 | |
aae5239b | 38 | T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) |
cd78cea2 | 39 | THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh))) |
69b9924b | 40 | TLIBS = $(sort $(wildcard lib-*.sh)) annotate-tests.sh |
ed5a2457 | 41 | TPERF = $(sort $(wildcard perf/p[0-9][0-9][0-9][0-9]-*.sh)) |
69b9924b | 42 | TINTEROP = $(sort $(wildcard interop/i[0-9][0-9][0-9][0-9]-*.sh)) |
80339445 | 43 | CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test))) |
d00113ec | 44 | CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl |
0df903d4 | 45 | UNIT_TESTS = $(sort $(filter-out %.pdb unit-tests/bin/t-basic%,$(wildcard unit-tests/bin/t-*))) |
e1970ce4 | 46 | |
69b9924b ES |
47 | # `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`) |
48 | # checks all tests in all scripts via a single invocation, so tell individual | |
7b6555ab JK |
49 | # scripts not to run the external "chainlint.pl" script themselves |
50 | CHAINLINTSUPPRESS = GIT_TEST_EXT_CHAIN_LINT=0 && export GIT_TEST_EXT_CHAIN_LINT && | |
69b9924b | 51 | |
28d836c8 MG |
52 | all: $(DEFAULT_TEST_TARGET) |
53 | ||
80339445 | 54 | test: pre-clean check-chainlint $(TEST_LINT) |
69b9924b | 55 | $(CHAINLINTSUPPRESS) $(MAKE) aggregate-results-and-cleanup |
23fc63bf | 56 | |
93a04bb1 JS |
57 | failed: |
58 | @failed=$$(cd '$(TEST_RESULTS_DIRECTORY_SQ)' && \ | |
59 | grep -l '^failed [1-9]' *.counts | \ | |
60 | sed -n 's/\.counts$$/.sh/p') && \ | |
61 | test -z "$$failed" || $(MAKE) $$failed | |
62 | ||
80339445 | 63 | prove: pre-clean check-chainlint $(TEST_LINT) |
69b9924b | 64 | @echo "*** prove ***"; $(CHAINLINTSUPPRESS) $(PROVE) --exec '$(TEST_SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS) |
60f26f63 | 65 | $(MAKE) clean-except-prove-cache |
28d836c8 | 66 | |
23fc63bf | 67 | $(T): |
3f824e91 | 68 | @echo "*** $@ ***"; '$(TEST_SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS) |
e1970ce4 | 69 | |
e137fe3b PW |
70 | $(UNIT_TESTS): |
71 | @echo "*** $@ ***"; $@ | |
72 | ||
73 | .PHONY: unit-tests unit-tests-raw unit-tests-prove | |
74 | unit-tests: $(DEFAULT_UNIT_TEST_TARGET) | |
75 | ||
76 | unit-tests-raw: $(UNIT_TESTS) | |
77 | ||
78 | unit-tests-prove: | |
79 | @echo "*** prove - unit tests ***"; $(PROVE) $(GIT_PROVE_OPTS) $(UNIT_TESTS) | |
80 | ||
f8d5ffc2 | 81 | pre-clean: |
54bb9015 | 82 | $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)' |
f8d5ffc2 | 83 | |
80339445 | 84 | clean-except-prove-cache: clean-chainlint |
fee65b19 | 85 | $(RM) -r 'trash directory'.* |
34b383e7 | 86 | $(RM) -r valgrind/bin |
60f26f63 MH |
87 | |
88 | clean: clean-except-prove-cache | |
d11b8751 | 89 | $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)' |
9a3028b9 | 90 | $(RM) .prove |
23fc63bf | 91 | |
80339445 ES |
92 | clean-chainlint: |
93 | $(RM) -r '$(CHAINLINTTMP_SQ)' | |
94 | ||
95 | check-chainlint: | |
96 | @mkdir -p '$(CHAINLINTTMP_SQ)' && \ | |
d00113ec ES |
97 | for i in $(CHAINLINTTESTS); do \ |
98 | echo "test_expect_success '$$i' '" && \ | |
99 | sed -e '/^# LINT: /d' chainlint/$$i.test && \ | |
100 | echo "'"; \ | |
101 | done >'$(CHAINLINTTMP_SQ)'/tests && \ | |
102 | { \ | |
103 | echo "# chainlint: $(CHAINLINTTMP_SQ)/tests" && \ | |
104 | for i in $(CHAINLINTTESTS); do \ | |
105 | echo "# chainlint: $$i" && \ | |
647b5e09 | 106 | cat chainlint/$$i.expect; \ |
d00113ec ES |
107 | done \ |
108 | } >'$(CHAINLINTTMP_SQ)'/expect && \ | |
109 | $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests | \ | |
647b5e09 PS |
110 | sed -e 's/^[1-9][0-9]* //' >'$(CHAINLINTTMP_SQ)'/actual && \ |
111 | diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual | |
80339445 | 112 | |
c2cafd39 JS |
113 | test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \ |
114 | test-lint-filenames | |
69b9924b ES |
115 | ifneq ($(GIT_TEST_CHAIN_LINT),0) |
116 | test-lint: test-chainlint | |
117 | endif | |
d38732c2 JK |
118 | |
119 | test-lint-duplicates: | |
ed5a2457 | 120 | @dups=`echo $(T) $(TPERF) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \ |
d38732c2 JK |
121 | test -z "$$dups" || { \ |
122 | echo >&2 "duplicate test numbers:" $$dups; exit 1; } | |
123 | ||
124 | test-lint-executable: | |
ed5a2457 | 125 | @bad=`for i in $(T) $(TPERF); do test -x "$$i" || echo $$i; done` && \ |
d38732c2 JK |
126 | test -z "$$bad" || { \ |
127 | echo >&2 "non-executable tests:" $$bad; exit 1; } | |
128 | ||
c7ce70ac | 129 | test-lint-shell-syntax: |
ed5a2457 | 130 | @'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) $(THELPERS) $(TPERF) |
c7ce70ac | 131 | |
c2cafd39 JS |
132 | test-lint-filenames: |
133 | @# We do *not* pass a glob to ls-files but use grep instead, to catch | |
134 | @# non-ASCII characters (which are quoted within double-quotes) | |
135 | @bad="$$(git -c core.quotepath=true ls-files 2>/dev/null | \ | |
136 | grep '["*:<>?\\|]')"; \ | |
137 | test -z "$$bad" || { \ | |
138 | echo >&2 "non-portable file name(s): $$bad"; exit 1; } | |
139 | ||
69b9924b ES |
140 | test-chainlint: |
141 | @$(CHAINLINT) $(T) $(TLIBS) $(TPERF) $(TINTEROP) | |
142 | ||
e3df89a4 JS |
143 | aggregate-results-and-cleanup: $(T) |
144 | $(MAKE) aggregate-results | |
145 | $(MAKE) clean | |
146 | ||
f8d5ffc2 | 147 | aggregate-results: |
90ff7c98 | 148 | @'$(SHELL_PATH_SQ)' ./aggregate-results.sh '$(TEST_RESULTS_DIRECTORY_SQ)' |
f8d5ffc2 | 149 | |
7f6fdea1 | 150 | valgrind: |
7ef4d6b9 | 151 | $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind" |
7f6fdea1 | 152 | |
342e9ef2 TR |
153 | perf: |
154 | $(MAKE) -C perf/ all | |
155 | ||
69b9924b | 156 | .PHONY: pre-clean $(T) aggregate-results clean valgrind perf \ |
e137fe3b | 157 | check-chainlint clean-chainlint test-chainlint $(UNIT_TESTS) |