@matheusbsbs / matheus-bagliano / commits / d38732c28c
Fork 0

tests: add some script lint checks

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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Dec 13, 2010 at 12:22 UTC d38732c28cb43387d6d66f72bbc6fd91f3d0b516
1 file changed +14 -2
t/Makefile
+14 -2
@@ -23,10 +23,10 @@ TGITWEB = $(wildcard t95[0-9][0-9]-*.sh)
23
24 all: $(DEFAULT_TEST_TARGET)
25
26 -test: pre-clean
26 +test: pre-clean $(TEST_LINT)
27 $(MAKE) aggregate-results-and-cleanup
28
29 -prove: pre-clean
29 +prove: pre-clean $(TEST_LINT)
30 @echo "*** prove ***"; GIT_CONFIG=.git/config $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
31 $(MAKE) clean
32
@@ -41,6 +41,18 @@ clean:
41 $(RM) -r valgrind/bin
42 $(RM) .prove
43
44 +test-lint: test-lint-duplicates test-lint-executable
45 +
46 +test-lint-duplicates:
47 + @dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
48 + test -z "$$dups" || { \
49 + echo >&2 "duplicate test numbers:" $$dups; exit 1; }
50 +
51 +test-lint-executable:
52 + @bad=`for i in $(T); do test -x "$$i" || echo $$i; done` && \
53 + test -z "$$bad" || { \
54 + echo >&2 "non-executable tests:" $$bad; exit 1; }
55 +
56 aggregate-results-and-cleanup: $(T)
57 $(MAKE) aggregate-results
58 $(MAKE) clean