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
10SHELL_PATH ?= $(SHELL)
11PERL_PATH ?= /usr/bin/perl
12TAR ?= $(TAR)
13RM ?= rm -f
14PROVE ?= prove
15DEFAULT_TEST_TARGET ?= test
16TEST_LINT ?= test-lint
17
18ifdef TEST_OUTPUT_DIRECTORY
19TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results
20else
21TEST_RESULTS_DIRECTORY = test-results
22endif
23
24# Shell quote;
25SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
26PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
27TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
28
29T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
30TGITWEB = $(sort $(wildcard t95[0-9][0-9]-*.sh))
31THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh)))
32
33all: $(DEFAULT_TEST_TARGET)
34
35test: pre-clean $(TEST_LINT)
36 $(MAKE) aggregate-results-and-cleanup
37
38prove: pre-clean $(TEST_LINT)
39 @echo "*** prove ***"; $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
40 $(MAKE) clean-except-prove-cache
41
42$(T):
43 @echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
44
45pre-clean:
46 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
47
48clean-except-prove-cache:
49 $(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)'
50 $(RM) -r valgrind/bin
51
52clean: clean-except-prove-cache
53 $(RM) .prove
54
55test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
56 test-lint-filenames
57
58test-lint-duplicates:
59 @dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
60 test -z "$$dups" || { \
61 echo >&2 "duplicate test numbers:" $$dups; exit 1; }
62
63test-lint-executable:
64 @bad=`for i in $(T); do test -x "$$i" || echo $$i; done` && \
65 test -z "$$bad" || { \
66 echo >&2 "non-executable tests:" $$bad; exit 1; }
67
68test-lint-shell-syntax:
69 @'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) $(THELPERS)
70
71test-lint-filenames:
72 @# We do *not* pass a glob to ls-files but use grep instead, to catch
73 @# non-ASCII characters (which are quoted within double-quotes)
74 @bad="$$(git -c core.quotepath=true ls-files 2>/dev/null | \
75 grep '["*:<>?\\|]')"; \
76 test -z "$$bad" || { \
77 echo >&2 "non-portable file name(s): $$bad"; exit 1; }
78
79aggregate-results-and-cleanup: $(T)
80 $(MAKE) aggregate-results
81 $(MAKE) clean
82
83aggregate-results:
84 for f in '$(TEST_RESULTS_DIRECTORY_SQ)'/t*-*.counts; do \
85 echo "$$f"; \
86 done | '$(SHELL_PATH_SQ)' ./aggregate-results.sh
87
88gitweb-test:
89 $(MAKE) $(TGITWEB)
90
91valgrind:
92 $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"
93
94perf:
95 $(MAKE) -C perf/ all
96
97.PHONY: pre-clean $(T) aggregate-results clean valgrind perf