t/Makefile: get UNIT_TESTS list from C sources
[git.git] / t / Makefile
blob281f4c3534fd30ad090cf1d9d4a4a7272d90a298
1 # Import tree-wide shared Makefile behavior and libraries
2 include ../shared.mak
4 # Run tests
6 # Copyright (c) 2005 Junio C Hamano
9 -include ../config.mak.uname
10 -include ../config.mak.autogen
11 -include ../config.mak
13 #GIT_TEST_OPTS = --verbose --debug
14 SHELL_PATH ?= $(SHELL)
15 TEST_SHELL_PATH ?= $(SHELL_PATH)
16 PERL_PATH ?= /usr/bin/perl
17 TAR ?= $(TAR)
18 RM ?= rm -f
19 PROVE ?= prove
20 DEFAULT_TEST_TARGET ?= test
21 DEFAULT_UNIT_TEST_TARGET ?= unit-tests-raw
22 TEST_LINT ?= test-lint
24 ifdef TEST_OUTPUT_DIRECTORY
25 TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results
26 CHAINLINTTMP = $(TEST_OUTPUT_DIRECTORY)/chainlinttmp
27 else
28 TEST_RESULTS_DIRECTORY = test-results
29 CHAINLINTTMP = chainlinttmp
30 endif
32 # Shell quote;
33 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
34 TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
35 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
36 TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
37 CHAINLINTTMP_SQ = $(subst ','\'',$(CHAINLINTTMP))
39 T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
40 THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh)))
41 TLIBS = $(sort $(wildcard lib-*.sh)) annotate-tests.sh
42 TPERF = $(sort $(wildcard perf/p[0-9][0-9][0-9][0-9]-*.sh))
43 TINTEROP = $(sort $(wildcard interop/i[0-9][0-9][0-9][0-9]-*.sh))
44 CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test)))
45 CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl
46 UNIT_TEST_SOURCES = $(wildcard unit-tests/t-*.c)
47 UNIT_TEST_PROGRAMS = $(patsubst unit-tests/%.c,unit-tests/bin/%$(X),$(UNIT_TEST_SOURCES))
48 UNIT_TESTS = $(sort $(filter-out unit-tests/bin/t-basic%,$(UNIT_TEST_PROGRAMS)))
50 # `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`)
51 # checks all tests in all scripts via a single invocation, so tell individual
52 # scripts not to run the external "chainlint.pl" script themselves
53 CHAINLINTSUPPRESS = GIT_TEST_EXT_CHAIN_LINT=0 && export GIT_TEST_EXT_CHAIN_LINT &&
55 all: $(DEFAULT_TEST_TARGET)
57 test: pre-clean check-chainlint $(TEST_LINT)
58 $(CHAINLINTSUPPRESS) $(MAKE) aggregate-results-and-cleanup
60 failed:
61 @failed=$$(cd '$(TEST_RESULTS_DIRECTORY_SQ)' && \
62 grep -l '^failed [1-9]' *.counts | \
63 sed -n 's/\.counts$$/.sh/p') && \
64 test -z "$$failed" || $(MAKE) $$failed
66 prove: pre-clean check-chainlint $(TEST_LINT)
67 @echo "*** prove ***"; $(CHAINLINTSUPPRESS) $(PROVE) --exec '$(TEST_SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
68 $(MAKE) clean-except-prove-cache
70 $(T):
71 @echo "*** $@ ***"; '$(TEST_SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
73 $(UNIT_TESTS):
74 @echo "*** $@ ***"; $@
76 .PHONY: unit-tests unit-tests-raw unit-tests-prove
77 unit-tests: $(DEFAULT_UNIT_TEST_TARGET)
79 unit-tests-raw: $(UNIT_TESTS)
81 unit-tests-prove:
82 @echo "*** prove - unit tests ***"; $(PROVE) $(GIT_PROVE_OPTS) $(UNIT_TESTS)
84 pre-clean:
85 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
87 clean-except-prove-cache: clean-chainlint
88 $(RM) -r 'trash directory'.*
89 $(RM) -r valgrind/bin
91 clean: clean-except-prove-cache
92 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
93 $(RM) .prove
95 clean-chainlint:
96 $(RM) -r '$(CHAINLINTTMP_SQ)'
98 check-chainlint:
99 @mkdir -p '$(CHAINLINTTMP_SQ)' && \
100 for i in $(CHAINLINTTESTS); do \
101 echo "test_expect_success '$$i' '" && \
102 sed -e '/^# LINT: /d' chainlint/$$i.test && \
103 echo "'"; \
104 done >'$(CHAINLINTTMP_SQ)'/tests && \
106 echo "# chainlint: $(CHAINLINTTMP_SQ)/tests" && \
107 for i in $(CHAINLINTTESTS); do \
108 echo "# chainlint: $$i" && \
109 cat chainlint/$$i.expect; \
110 done \
111 } >'$(CHAINLINTTMP_SQ)'/expect && \
112 $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests | \
113 sed -e 's/^[1-9][0-9]* //' >'$(CHAINLINTTMP_SQ)'/actual && \
114 diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual
116 test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
117 test-lint-filenames
118 ifneq ($(GIT_TEST_CHAIN_LINT),0)
119 test-lint: test-chainlint
120 endif
122 test-lint-duplicates:
123 @dups=`echo $(T) $(TPERF) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
124 test -z "$$dups" || { \
125 echo >&2 "duplicate test numbers:" $$dups; exit 1; }
127 test-lint-executable:
128 @bad=`for i in $(T) $(TPERF); do test -x "$$i" || echo $$i; done` && \
129 test -z "$$bad" || { \
130 echo >&2 "non-executable tests:" $$bad; exit 1; }
132 test-lint-shell-syntax:
133 @'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) $(THELPERS) $(TPERF)
135 test-lint-filenames:
136 @# We do *not* pass a glob to ls-files but use grep instead, to catch
137 @# non-ASCII characters (which are quoted within double-quotes)
138 @bad="$$(git -c core.quotepath=true ls-files 2>/dev/null | \
139 grep '["*:<>?\\|]')"; \
140 test -z "$$bad" || { \
141 echo >&2 "non-portable file name(s): $$bad"; exit 1; }
143 test-chainlint:
144 @$(CHAINLINT) $(T) $(TLIBS) $(TPERF) $(TINTEROP)
146 aggregate-results-and-cleanup: $(T)
147 $(MAKE) aggregate-results
148 $(MAKE) clean
150 aggregate-results:
151 @'$(SHELL_PATH_SQ)' ./aggregate-results.sh '$(TEST_RESULTS_DIRECTORY_SQ)'
153 valgrind:
154 $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"
156 perf:
157 $(MAKE) -C perf/ all
159 .PHONY: pre-clean $(T) aggregate-results clean valgrind perf \
160 check-chainlint clean-chainlint test-chainlint $(UNIT_TESTS)