Git fork
at reftables-rust 197 lines 6.2 kB view raw
1# The default target of this Makefile is... 2all:: 3 4# Import tree-wide shared Makefile behavior and libraries 5include ../shared.mak 6 7# Run tests 8# 9# Copyright (c) 2005 Junio C Hamano 10# 11 12-include ../config.mak.uname 13-include ../config.mak.autogen 14-include ../config.mak 15 16#GIT_TEST_OPTS = --verbose --debug 17SHELL_PATH ?= $(SHELL) 18TEST_SHELL_PATH ?= $(SHELL_PATH) 19PERL_PATH ?= /usr/bin/perl 20TAR ?= $(TAR) 21RM ?= rm -f 22PROVE ?= prove 23DEFAULT_TEST_TARGET ?= test 24DEFAULT_UNIT_TEST_TARGET ?= unit-tests-raw 25TEST_LINT ?= test-lint 26 27ifdef TEST_OUTPUT_DIRECTORY 28TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results 29CHAINLINTTMP = $(TEST_OUTPUT_DIRECTORY)/chainlinttmp 30else 31TEST_RESULTS_DIRECTORY = test-results 32CHAINLINTTMP = chainlinttmp 33endif 34 35# Shell quote; 36SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) 37TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH)) 38PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH)) 39TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY)) 40CHAINLINTTMP_SQ = $(subst ','\'',$(CHAINLINTTMP)) 41 42T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) 43THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh))) 44TLIBS = $(sort $(wildcard lib-*.sh)) annotate-tests.sh 45TPERF = $(sort $(wildcard perf/p[0-9][0-9][0-9][0-9]-*.sh)) 46TINTEROP = $(sort $(wildcard interop/i[0-9][0-9][0-9][0-9]-*.sh)) 47CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test))) 48CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl 49UNIT_TEST_SOURCES = $(wildcard unit-tests/t-*.c) 50UNIT_TEST_PROGRAMS = $(patsubst unit-tests/%.c,unit-tests/bin/%$(X),$(UNIT_TEST_SOURCES)) 51UNIT_TEST_PROGRAMS += unit-tests/bin/unit-tests$(X) 52UNIT_TESTS = $(sort $(UNIT_TEST_PROGRAMS)) 53UNIT_TESTS_NO_DIR = $(notdir $(UNIT_TESTS)) 54 55# `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`) 56# checks all tests in all scripts via a single invocation, so tell individual 57# scripts not to run the external "chainlint.pl" script themselves 58CHAINLINTSUPPRESS = GIT_TEST_EXT_CHAIN_LINT=0 && export GIT_TEST_EXT_CHAIN_LINT && 59 60all:: $(DEFAULT_TEST_TARGET) 61 62test: pre-clean check-meson $(TEST_LINT) 63 $(CHAINLINTSUPPRESS) $(MAKE) aggregate-results-and-cleanup 64 65ifneq ($(PERL_PATH),) 66test: check-chainlint 67prove: check-chainlint 68endif 69 70failed: 71 @failed=$$(cd '$(TEST_RESULTS_DIRECTORY_SQ)' && \ 72 grep -l '^failed [1-9]' *.counts | \ 73 sed -n 's/\.counts$$/.sh/p') && \ 74 test -z "$$failed" || $(MAKE) $$failed 75 76prove: pre-clean $(TEST_LINT) 77 @echo "*** prove (shell & unit tests) ***" 78 @$(CHAINLINTSUPPRESS) TEST_OPTIONS='$(GIT_TEST_OPTS)' TEST_SHELL_PATH='$(TEST_SHELL_PATH_SQ)' $(PROVE) --exec ./run-test.sh $(GIT_PROVE_OPTS) $(T) $(UNIT_TESTS) 79 $(MAKE) clean-except-prove-cache 80 81$(T): 82 @echo "*** $@ ***"; '$(TEST_SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS) 83 84$(UNIT_TESTS): 85 @echo "*** $@ ***"; $@ 86 87.PHONY: unit-tests unit-tests-raw unit-tests-prove unit-tests-test-tool 88unit-tests: $(DEFAULT_UNIT_TEST_TARGET) 89 90unit-tests-raw: $(UNIT_TESTS) 91 92unit-tests-prove: 93 @echo "*** prove - unit tests ***"; $(PROVE) $(GIT_PROVE_OPTS) $(UNIT_TESTS) 94 95unit-tests-test-tool: 96 @echo "*** test-tool - unit tests **" 97 ( \ 98 cd unit-tests/bin && \ 99 ../../helper/test-tool$X run-command testsuite $(UNIT_TESTS_NO_DIR)\ 100 ) 101 102pre-clean: 103 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)' 104 105clean-except-prove-cache: clean-chainlint 106 $(RM) -r 'trash directory'.* 107 $(RM) -r valgrind/bin 108 109clean: clean-except-prove-cache 110 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)' 111 $(RM) -r mesontmp 112 $(RM) .prove 113 114clean-chainlint: 115 $(RM) -r '$(CHAINLINTTMP_SQ)' 116 117check-chainlint: 118 @mkdir -p '$(CHAINLINTTMP_SQ)' && \ 119 '$(PERL_PATH_SQ)' chainlint-cat.pl '$(CHAINLINTTMP_SQ)' $(CHAINLINTTESTS) && \ 120 { $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests >'$(CHAINLINTTMP_SQ)'/actual || true; } && \ 121 diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual 122 123check-meson: 124 @# awk acts up when trying to match single quotes, so we use \047 instead. 125 @mkdir -p mesontmp && \ 126 printf "%s\n" \ 127 "integration_tests t[0-9][0-9][0-9][0-9]-*.sh" \ 128 "clar_test_suites unit-tests/u-*.c" | \ 129 while read -r variable pattern; do \ 130 awk "/^$$variable = \[\$$/ {flag=1 ; next } /^]$$/ { flag=0 } flag { gsub(/^ \047/, \"\"); gsub(/\047,\$$/, \"\"); print }" meson.build >mesontmp/meson.txt && \ 131 ls $$pattern >mesontmp/actual.txt && \ 132 if ! cmp mesontmp/meson.txt mesontmp/actual.txt; then \ 133 echo "Meson tests differ from actual tests:"; \ 134 diff -u mesontmp/meson.txt mesontmp/actual.txt; \ 135 exit 1; \ 136 fi; \ 137 done 138 139test-lint: test-lint-duplicates test-lint-executable \ 140 test-lint-filenames 141ifneq ($(PERL_PATH),) 142test-lint: test-lint-shell-syntax 143else 144GIT_TEST_CHAIN_LINT = 0 145endif 146ifneq ($(GIT_TEST_CHAIN_LINT),0) 147test-lint: test-chainlint 148endif 149 150test-lint-duplicates: 151 @dups=`echo $(T) $(TPERF) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \ 152 test -z "$$dups" || { \ 153 echo >&2 "duplicate test numbers:" $$dups; exit 1; } 154 155test-lint-executable: 156 @bad=`for i in $(T) $(TPERF); do test -x "$$i" || echo $$i; done` && \ 157 test -z "$$bad" || { \ 158 echo >&2 "non-executable tests:" $$bad; exit 1; } 159 160test-lint-shell-syntax: 161 @'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) $(THELPERS) $(TPERF) 162 163test-lint-filenames: 164 @# We do *not* pass a glob to ls-files but use grep instead, to catch 165 @# non-ASCII characters (which are quoted within double-quotes) 166 @bad="$$(git -c core.quotepath=true ls-files 2>/dev/null | \ 167 grep '["*:<>?\\|]')"; \ 168 test -z "$$bad" || { \ 169 echo >&2 "non-portable file name(s): $$bad"; exit 1; } 170 171test-chainlint: 172 @$(CHAINLINT) $(T) $(TLIBS) $(TPERF) $(TINTEROP) 173 174aggregate-results-and-cleanup: $(T) 175 $(MAKE) aggregate-results 176 $(MAKE) clean 177 178aggregate-results: 179 @'$(SHELL_PATH_SQ)' ./aggregate-results.sh '$(TEST_RESULTS_DIRECTORY_SQ)' 180 181valgrind: 182 $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind" 183 184perf: 185 $(MAKE) -C perf/ all 186 187.PHONY: pre-clean $(T) aggregate-results clean valgrind perf \ 188 check-chainlint clean-chainlint test-chainlint $(UNIT_TESTS) 189 190.PHONY: libgit-sys-test libgit-rs-test 191libgit-sys-test: 192 $(QUIET)cargo test --manifest-path ../contrib/libgit-sys/Cargo.toml 193libgit-rs-test: libgit-sys-test 194 $(QUIET)cargo test --manifest-path ../contrib/libgit-rs/Cargo.toml 195ifdef INCLUDE_LIBGIT_RS 196all:: libgit-rs-test 197endif