test-guard.mk: Add file
Running "make clean" in some directories can break "make test" in others. That notably happens by running clean somewhere in or below $(TOPDIR)/src/python, which removes __init__.py files potentially needed by unit and integration tests in $(TOPDIR)/test. This commit makes the failure easily visible by introducing the notion of "testabiltity" - if the tree is not testable, "make test" logs exactly that in a clear error message and gives up. Makefiles which need to check "testability" can use it as a prerequisite. This commit does that with py-run.mk and jw-py-test.mk. Testability is asserted by running "make", "make all" or "make test" from $(TOPDIR). A successful toplevel build coincides with testability, and leaves a $(TOPDIR)/dirs-all.done behind, which is why that file is the perfect testability marker. It is automatically created by a toplevel build and cleared by using the "invalidate-testability" prerequisite. This commit makes target "clean" depend on it in py-mod.mk. To be extended to other use cases / makefile snippets as needed. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
c471388fba
commit
1c39215b39
4 changed files with 28 additions and 3 deletions
21
make/test-guard.mk
Normal file
21
make/test-guard.mk
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Testability guard
|
||||
#
|
||||
# Tree testability is a single top-level property tracked by
|
||||
# $(TOPDIR)/dirs-all.done: created by a full `make all` from the topdir,
|
||||
# removed by `make clean`. A per-dir `make test` only makes sense when the tree
|
||||
# is importable, i.e. testable. So `test` requires testability, and a `make
|
||||
# clean` that drops artifacts crucial for testing (a Python module's
|
||||
# __init__.py, ...) invalidates it.
|
||||
|
||||
.PHONY: testability invalidate-testability
|
||||
|
||||
TEST_GUARD = $(TOPDIR)/dirs-all.done
|
||||
|
||||
all:
|
||||
|
||||
testability:
|
||||
@test -f "$(TEST_GUARD)" || \
|
||||
{ echo 'Error: Tree not testable -- run "make all" (or "make test") from the project\'s root to fix' >&2; exit 1; }
|
||||
|
||||
invalidate-testability:
|
||||
$(RM) -f "$(TEST_GUARD)"
|
||||
Loading…
Reference in a new issue