t/t1*: avoid redundant uses of cat
[alt-git.git] / t / Makefile
blob2d95046f26ec6ebad9d8707e8c002aadc665a282
1 # The default target of this Makefile is...
2 all::
4 # Import tree-wide shared Makefile behavior and libraries
5 include ../shared.mak
7 # Run tests
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
20 TAR ?= $(TAR)
21 RM ?= rm -f
22 PROVE ?= prove
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
30 else
31 TEST_RESULTS_DIRECTORY = test-results
32 CHAINLINTTMP = chainlinttmp
33 endif
35 # Shell quote;
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_TESTS = $(sort $(filter-out unit-tests/bin/t-basic%,$(UNIT_TEST_PROGRAMS)))
53 # `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`)
54 # checks all tests in all scripts via a single invocation, so tell individual
55 # scripts not to run the external "chainlint.pl" script themselves
56 CHAINLINTSUPPRESS = GIT_TEST_EXT_CHAIN_LINT=0 && export GIT_TEST_EXT_CHAIN_LINT &&
58 all:: $(DEFAULT_TEST_TARGET)
60 test: pre-clean check-chainlint $(TEST_LINT)
61 $(CHAINLINTSUPPRESS) $(MAKE) aggregate-results-and-cleanup
63 failed:
64 @failed=$$(cd '$(TEST_RESULTS_DIRECTORY_SQ)' && \
65 grep -l '^failed [1-9]' *.counts | \
66 sed -n 's/\.counts$$/.sh/p') && \
67 test -z "$$failed" || $(MAKE) $$failed
69 prove: pre-clean check-chainlint $(TEST_LINT)
70 @echo "*** prove ***"; $(CHAINLINTSUPPRESS) $(PROVE) --exec '$(TEST_SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
71 $(MAKE) clean-except-prove-cache
73 $(T):
74 @echo "*** $@ ***"; '$(TEST_SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
76 $(UNIT_TESTS):
77 @echo "*** $@ ***"; $@
79 .PHONY: unit-tests unit-tests-raw unit-tests-prove
80 unit-tests: $(DEFAULT_UNIT_TEST_TARGET)
82 unit-tests-raw: $(UNIT_TESTS)
84 unit-tests-prove:
85 @echo "*** prove - unit tests ***"; $(PROVE) $(GIT_PROVE_OPTS) $(UNIT_TESTS)
87 pre-clean:
88 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
90 clean-except-prove-cache: clean-chainlint
91 $(RM) -r 'trash directory'.*
92 $(RM) -r valgrind/bin
94 clean: clean-except-prove-cache
95 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
96 $(RM) .prove
98 clean-chainlint:
99 $(RM) -r '$(CHAINLINTTMP_SQ)'
101 check-chainlint:
102 @mkdir -p '$(CHAINLINTTMP_SQ)' && \
103 for i in $(CHAINLINTTESTS); do \
104 echo "test_expect_success '$$i' '" && \
105 sed -e '/^# LINT: /d' chainlint/$$i.test && \
106 echo "'"; \
107 done >'$(CHAINLINTTMP_SQ)'/tests && \
109 echo "# chainlint: $(CHAINLINTTMP_SQ)/tests" && \
110 for i in $(CHAINLINTTESTS); do \
111 echo "# chainlint: $$i" && \
112 cat chainlint/$$i.expect; \
113 done \
114 } >'$(CHAINLINTTMP_SQ)'/expect && \
115 $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests | \
116 sed -e 's/^[1-9][0-9]* //' >'$(CHAINLINTTMP_SQ)'/actual && \
117 diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual
119 test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
120 test-lint-filenames
121 ifneq ($(GIT_TEST_CHAIN_LINT),0)
122 test-lint: test-chainlint
123 endif
125 test-lint-duplicates:
126 @dups=`echo $(T) $(TPERF) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
127 test -z "$$dups" || { \
128 echo >&2 "duplicate test numbers:" $$dups; exit 1; }
130 test-lint-executable:
131 @bad=`for i in $(T) $(TPERF); do test -x "$$i" || echo $$i; done` && \
132 test -z "$$bad" || { \
133 echo >&2 "non-executable tests:" $$bad; exit 1; }
135 test-lint-shell-syntax:
136 @'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) $(THELPERS) $(TPERF)
138 test-lint-filenames:
139 @# We do *not* pass a glob to ls-files but use grep instead, to catch
140 @# non-ASCII characters (which are quoted within double-quotes)
141 @bad="$$(git -c core.quotepath=true ls-files 2>/dev/null | \
142 grep '["*:<>?\\|]')"; \
143 test -z "$$bad" || { \
144 echo >&2 "non-portable file name(s): $$bad"; exit 1; }
146 test-chainlint:
147 @$(CHAINLINT) $(T) $(TLIBS) $(TPERF) $(TINTEROP)
149 aggregate-results-and-cleanup: $(T)
150 $(MAKE) aggregate-results
151 $(MAKE) clean
153 aggregate-results:
154 @'$(SHELL_PATH_SQ)' ./aggregate-results.sh '$(TEST_RESULTS_DIRECTORY_SQ)'
156 valgrind:
157 $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"
159 perf:
160 $(MAKE) -C perf/ all
162 .PHONY: pre-clean $(T) aggregate-results clean valgrind perf \
163 check-chainlint clean-chainlint test-chainlint $(UNIT_TESTS)