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