]> git.ipfire.org Git - thirdparty/git.git/blob - t/Makefile
Merge branch 'tl/doc-cli-options-first'
[thirdparty/git.git] / t / Makefile
1 # Run tests
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 #
5
6 -include ../config.mak.autogen
7 -include ../config.mak
8
9 #GIT_TEST_OPTS = --verbose --debug
10 SHELL_PATH ?= $(SHELL)
11 TEST_SHELL_PATH ?= $(SHELL_PATH)
12 PERL_PATH ?= /usr/bin/perl
13 TAR ?= $(TAR)
14 RM ?= rm -f
15 PROVE ?= prove
16 DEFAULT_TEST_TARGET ?= test
17 TEST_LINT ?= test-lint
18
19 ifdef TEST_OUTPUT_DIRECTORY
20 TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results
21 CHAINLINTTMP = $(TEST_OUTPUT_DIRECTORY)/chainlinttmp
22 else
23 TEST_RESULTS_DIRECTORY = test-results
24 CHAINLINTTMP = chainlinttmp
25 endif
26
27 # Shell quote;
28 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
29 TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
30 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
31 TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
32 CHAINLINTTMP_SQ = $(subst ','\'',$(CHAINLINTTMP))
33
34 T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
35 TGITWEB = $(sort $(wildcard t95[0-9][0-9]-*.sh))
36 THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh)))
37 TPERF = $(sort $(wildcard perf/p[0-9][0-9][0-9][0-9]-*.sh))
38 CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test)))
39 CHAINLINT = sed -f chainlint.sed
40
41 all: $(DEFAULT_TEST_TARGET)
42
43 test: pre-clean check-chainlint $(TEST_LINT)
44 $(MAKE) aggregate-results-and-cleanup
45
46 failed:
47 @failed=$$(cd '$(TEST_RESULTS_DIRECTORY_SQ)' && \
48 grep -l '^failed [1-9]' *.counts | \
49 sed -n 's/\.counts$$/.sh/p') && \
50 test -z "$$failed" || $(MAKE) $$failed
51
52 prove: pre-clean check-chainlint $(TEST_LINT)
53 @echo "*** prove ***"; $(PROVE) --exec '$(TEST_SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
54 $(MAKE) clean-except-prove-cache
55
56 $(T):
57 @echo "*** $@ ***"; '$(TEST_SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
58
59 pre-clean:
60 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
61
62 clean-except-prove-cache: clean-chainlint
63 $(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)'
64 $(RM) -r valgrind/bin
65
66 clean: clean-except-prove-cache
67 $(RM) .prove
68
69 clean-chainlint:
70 $(RM) -r '$(CHAINLINTTMP_SQ)'
71
72 check-chainlint:
73 @mkdir -p '$(CHAINLINTTMP_SQ)' && \
74 sed -e '/^# LINT: /d' $(patsubst %,chainlint/%.test,$(CHAINLINTTESTS)) >'$(CHAINLINTTMP_SQ)'/tests && \
75 sed -e '/^[ ]*$$/d' $(patsubst %,chainlint/%.expect,$(CHAINLINTTESTS)) >'$(CHAINLINTTMP_SQ)'/expect && \
76 $(CHAINLINT) '$(CHAINLINTTMP_SQ)'/tests | grep -v '^[ ]*$$' >'$(CHAINLINTTMP_SQ)'/actual && \
77 diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual
78
79 test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
80 test-lint-filenames
81
82 test-lint-duplicates:
83 @dups=`echo $(T) $(TPERF) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
84 test -z "$$dups" || { \
85 echo >&2 "duplicate test numbers:" $$dups; exit 1; }
86
87 test-lint-executable:
88 @bad=`for i in $(T) $(TPERF); do test -x "$$i" || echo $$i; done` && \
89 test -z "$$bad" || { \
90 echo >&2 "non-executable tests:" $$bad; exit 1; }
91
92 test-lint-shell-syntax:
93 @'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) $(THELPERS) $(TPERF)
94
95 test-lint-filenames:
96 @# We do *not* pass a glob to ls-files but use grep instead, to catch
97 @# non-ASCII characters (which are quoted within double-quotes)
98 @bad="$$(git -c core.quotepath=true ls-files 2>/dev/null | \
99 grep '["*:<>?\\|]')"; \
100 test -z "$$bad" || { \
101 echo >&2 "non-portable file name(s): $$bad"; exit 1; }
102
103 aggregate-results-and-cleanup: $(T)
104 $(MAKE) aggregate-results
105 $(MAKE) clean
106
107 aggregate-results:
108 for f in '$(TEST_RESULTS_DIRECTORY_SQ)'/t*-*.counts; do \
109 echo "$$f"; \
110 done | '$(SHELL_PATH_SQ)' ./aggregate-results.sh
111
112 gitweb-test:
113 $(MAKE) $(TGITWEB)
114
115 valgrind:
116 $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"
117
118 perf:
119 $(MAKE) -C perf/ all
120
121 .PHONY: pre-clean $(T) aggregate-results clean valgrind perf check-chainlint clean-chainlint