Skip to content

Commit d38732c

Browse files
peffgitster
authored andcommitted
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>
1 parent 0d6504c commit d38732c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

t/Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ TGITWEB = $(wildcard t95[0-9][0-9]-*.sh)
2323

2424
all: $(DEFAULT_TEST_TARGET)
2525

26-
test: pre-clean
26+
test: pre-clean $(TEST_LINT)
2727
$(MAKE) aggregate-results-and-cleanup
2828

29-
prove: pre-clean
29+
prove: pre-clean $(TEST_LINT)
3030
@echo "*** prove ***"; GIT_CONFIG=.git/config $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
3131
$(MAKE) clean
3232

@@ -41,6 +41,18 @@ clean:
4141
$(RM) -r valgrind/bin
4242
$(RM) .prove
4343

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+
4456
aggregate-results-and-cleanup: $(T)
4557
$(MAKE) aggregate-results
4658
$(MAKE) clean

0 commit comments

Comments
 (0)