[PATCH] tests: add some script lint checks
From: Jeff King <hidden>
Date: 2016-06-15 22:48:36
Subsystem:
the rest · Maintainer:
Linus Torvalds
There are some common but minor errors we tend to make in
writing test scripts:
1. Scripts are left non-executable. This is not usually
noticed immediately because "make test" does not need
the bit, but it is a matter of git policy to make them
executable (and is a slight convenience when running
individual scripts).
2. Two scripts are allocated the same number. Usually this
happens on separate branches, and the problem only
comes about during a merge. But since there is no
textual conflict, the merger would have to be very
observant to notice.
This is also a minor error, but can make GIT_SKIP_TESTS
ambiguous.
This patch introduces a "test-lint" target which checks
both. It is not invoked by default. You can invoke it as
"make test-lint", or you can make it a prerequisite of
running the tests by specifying "TEST_LINT = test-lint" in
your config.mak or on the command line.
Signed-off-by: Jeff King <redacted>
---
The dup half is based on Johannes' earlier patch.
Obviously this can help submitters avoid dumb mistakes, so I plan to
turn it on for myself. As maintainer, Junio, you might want to run at
least with TEST_LINT = test-lint-duplicate, since you can then catch
duplicates introduced by merges and fix them up as part of the merge.
t/Makefile | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/t/Makefile b/t/Makefile
index 25c559b..40ae67c 100644
--- a/t/Makefile
+++ b/t/Makefile@@ -16,7 +16,7 @@ SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) TSVN = $(wildcard t91[0-9][0-9]-*.sh) -all: pre-clean +all: pre-clean $(TEST_LINT) $(MAKE) aggregate-results-and-cleanup $(T):
@@ -30,6 +30,18 @@ clean: $(RM) t????/cvsroot/CVSROOT/?* $(RM) -r valgrind/bin +test-lint: test-lint-duplicates test-lint-executable + +test-lint-duplicates: + @dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \ + test -z "$$dups" || { \ + echo >&2 "duplicate test numbers:" $$dups; exit 1; } + +test-lint-executable: + @bad=`for i in $(T); do test -x "$$i" || echo $$i; done` && \ + test -z "$$bad" || { \ + echo >&2 "non-executable tests:" $$bad; exit 1; } + aggregate-results-and-cleanup: $(T) $(MAKE) aggregate-results $(MAKE) clean
--
1.7.1.rc1.245.g808fe