# [PATCH] tests: add some script lint checks

2 messages from 2010-04-12 to 2010-04-12. Participants: Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/23425

## Jeff King, 2010-04-12 06:52

Subject: [PATCH] tests: add some script lint checks
Message-ID: <20100412065234.GA12462@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20100412065234.GA12462%40coredump.intra.peff.net

```
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>
---
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

```

## Junio C Hamano, 2010-04-12 07:41

Subject: Re: [PATCH] tests: add some script lint checks
Message-ID: <7vochpm81y.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vochpm81y.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20100412065234.GA12462@coredump.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> 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.

Thanks.  They are caught by pre-applypatch from 'todo' these days.  I
should also perhaps check for the executable bit there.

```
