t/t0211-trace2-perf.sh: fix typo patern -> pattern
[alt-git.git] / t / Makefile
blob882782a519c97b65d2a6d487ac6849a540015fe4
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.autogen
10 -include ../config.mak
12 #GIT_TEST_OPTS = --verbose --debug
13 SHELL_PATH ?= $(SHELL)
14 TEST_SHELL_PATH ?= $(SHELL_PATH)
15 PERL_PATH ?= /usr/bin/perl
16 TAR ?= $(TAR)
17 RM ?= rm -f
18 PROVE ?= prove
19 DEFAULT_TEST_TARGET ?= test
20 TEST_LINT ?= test-lint
22 ifdef TEST_OUTPUT_DIRECTORY
23 TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results
24 CHAINLINTTMP = $(TEST_OUTPUT_DIRECTORY)/chainlinttmp
25 else
26 TEST_RESULTS_DIRECTORY = test-results
27 CHAINLINTTMP = chainlinttmp
28 endif
30 # Shell quote;
31 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
32 TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
33 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
34 TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
35 CHAINLINTTMP_SQ = $(subst ','\'',$(CHAINLINTTMP))
37 T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
38 THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh)))
39 TLIBS = $(sort $(wildcard lib-*.sh)) annotate-tests.sh
40 TPERF = $(sort $(wildcard perf/p[0-9][0-9][0-9][0-9]-*.sh))
41 TINTEROP = $(sort $(wildcard interop/i[0-9][0-9][0-9][0-9]-*.sh))
42 CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test)))
43 CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl
45 # `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`)
46 # checks all tests in all scripts via a single invocation, so tell individual
47 # scripts not to "chainlint" themselves
48 CHAINLINTSUPPRESS = GIT_TEST_CHAIN_LINT=0 && export GIT_TEST_CHAIN_LINT &&
50 all: $(DEFAULT_TEST_TARGET)
52 test: pre-clean check-chainlint $(TEST_LINT)
53 $(CHAINLINTSUPPRESS) $(MAKE) aggregate-results-and-cleanup
55 failed:
56 @failed=$$(cd '$(TEST_RESULTS_DIRECTORY_SQ)' && \
57 grep -l '^failed [1-9]' *.counts | \
58 sed -n 's/\.counts$$/.sh/p') && \
59 test -z "$$failed" || $(MAKE) $$failed
61 prove: pre-clean check-chainlint $(TEST_LINT)
62 @echo "*** prove ***"; $(CHAINLINTSUPPRESS) $(PROVE) --exec '$(TEST_SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
63 $(MAKE) clean-except-prove-cache
65 $(T):
66 @echo "*** $@ ***"; '$(TEST_SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
68 pre-clean:
69 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
71 clean-except-prove-cache: clean-chainlint
72 $(RM) -r 'trash directory'.*
73 $(RM) -r valgrind/bin
75 clean: clean-except-prove-cache
76 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
77 $(RM) .prove
79 clean-chainlint:
80 $(RM) -r '$(CHAINLINTTMP_SQ)'
82 check-chainlint:
83 @mkdir -p '$(CHAINLINTTMP_SQ)' && \
84 for i in $(CHAINLINTTESTS); do \
85 echo "test_expect_success '$$i' '" && \
86 sed -e '/^# LINT: /d' chainlint/$$i.test && \
87 echo "'"; \
88 done >'$(CHAINLINTTMP_SQ)'/tests && \
89 { \
90 echo "# chainlint: $(CHAINLINTTMP_SQ)/tests" && \
91 for i in $(CHAINLINTTESTS); do \
92 echo "# chainlint: $$i" && \
93 sed -e '/^[ ]*$$/d' chainlint/$$i.expect; \
94 done \
95 } >'$(CHAINLINTTMP_SQ)'/expect && \
96 $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests | \
97 grep -v '^[ ]*$$' >'$(CHAINLINTTMP_SQ)'/actual && \
98 if test -f ../GIT-BUILD-OPTIONS; then \
99 . ../GIT-BUILD-OPTIONS; \
100 fi && \
101 if test -x ../git$$X; then \
102 DIFFW="../git$$X --no-pager diff -w --no-index"; \
103 else \
104 DIFFW="diff -w -u"; \
105 fi && \
106 $$DIFFW '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual
108 test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
109 test-lint-filenames
110 ifneq ($(GIT_TEST_CHAIN_LINT),0)
111 test-lint: test-chainlint
112 endif
114 test-lint-duplicates:
115 @dups=`echo $(T) $(TPERF) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
116 test -z "$$dups" || { \
117 echo >&2 "duplicate test numbers:" $$dups; exit 1; }
119 test-lint-executable:
120 @bad=`for i in $(T) $(TPERF); do test -x "$$i" || echo $$i; done` && \
121 test -z "$$bad" || { \
122 echo >&2 "non-executable tests:" $$bad; exit 1; }
124 test-lint-shell-syntax:
125 @'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) $(THELPERS) $(TPERF)
127 test-lint-filenames:
128 @# We do *not* pass a glob to ls-files but use grep instead, to catch
129 @# non-ASCII characters (which are quoted within double-quotes)
130 @bad="$$(git -c core.quotepath=true ls-files 2>/dev/null | \
131 grep '["*:<>?\\|]')"; \
132 test -z "$$bad" || { \
133 echo >&2 "non-portable file name(s): $$bad"; exit 1; }
135 test-chainlint:
136 @$(CHAINLINT) $(T) $(TLIBS) $(TPERF) $(TINTEROP)
138 aggregate-results-and-cleanup: $(T)
139 $(MAKE) aggregate-results
140 $(MAKE) clean
142 aggregate-results:
143 for f in '$(TEST_RESULTS_DIRECTORY_SQ)'/t*-*.counts; do \
144 echo "$$f"; \
145 done | '$(SHELL_PATH_SQ)' ./aggregate-results.sh
147 valgrind:
148 $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"
150 perf:
151 $(MAKE) -C perf/ all
153 .PHONY: pre-clean $(T) aggregate-results clean valgrind perf \
154 check-chainlint clean-chainlint test-chainlint