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