Skip to content

Commit 8033944

Browse files
sunshinecogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 878f988 commit 8033944

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

t/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/trash directory*
22
/test-results
33
/.prove
4+
/chainlinttmp

t/Makefile

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,28 @@ TEST_LINT ?= test-lint
1818

1919
ifdef TEST_OUTPUT_DIRECTORY
2020
TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results
21+
CHAINLINTTMP = $(TEST_OUTPUT_DIRECTORY)/chainlinttmp
2122
else
2223
TEST_RESULTS_DIRECTORY = test-results
24+
CHAINLINTTMP = chainlinttmp
2325
endif
2426

2527
# Shell quote;
2628
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
2729
TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
2830
PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
2931
TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
32+
CHAINLINTTMP_SQ = $(subst ','\'',$(CHAINLINTTMP))
3033

3134
T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
3235
TGITWEB = $(sort $(wildcard t95[0-9][0-9]-*.sh))
3336
THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh)))
37+
CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test)))
38+
CHAINLINT = sed -f chainlint.sed
3439

3540
all: $(DEFAULT_TEST_TARGET)
3641

37-
test: pre-clean $(TEST_LINT)
42+
test: pre-clean check-chainlint $(TEST_LINT)
3843
$(MAKE) aggregate-results-and-cleanup
3944

4045
failed:
@@ -43,7 +48,7 @@ failed:
4348
sed -n 's/\.counts$$/.sh/p') && \
4449
test -z "$$failed" || $(MAKE) $$failed
4550

46-
prove: pre-clean $(TEST_LINT)
51+
prove: pre-clean check-chainlint $(TEST_LINT)
4752
@echo "*** prove ***"; $(PROVE) --exec '$(TEST_SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
4853
$(MAKE) clean-except-prove-cache
4954

@@ -53,13 +58,25 @@ $(T):
5358
pre-clean:
5459
$(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
5560

56-
clean-except-prove-cache:
61+
clean-except-prove-cache: clean-chainlint
5762
$(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)'
5863
$(RM) -r valgrind/bin
5964

6065
clean: clean-except-prove-cache
6166
$(RM) .prove
6267

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+
6380
test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
6481
test-lint-filenames
6582

@@ -102,4 +119,4 @@ valgrind:
102119
perf:
103120
$(MAKE) -C perf/ all
104121

105-
.PHONY: pre-clean $(T) aggregate-results clean valgrind perf
122+
.PHONY: pre-clean $(T) aggregate-results clean valgrind perf check-chainlint clean-chainlint

0 commit comments

Comments
 (0)