chainlint.pl: add test_expect_success call to test snippets
The chainlint tests are a series of individual files, each holding a
test body. The "make check-chainlint" target assembles them into a
single file, adding a "test_expect_success" function call around each.
Let's instead include that function call in the files themselves. This
is a little more boilerplate, but has several advantages:
1. You can now run chainlint manually on snippets with just "perl
chainlint.perl chainlint/foo.test". This can make developing and
debugging a little easier.
2. Many of the tests implicitly relied on the syntax of the lines
added by the Makefile (in particular the use of single-quotes).
This assumption is much easier to see when the single-quotes are
alongside the test body.
3. We had no way to test how the chainlint program handled
various test_expect_success lines themselves. Now we'll be able to
check variations.
The change to the .test files was done mechanically, using the same
test names they would have been assigned by the Makefile (this is
important to match the expected output). The Makefile has the minimal
change to drop the extra lines; there are more cleanups possible but a
future patch in this series will rewrite this substantially anyway.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committedJul 10, 2024 at 04:34 UTCa5e450144dbc85b5cd7b0e01c6aa7fd30f117ee2
73 files changed+145-3
t/Makefile
+1-3
index b2eb9f770b..e7a476966e 100644--- a/t/Makefile+++ b/t/Makefile@@ -109,9 +109,7 @@ clean-chainlint: check-chainlint: @mkdir -p '$(CHAINLINTTMP_SQ)' && \ for i in $(CHAINLINTTESTS); do \- echo "test_expect_success '$$i' '" && \- sed -e '/^# LINT: /d' chainlint/$$i.test && \- echo "'"; \+ sed -e '/^# LINT: /d' chainlint/$$i.test; \ done >'$(CHAINLINTTMP_SQ)'/tests && \ { \ echo "# chainlint: $(CHAINLINTTMP_SQ)/tests" && \
t/chainlint/arithmetic-expansion.test
+2
index 16206960d8..7b4c5c9a41 100644--- a/t/chainlint/arithmetic-expansion.test+++ b/t/chainlint/arithmetic-expansion.test@@ -1,3 +1,4 @@+test_expect_success 'arithmetic-expansion' ' ( foo && # LINT: closing ")" of $((...)) not misinterpreted as subshell-closing ")"@@ -9,3 +10,4 @@ bar=$((42 + 1)) baz )+'
t/chainlint/bash-array.test
+2
index 92bbb777b8..4ca977d299 100644--- a/t/chainlint/bash-array.test+++ b/t/chainlint/bash-array.test@@ -1,3 +1,4 @@+test_expect_success 'bash-array' ' ( foo && # LINT: ")" in Bash array assignment not misinterpreted as subshell-closing ")"@@ -10,3 +11,4 @@ bar=${#bar[@]} && baz )+'
t/chainlint/blank-line-before-esac.test
+2
index cecccad19f..51f02ea0c5 100644--- a/t/chainlint/blank-line-before-esac.test+++ b/t/chainlint/blank-line-before-esac.test@@ -1,3 +1,4 @@+test_expect_success 'blank-line-before-esac' ' # LINT: blank line before "esac" test_done () { case "$test_failure" in@@ -17,3 +18,4 @@ test_done () { esac }+'
index 86f81ece63..71ef1d0b7f 100644--- a/t/chainlint/chained-block.test+++ b/t/chainlint/chained-block.test@@ -1,3 +1,4 @@+test_expect_success 'chained-block' ' # LINT: start of block chained to preceding command echo nobody home && { test the doohicky@@ -9,3 +10,4 @@ GIT_EXTERNAL_DIFF=echo git diff | { read path oldfile oldhex oldmode newfile newhex newmode && test "z$oh" = "z$oldhex" }+'
t/chainlint/chained-subshell.test
+2
index 4ff6ddd8cb..1f11f65398 100644--- a/t/chainlint/chained-subshell.test+++ b/t/chainlint/chained-subshell.test@@ -1,3 +1,4 @@+test_expect_success 'chained-subshell' ' # LINT: start of subshell chained to preceding command mkdir sub && ( cd sub &&@@ -11,3 +12,4 @@ test -f $s1 test $(cat $s2) = tree2path1 && # LINT: closing subshell ")" correctly detected on same line as "$(...)" test $(cat $s3) = tree3path1)+'
index 5efeda58b2..f98ae4c42d 100644--- a/t/chainlint/complex-if-in-cuddled-loop.test+++ b/t/chainlint/complex-if-in-cuddled-loop.test@@ -1,3 +1,4 @@+test_expect_success 'complex-if-in-cuddled-loop' ' # LINT: "for" loop cuddled with "(" and ")" and nested "if" with complex # LINT: multi-line condition; indented with spaces, not tabs (for i in a b c; do@@ -9,3 +10,4 @@ fi done) && test ! -f file+'
t/chainlint/cuddled-if-then-else.test
+2
index 7c53f4efe3..b1b42e1aac 100644--- a/t/chainlint/cuddled-if-then-else.test+++ b/t/chainlint/cuddled-if-then-else.test@@ -1,3 +1,4 @@+test_expect_success 'cuddled-if-then-else' ' # LINT: "if" cuddled with "(" and ")"; indented with spaces, not tabs (if test -z ""; then echo empty@@ -5,3 +6,4 @@ echo bizzy fi) && echo foobar+'
t/chainlint/cuddled-loop.test
+2
index 3c2a62f751..6fccb6ac22 100644--- a/t/chainlint/cuddled-loop.test+++ b/t/chainlint/cuddled-loop.test@@ -1,3 +1,4 @@+test_expect_success 'cuddled-loop' ' # LINT: "while" loop cuddled with "(" and ")", with embedded (allowed) # LINT: "|| exit {n}" to exit loop early, and using redirection "<" to feed # LINT: loop; indented with spaces, not tabs@@ -5,3 +6,4 @@ do foobar bop || exit 1 done <file ) && outside subshell+'
t/chainlint/cuddled.test
+2
index 257b5b5eed..5a6ef7a4a6 100644--- a/t/chainlint/cuddled.test+++ b/t/chainlint/cuddled.test@@ -1,3 +1,4 @@+test_expect_success 'cuddled' ' # LINT: first subshell statement cuddled with opening "(" (cd foo && bar@@ -20,3 +21,4 @@ # LINT: same with missing "&&" (cd foo bar)+'
t/chainlint/double-here-doc.test
+2
index cd584a4357..1b69b7a651 100644--- a/t/chainlint/double-here-doc.test+++ b/t/chainlint/double-here-doc.test@@ -1,3 +1,4 @@+test_expect_success 'double-here-doc' ' run_sub_test_lib_test_err run-inv-range-start \ "--run invalid range start" \ --run="a-5" <<-\EOF &&@@ -10,3 +11,4 @@ check_sub_test_lib_test_err run-inv-range-start \ EOF_OUT > error: --run: invalid non-numeric in range start: ${SQ}a-5${SQ} EOF_ERR+'
t/chainlint/dqstring-line-splice.test
+2
index b40714439f..f6aa637be8 100644--- a/t/chainlint/dqstring-line-splice.test+++ b/t/chainlint/dqstring-line-splice.test@@ -1,3 +1,4 @@+test_expect_success 'dqstring-line-splice' ' # LINT: line-splice within DQ-string '" echo 'fatal: reword option of --fixup is mutually exclusive with'\@@ -5,3 +6,4 @@ echo 'fatal: reword option of --fixup is mutually exclusive with'\ test_must_fail git commit --fixup=reword:HEAD~ $1 2>actual && test_cmp expect actual "'+'
t/chainlint/dqstring-no-interpolate.test
+2
index d2f4219cbb..7ae079b558 100644--- a/t/chainlint/dqstring-no-interpolate.test+++ b/t/chainlint/dqstring-no-interpolate.test@@ -1,3 +1,4 @@+test_expect_success 'dqstring-no-interpolate' ' # LINT: regex dollar-sign eol anchor in double-quoted string not special grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" out &&@@ -13,3 +14,4 @@ grep "^\\.git\$" output.txt && cut -d ' ' -f 2 <output | sort >actual && test_cmp expect actual "'+'
index 323595b5bd..796de21b7c 100644--- a/t/chainlint/exclamation.test+++ b/t/chainlint/exclamation.test@@ -1,3 +1,4 @@+test_expect_success 'exclamation' ' # LINT: "! word" is two tokens if ! condition; then echo nope; else yep; fi && # LINT: "!word" is single token, not two tokens "!" and "word"@@ -6,3 +7,4 @@ test_prerequisite !MINGW && mail uucp!address && # LINT: "!word!" is single token, not three tokens "!", "word", and "!" echo !whatever!+'
t/chainlint/exit-loop.test
+2
index 2f038207e1..7e8b68b465 100644--- a/t/chainlint/exit-loop.test+++ b/t/chainlint/exit-loop.test@@ -1,3 +1,4 @@+test_expect_success 'exit-loop' ' ( for i in a b c do@@ -25,3 +26,4 @@ i=$(($i + 1)) done )+'
t/chainlint/exit-subshell.test
+2
index 4e6ab69b88..05dff55cd7 100644--- a/t/chainlint/exit-subshell.test+++ b/t/chainlint/exit-subshell.test@@ -1,6 +1,8 @@+test_expect_success 'exit-subshell' ' ( # LINT: "|| exit {n}" valid subshell escape without hurting &&-chain foo || exit 1 bar && baz )+'
t/chainlint/for-loop-abbreviated.test
+2
index 1084eccb89..1dd14f2a44 100644--- a/t/chainlint/for-loop-abbreviated.test+++ b/t/chainlint/for-loop-abbreviated.test@@ -1,6 +1,8 @@+test_expect_success 'for-loop-abbreviated' ' # LINT: for-loop lacking optional "in [word...]" before "do" for it do path=$(expr "$it" : '\([^:]*\)') && git update-index --add "$path" || exit done+'
t/chainlint/for-loop.test
+2
index 6cb3428158..6f2489eb19 100644--- a/t/chainlint/for-loop.test+++ b/t/chainlint/for-loop.test@@ -1,3 +1,4 @@+test_expect_success 'for-loop' ' ( # LINT: "for", "do", "done" do not need "&&" for i in a b c@@ -17,3 +18,4 @@ cat $i done )+'
t/chainlint/function.test
+2
index 5ee59562c9..763fcf3f87 100644--- a/t/chainlint/function.test+++ b/t/chainlint/function.test@@ -1,3 +1,4 @@+test_expect_success 'function' ' # LINT: "()" in function definition not mistaken for subshell sha1_file() { echo "$*" | sed "s#..#.git/objects/&/#"@@ -11,3 +12,4 @@ remove_object() { } sha1_file arg && remove_object arg+'
t/chainlint/here-doc-close-subshell.test
+2
index b857ff5467..2458f3323b 100644--- a/t/chainlint/here-doc-close-subshell.test+++ b/t/chainlint/here-doc-close-subshell.test@@ -1,5 +1,7 @@+test_expect_success 'here-doc-close-subshell' ' ( # LINT: line contains here-doc and closes nested subshell cat <<-\INPUT) fizz INPUT+'
t/chainlint/here-doc-indent-operator.test
+2
index c8a6f18eb4..a2656f47c1 100644--- a/t/chainlint/here-doc-indent-operator.test+++ b/t/chainlint/here-doc-indent-operator.test@@ -1,3 +1,4 @@+test_expect_success 'here-doc-indent-operator' ' # LINT: whitespace between operator "<<-" and tag legal cat >expect <<- EOF && header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0@@ -11,3 +12,4 @@ this is not indented -EOF cleanup+'
index 3f5f92cad3..c91b695319 100644--- a/t/chainlint/here-doc.test+++ b/t/chainlint/here-doc.test@@ -1,3 +1,4 @@+test_expect_success 'here-doc' ' # LINT: stitch together incomplete \-ending lines # LINT: swallow here-doc to avoid false positives in content boodle wobba \@@ -28,3 +29,4 @@ morticia wednesday pugsly EOF+'
t/chainlint/if-condition-split.test
+2
index 240daa9fd5..9a3b3ed04a 100644--- a/t/chainlint/if-condition-split.test+++ b/t/chainlint/if-condition-split.test@@ -1,3 +1,4 @@+test_expect_success 'if-condition-split' ' # LINT: "if" condition split across multiple lines at "&&" or "||" if bob && marcia ||@@ -6,3 +7,4 @@ then echo "nomads" echo "for sure" fi+'
t/chainlint/if-in-loop.test
+2
index 90c23976fe..5be9d1cfa5 100644--- a/t/chainlint/if-in-loop.test+++ b/t/chainlint/if-in-loop.test@@ -1,3 +1,4 @@+test_expect_success 'if-in-loop' ' ( for i in a b c do@@ -13,3 +14,4 @@ done bar )+'
t/chainlint/if-then-else.test
+2
index 2055336c2b..6582a7f440 100644--- a/t/chainlint/if-then-else.test+++ b/t/chainlint/if-then-else.test@@ -1,3 +1,4 @@+test_expect_success 'if-then-else' ' ( # LINT: "if", "then", "elif", "else", "fi" do not need "&&" if test -n ""@@ -27,3 +28,4 @@ echo empty fi )+'
t/chainlint/incomplete-line.test
+2
index d856658083..74a93021eb 100644--- a/t/chainlint/incomplete-line.test+++ b/t/chainlint/incomplete-line.test@@ -1,3 +1,4 @@+test_expect_success 'incomplete-line' ' # LINT: stitch together all incomplete \-ending lines line 1 \ line 2 \@@ -10,3 +11,4 @@ line 4 && line 7 \ line 8 )+'
t/chainlint/inline-comment.test
+2
index 8f26856e77..4fbbf1058a 100644--- a/t/chainlint/inline-comment.test+++ b/t/chainlint/inline-comment.test@@ -1,3 +1,4 @@+test_expect_success 'inline-comment' ' ( # LINT: swallow inline comment (leaving command intact) foobar && # comment 1@@ -10,3 +11,4 @@ # LINT: "#" in string in cuddled subshell not misinterpreted as comment (cd foo && flibble "not a # comment")+'
t/chainlint/loop-detect-failure.test
+2
index b9791cc802..44673aa394 100644--- a/t/chainlint/loop-detect-failure.test+++ b/t/chainlint/loop-detect-failure.test@@ -1,3 +1,4 @@+test_expect_success 'loop-detect-failure' ' git init r1 && # LINT: loop handles failure explicitly with "|| return 1" for n in 1 2 3 4 5@@ -15,3 +16,4 @@ do git -C r2 add large.$n && git -C r2 commit -m "$n" done+'
t/chainlint/loop-detect-status.test
+2
index 1c6c23cfc9..8b639be073 100644--- a/t/chainlint/loop-detect-status.test+++ b/t/chainlint/loop-detect-status.test@@ -1,3 +1,4 @@+test_expect_success 'loop-detect-status' ' # LINT: "$?" handled explicitly within loop body (while test $i -le $blobcount do@@ -17,3 +18,4 @@ cat commit) | git fast-import --big-file-threshold=2 && test ! -f exit-status+'
t/chainlint/loop-in-if.test
+2
index dfcc3f98fb..b0d0d393cf 100644--- a/t/chainlint/loop-in-if.test+++ b/t/chainlint/loop-in-if.test@@ -1,3 +1,4 @@+test_expect_success 'loop-in-if' ' ( if true then@@ -13,3 +14,4 @@ fi bar )+'
index b4610ce815..590914b733 100644--- a/t/chainlint/token-pasting.test+++ b/t/chainlint/token-pasting.test@@ -1,3 +1,4 @@+test_expect_success 'token-pasting' ' # LINT: single token; composite of multiple strings git config filter.rot13.smudge ./rot13.sh && git config filter.rot13.clean ./rot13.sh &&@@ -30,3 +31,4 @@ downstream_url_for_sed=$( # LINT: exit/enter string context; "&" inside string not command terminator sed -e '\''s/\\/\\\\/g'\'' -e '\''s/[[/.*^$]/\\&/g'\'' )+'
t/chainlint/unclosed-here-doc-indent.test
+2
index 5c841a9dfd..7ac9d0f7d7 100644--- a/t/chainlint/unclosed-here-doc-indent.test+++ b/t/chainlint/unclosed-here-doc-indent.test@@ -1,4 +1,6 @@+test_expect_success 'unclosed-here-doc-indent' ' command_which_is_run && cat >expect <<-\EOF && we forget to end the here-doc command_which_is_gobbled+'
t/chainlint/unclosed-here-doc.test
+2
index 69d3786c34..68e78f06f3 100644--- a/t/chainlint/unclosed-here-doc.test+++ b/t/chainlint/unclosed-here-doc.test@@ -1,3 +1,4 @@+test_expect_success 'unclosed-here-doc' ' command_which_is_run && cat >expect <<\EOF && we try to end the here-doc below,@@ -5,3 +6,4 @@ cat >expect <<\EOF && since the operator is not "<<-". EOF command_which_is_gobbled+'
t/chainlint/while-loop.test
+2
index d09fb016e4..33a201906a 100644--- a/t/chainlint/while-loop.test+++ b/t/chainlint/while-loop.test@@ -1,3 +1,4 @@+test_expect_success 'while-loop' ' ( # LINT: "while", "do", "done" do not need "&&" while true@@ -17,3 +18,4 @@ cat bar done )+'