t/Makefile: add machinery to check correctness of chainlint.sed

The --chain-lint option uses heuristics and knowledge of shell syntax to detect broken &&-chains in subshells by pure textual inspection. Although the heuristics work well, they are still best-guesses and future changes could accidentally break assumptions upon which they are based. To protect against this possibility, tests checking correctness of the linter itself will be added. As preparation, add a new makefile "check-chainlint" target and associated machinery. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jul 11, 2018 at 02:46 UTC 803394459d40f8d07cef11d49900ba6f72887869
2 files changed +22 -4
t/.gitignore
+1
@@ -1,3 +1,4 @@
1 /trash directory*
2 /test-results
3 /.prove
4 +/chainlinttmp
t/Makefile
+21 -4
@@ -18,8 +18,10 @@ TEST_LINT ?= test-lint
18
19 ifdef TEST_OUTPUT_DIRECTORY
20 TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results
21 +CHAINLINTTMP = $(TEST_OUTPUT_DIRECTORY)/chainlinttmp
22 else
23 TEST_RESULTS_DIRECTORY = test-results
24 +CHAINLINTTMP = chainlinttmp
25 endif
26
27 # Shell quote;
@@ -27,14 +29,17 @@ SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
29 TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
30 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
31 TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
32 +CHAINLINTTMP_SQ = $(subst ','\'',$(CHAINLINTTMP))
33
34 T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
35 TGITWEB = $(sort $(wildcard t95[0-9][0-9]-*.sh))
36 THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh)))
37 +CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test)))
38 +CHAINLINT = sed -f chainlint.sed
39
40 all: $(DEFAULT_TEST_TARGET)
41
37 -test: pre-clean $(TEST_LINT)
42 +test: pre-clean check-chainlint $(TEST_LINT)
43 $(MAKE) aggregate-results-and-cleanup
44
45 failed:
@@ -43,7 +48,7 @@ failed:
48 sed -n 's/\.counts$$/.sh/p') && \
49 test -z "$$failed" || $(MAKE) $$failed
50
46 -prove: pre-clean $(TEST_LINT)
51 +prove: pre-clean check-chainlint $(TEST_LINT)
52 @echo "*** prove ***"; $(PROVE) --exec '$(TEST_SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
53 $(MAKE) clean-except-prove-cache
54
@@ -53,13 +58,25 @@ $(T):
58 pre-clean:
59 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
60
56 -clean-except-prove-cache:
61 +clean-except-prove-cache: clean-chainlint
62 $(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)'
63 $(RM) -r valgrind/bin
64
65 clean: clean-except-prove-cache
66 $(RM) .prove
67
68 +clean-chainlint:
69 + $(RM) -r '$(CHAINLINTTMP_SQ)'
70 +
71 +check-chainlint:
72 + @mkdir -p '$(CHAINLINTTMP_SQ)' && \
73 + err=0 && \
74 + for i in $(CHAINLINTTESTS); do \
75 + $(CHAINLINT) <chainlint/$$i.test | \
76 + sed -e '/^# LINT: /d' >'$(CHAINLINTTMP_SQ)'/$$i.actual && \
77 + diff -u chainlint/$$i.expect '$(CHAINLINTTMP_SQ)'/$$i.actual || err=1; \
78 + done && exit $$err
79 +
80 test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
81 test-lint-filenames
82
@@ -102,4 +119,4 @@ valgrind:
119 perf:
120 $(MAKE) -C perf/ all
121
105 -.PHONY: pre-clean $(T) aggregate-results clean valgrind perf
122 +.PHONY: pre-clean $(T) aggregate-results clean valgrind perf check-chainlint clean-chainlint