| 1 |
|
| 2 |
all:: |
| 3 |
|
| 4 |
|
| 5 |
include ../shared.mak |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
-include ../config.mak.uname |
| 13 |
-include ../config.mak.autogen |
| 14 |
-include ../config.mak |
| 15 |
|
| 16 |
|
| 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 |
else |
| 31 |
TEST_RESULTS_DIRECTORY = test-results |
| 32 |
CHAINLINTTMP = chainlinttmp |
| 33 |
endif |
| 34 |
|
| 35 |
|
| 36 |
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) |
| 37 |
TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH)) |
| 38 |
PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH)) |
| 39 |
TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY)) |
| 40 |
CHAINLINTTMP_SQ = $(subst ','\'',$(CHAINLINTTMP)) |
| 41 |
|
| 42 |
T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) |
| 43 |
THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh))) |
| 44 |
TLIBS = $(sort $(wildcard lib-*.sh)) annotate-tests.sh |
| 45 |
TPERF = $(sort $(wildcard perf/p[0-9][0-9][0-9][0-9]-*.sh)) |
| 46 |
TINTEROP = $(sort $(wildcard interop/i[0-9][0-9][0-9][0-9]-*.sh)) |
| 47 |
CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test))) |
| 48 |
CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl |
| 49 |
UNIT_TEST_SOURCES = $(wildcard unit-tests/t-*.c) |
| 50 |
UNIT_TEST_PROGRAMS = $(patsubst unit-tests/%.c,unit-tests/bin/%$(X),$(UNIT_TEST_SOURCES)) |
| 51 |
UNIT_TEST_PROGRAMS += unit-tests/bin/unit-tests$(X) |
| 52 |
UNIT_TESTS = $(sort $(UNIT_TEST_PROGRAMS)) |
| 53 |
UNIT_TESTS_NO_DIR = $(notdir $(UNIT_TESTS)) |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
CHAINLINTSUPPRESS = GIT_TEST_EXT_CHAIN_LINT=0 && export GIT_TEST_EXT_CHAIN_LINT && |
| 59 |
|
| 60 |
all:: $(DEFAULT_TEST_TARGET) |
| 61 |
|
| 62 |
test: pre-clean check-meson $(TEST_LINT) |
| 63 |
$(CHAINLINTSUPPRESS) $(MAKE) aggregate-results-and-cleanup |
| 64 |
|
| 65 |
ifneq ($(PERL_PATH),) |
| 66 |
test: check-chainlint |
| 67 |
prove: check-chainlint |
| 68 |
endif |
| 69 |
|
| 70 |
failed: |
| 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 |
|
| 76 |
prove: 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 |
| 88 |
unit-tests: $(DEFAULT_UNIT_TEST_TARGET) |
| 89 |
|
| 90 |
unit-tests-raw: $(UNIT_TESTS) |
| 91 |
|
| 92 |
unit-tests-prove: |
| 93 |
@echo "*** prove - unit tests ***"; $(PROVE) $(GIT_PROVE_OPTS) $(UNIT_TESTS) |
| 94 |
|
| 95 |
unit-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 |
|
| 102 |
pre-clean: |
| 103 |
$(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)' |
| 104 |
|
| 105 |
clean-except-prove-cache: clean-chainlint |
| 106 |
$(RM) -r 'trash directory'.* |
| 107 |
$(RM) -r valgrind/bin |
| 108 |
|
| 109 |
clean: clean-except-prove-cache |
| 110 |
$(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)' |
| 111 |
$(RM) -r mesontmp |
| 112 |
$(RM) .prove |
| 113 |
|
| 114 |
clean-chainlint: |
| 115 |
$(RM) -r '$(CHAINLINTTMP_SQ)' |
| 116 |
|
| 117 |
check-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 |
|
| 123 |
check-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 |
|
| 139 |
test-lint: test-lint-duplicates test-lint-executable \ |
| 140 |
test-lint-filenames |
| 141 |
ifneq ($(PERL_PATH),) |
| 142 |
test-lint: test-lint-shell-syntax |
| 143 |
else |
| 144 |
GIT_TEST_CHAIN_LINT = 0 |
| 145 |
endif |
| 146 |
ifneq ($(GIT_TEST_CHAIN_LINT),0) |
| 147 |
test-lint: test-chainlint |
| 148 |
endif |
| 149 |
|
| 150 |
test-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 |
|
| 155 |
test-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 |
|
| 160 |
test-lint-shell-syntax: |
| 161 |
@'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) $(THELPERS) $(TPERF) |
| 162 |
|
| 163 |
test-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 |
|
| 171 |
test-chainlint: |
| 172 |
@$(CHAINLINT) $(T) $(TLIBS) $(TPERF) $(TINTEROP) |
| 173 |
|
| 174 |
aggregate-results-and-cleanup: $(T) |
| 175 |
$(MAKE) aggregate-results |
| 176 |
$(MAKE) clean |
| 177 |
|
| 178 |
aggregate-results: |
| 179 |
@'$(SHELL_PATH_SQ)' ./aggregate-results.sh '$(TEST_RESULTS_DIRECTORY_SQ)' |
| 180 |
|
| 181 |
valgrind: |
| 182 |
$(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind" |
| 183 |
|
| 184 |
perf: |
| 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 |
| 191 |
libgit-sys-test: |
| 192 |
$(QUIET)cargo test --manifest-path ../contrib/libgit-sys/Cargo.toml |
| 193 |
libgit-rs-test: libgit-sys-test |
| 194 |
$(QUIET)cargo test --manifest-path ../contrib/libgit-rs/Cargo.toml |
| 195 |
ifdef INCLUDE_LIBGIT_RS |
| 196 |
all:: libgit-rs-test |
| 197 |
endif |