t / Makefileon commit Merge branch 'sg/core-filemode-doc-typofix' into maint (b8a4652)
   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
  38failed:
  39        @failed=$$(cd '$(TEST_RESULTS_DIRECTORY_SQ)' && \
  40                grep -l '^failed [1-9]' *.counts | \
  41                sed -n 's/\.counts$$/.sh/p') && \
  42        test -z "$$failed" || $(MAKE) $$failed
  43
  44prove: pre-clean $(TEST_LINT)
  45        @echo "*** prove ***"; $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
  46        $(MAKE) clean-except-prove-cache
  47
  48$(T):
  49        @echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
  50
  51pre-clean:
  52        $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
  53
  54clean-except-prove-cache:
  55        $(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)'
  56        $(RM) -r valgrind/bin
  57
  58clean: clean-except-prove-cache
  59        $(RM) .prove
  60
  61test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
  62        test-lint-filenames
  63
  64test-lint-duplicates:
  65        @dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
  66                test -z "$$dups" || { \
  67                echo >&2 "duplicate test numbers:" $$dups; exit 1; }
  68
  69test-lint-executable:
  70        @bad=`for i in $(T); do test -x "$$i" || echo $$i; done` && \
  71                test -z "$$bad" || { \
  72                echo >&2 "non-executable tests:" $$bad; exit 1; }
  73
  74test-lint-shell-syntax:
  75        @'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) $(THELPERS)
  76
  77test-lint-filenames:
  78        @# We do *not* pass a glob to ls-files but use grep instead, to catch
  79        @# non-ASCII characters (which are quoted within double-quotes)
  80        @bad="$$(git -c core.quotepath=true ls-files 2>/dev/null | \
  81                        grep '["*:<>?\\|]')"; \
  82                test -z "$$bad" || { \
  83                echo >&2 "non-portable file name(s): $$bad"; exit 1; }
  84
  85aggregate-results-and-cleanup: $(T)
  86        $(MAKE) aggregate-results
  87        $(MAKE) clean
  88
  89aggregate-results:
  90        for f in '$(TEST_RESULTS_DIRECTORY_SQ)'/t*-*.counts; do \
  91                echo "$$f"; \
  92        done | '$(SHELL_PATH_SQ)' ./aggregate-results.sh
  93
  94gitweb-test:
  95        $(MAKE) $(TGITWEB)
  96
  97valgrind:
  98        $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"
  99
 100perf:
 101        $(MAKE) -C perf/ all
 102
 103.PHONY: pre-clean $(T) aggregate-results clean valgrind perf