git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 04/10] t/chainlint: add chainlint "whitespace" test cases

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 11, 2018, 06:46 UTC
Message-ID
<20180711064642.6933-5-sunshine@sunshineco.com>
In-Reply-To
<20180711064642.6933-1-sunshine@sunshineco.com>

The --chain-lint option uses heuristics and knowledge of shell syntax to detect broken &&-chains in subshells by pure textual inspection. The heuristics handle a range of stylistic variations in existing tests (evolved over the years), however, they are still best-guesses. As such, it is possible for future changes to accidentally break assumptions upon which the heuristics are based. Protect against this possibility by adding tests which check the linter itself for correctness.

In addition to protecting against regressions, these tests help document (for humans) expected behavior, which is important since the linter's implementation language ('sed') does not necessarily lend itself to easy comprehension.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 t/chainlint/blank-line.expect        |  4 ++++
 t/chainlint/blank-line.test          | 10 ++++++++++
 t/chainlint/comment.expect           |  4 ++++
 t/chainlint/comment.test             | 11 +++++++++++
 t/chainlint/here-doc.expect          |  3 +++
 t/chainlint/here-doc.test            | 16 ++++++++++++++++
 t/chainlint/incomplete-line.expect   |  4 ++++
 t/chainlint/incomplete-line.test     | 12 ++++++++++++
 t/chainlint/inline-comment.expect    |  9 +++++++++
 t/chainlint/inline-comment.test      | 12 ++++++++++++
 t/chainlint/subshell-here-doc.expect |  5 +++++
 t/chainlint/subshell-here-doc.test   | 23 +++++++++++++++++++++++
 12 files changed, 113 insertions(+)
 create mode 100644 t/chainlint/blank-line.expect
 create mode 100644 t/chainlint/blank-line.test
 create mode 100644 t/chainlint/comment.expect
 create mode 100644 t/chainlint/comment.test
 create mode 100644 t/chainlint/here-doc.expect
 create mode 100644 t/chainlint/here-doc.test
 create mode 100644 t/chainlint/incomplete-line.expect
 create mode 100644 t/chainlint/incomplete-line.test
 create mode 100644 t/chainlint/inline-comment.expect
 create mode 100644 t/chainlint/inline-comment.test
 create mode 100644 t/chainlint/subshell-here-doc.expect
 create mode 100644 t/chainlint/subshell-here-doc.test
diff --git a/t/chainlint/blank-line.expect b/t/chainlint/blank-line.expect
new file mode 100644
index 0000000000..3be939ed38
--- /dev/null
+++ b/t/chainlint/blank-line.expect
@@ -0,0 +1,4 @@
+(
+	nothing &&
+	something
+>)
diff --git a/t/chainlint/blank-line.test b/t/chainlint/blank-line.test
new file mode 100644
index 0000000000..f6dd14302b
--- /dev/null
+++ b/t/chainlint/blank-line.test
@@ -0,0 +1,10 @@
+(
+
+	nothing &&
+
+	something
+# LINT: swallow blank lines since final _statement_ before subshell end is
+# LINT: significant to "&&"-check, not final _line_ (which might be blank)
+
+
+)
diff --git a/t/chainlint/comment.expect b/t/chainlint/comment.expect
new file mode 100644
index 0000000000..3be939ed38
--- /dev/null
+++ b/t/chainlint/comment.expect
@@ -0,0 +1,4 @@
+(
+	nothing &&
+	something
+>)
diff --git a/t/chainlint/comment.test b/t/chainlint/comment.test
new file mode 100644
index 0000000000..113c0c466f
--- /dev/null
+++ b/t/chainlint/comment.test
@@ -0,0 +1,11 @@
+(
+# LINT: swallow comment lines
+	# comment 1
+	nothing &&
+	# comment 2
+	something
+# LINT: swallow comment lines since final _statement_ before subshell end is
+# LINT: significant to "&&"-check, not final _line_ (which might be comment)
+	# comment 3
+	# comment 4
+)
diff --git a/t/chainlint/here-doc.expect b/t/chainlint/here-doc.expect
new file mode 100644
index 0000000000..2328fe7753
--- /dev/null
+++ b/t/chainlint/here-doc.expect
@@ -0,0 +1,3 @@
+boodle wobba        gorgo snoot        wafta snurb &&
+
+horticulture
diff --git a/t/chainlint/here-doc.test b/t/chainlint/here-doc.test
new file mode 100644
index 0000000000..bd36f6e1d3
--- /dev/null
+++ b/t/chainlint/here-doc.test
@@ -0,0 +1,16 @@
+# LINT: stitch together incomplete \-ending lines
+# LINT: swallow here-doc to avoid false positives in content
+boodle wobba \
+       gorgo snoot \
+       wafta snurb <<EOF &&
+quoth the raven,
+nevermore...
+EOF
+
+# LINT: swallow here-doc (EOF is last line of test)
+horticulture <<\EOF
+gomez
+morticia
+wednesday
+pugsly
+EOF
diff --git a/t/chainlint/incomplete-line.expect b/t/chainlint/incomplete-line.expect
new file mode 100644
index 0000000000..2f3ebabdc2
--- /dev/null
+++ b/t/chainlint/incomplete-line.expect
@@ -0,0 +1,4 @@
+line 1 line 2 line 3 line 4 &&
+(
+	line 5 	line 6 	line 7 	line 8
+>)
diff --git a/t/chainlint/incomplete-line.test b/t/chainlint/incomplete-line.test
new file mode 100644
index 0000000000..d856658083
--- /dev/null
+++ b/t/chainlint/incomplete-line.test
@@ -0,0 +1,12 @@
+# LINT: stitch together all incomplete \-ending lines
+line 1 \
+line 2 \
+line 3 \
+line 4 &&
+(
+# LINT: stitch together all incomplete \-ending lines (subshell)
+	line 5 \
+	line 6 \
+	line 7 \
+	line 8
+)
diff --git a/t/chainlint/inline-comment.expect b/t/chainlint/inline-comment.expect
new file mode 100644
index 0000000000..fc9f250ac4
--- /dev/null
+++ b/t/chainlint/inline-comment.expect
@@ -0,0 +1,9 @@
+(
+	foobar &&
+?!AMP?!	barfoo
+	flibble "not a # comment"
+>) &&
+
+(
+cd foo &&
+>	flibble "not a # comment")
diff --git a/t/chainlint/inline-comment.test b/t/chainlint/inline-comment.test
new file mode 100644
index 0000000000..8f26856e77
--- /dev/null
+++ b/t/chainlint/inline-comment.test
@@ -0,0 +1,12 @@
+(
+# LINT: swallow inline comment (leaving command intact)
+	foobar && # comment 1
+# LINT: mispositioned "&&" (correctly) swallowed with comment
+	barfoo # wrong position for &&
+# LINT: "#" in string not misinterpreted as comment
+	flibble "not a # comment"
+) &&
+
+# LINT: "#" in string in cuddled subshell not misinterpreted as comment
+(cd foo &&
+	flibble "not a # comment")
diff --git a/t/chainlint/subshell-here-doc.expect b/t/chainlint/subshell-here-doc.expect
new file mode 100644
index 0000000000..19d5aff233
--- /dev/null
+++ b/t/chainlint/subshell-here-doc.expect
@@ -0,0 +1,5 @@
+(
+	echo wobba 	       gorgo snoot 	       wafta snurb &&
+?!AMP?!	cat >bip
+	echo >bop
+>)
diff --git a/t/chainlint/subshell-here-doc.test b/t/chainlint/subshell-here-doc.test
new file mode 100644
index 0000000000..9c3564c247
--- /dev/null
+++ b/t/chainlint/subshell-here-doc.test
@@ -0,0 +1,23 @@
+(
+# LINT: stitch together incomplete \-ending lines
+# LINT: swallow here-doc to avoid false positives in content
+	echo wobba \
+	       gorgo snoot \
+	       wafta snurb <<-EOF &&
+	quoth the raven,
+	nevermore...
+	EOF
+
+# LINT: missing "&&" on 'cat'
+	cat <<EOF >bip
+	fish fly high
+	EOF
+
+# LINT: swallow here-doc (EOF is last line of subshell)
+	echo <<-\EOF >bop
+	gomez
+	morticia
+	wednesday
+	pugsly
+	EOF
+)
-- 
2.18.0.203.gfac676dfb9
Previous: Eric SunshineNext: Eric Sunshine
Message 69 of 123 in “t: detect and fix broken &&-chains in subshells”
  1. 00/29 t: detect and fix broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  2. 01/29 t7508: use test_when_finished() instead of managing exit code manuallyEric Sunshine, Jun 26, 2018
  3. 03/29 t1300: use sane_unset() to avoid breaking &&-chainEric Sunshine, Jun 26, 2018
  4. 02/29 t0001: use "{...}" block around "||" expression rather than subshellEric Sunshine, Jun 26, 2018
  5. 04/29 t3303: use standard here-doc tag "EOF" to avoid fooling --chain-lintEric Sunshine, Jun 26, 2018
  6. 09/29 t7810: use test_expect_code() instead of hand-rolled comparisonEric Sunshine, Jun 26, 2018
  7. 12/29 t9401: drop unnecessary nested subshellEric Sunshine, Jun 26, 2018
  8. 15/29 t: drop unnecessary terminating semicolons in subshellEric Sunshine, Jun 26, 2018
  9. 14/29 t: drop subshell with missing &&-chain in favor of simpler constructEric Sunshine, Jun 26, 2018
  10. Junio C HamanoJun 26, 2018
  11. Eric SunshineJun 26, 2018
  12. 20/29 t2000-t2999: fix broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  13. 18/29 t0000-t0999: fix broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  14. 24/29 t5000-t5999: fix broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  15. 28/29 t9119: fix broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  16. 29/29 t/test-lib: teach --chain-lint to detect broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  17. Junio C HamanoJun 26, 2018
  18. Eric SunshineJun 26, 2018
  19. Jeff KingJun 26, 2018
  20. Jeff KingJun 26, 2018
  21. Eric SunshineJun 26, 2018
  22. Elijah NewrenJun 26, 2018
  23. Eric SunshineJun 26, 2018
  24. Eric SunshineJun 26, 2018
  25. Jeff KingJun 26, 2018
  26. Eric SunshineJun 26, 2018
  27. Jeff KingJun 28, 2018
  28. Elijah NewrenJun 27, 2018
  29. Johannes SixtJun 27, 2018
  30. Eric SunshineJun 27, 2018
  31. Jeff KingJun 28, 2018
  32. Junio C HamanoJun 26, 2018
  33. 27/29 t9000-t9999: fix broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  34. 26/29 t7000-t7999: fix broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  35. 25/29 t6000-t6999: fix broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  36. 19/29 t1000-t1999: fix broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  37. 22/29 t3030: fix broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  38. 23/29 t4000-t4999: fix broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  39. 21/29 t3000-t3999: fix broken &&-chains in subshellsEric Sunshine, Jun 26, 2018
  40. 13/29 t/lib-submodule-update: fix broken "replace submodule must-fail" testEric Sunshine, Jun 26, 2018
  41. t/lib-submodule-update: fix absorbing testStefan Beller, Jun 27, 2018
  42. Eric SunshineJun 27, 2018
  43. 16/29 t: use test_might_fail() instead of manipulating exit code manuallyEric Sunshine, Jun 26, 2018
  44. 17/29 t: use test_must_fail() instead of checking exit code manuallyEric Sunshine, Jun 26, 2018
  45. Luke DiamandJun 26, 2018
  46. Elijah NewrenJun 26, 2018
  47. Eric SunshineJun 26, 2018
  48. Johannes SixtJun 26, 2018
  49. Eric SunshineJun 26, 2018
  50. Johannes SixtJun 26, 2018
  51. 07/29 t7201: drop pointless "exit 0" at end of subshellEric Sunshine, Jun 26, 2018
  52. 08/29 t7400: fix broken "submodule add/reconfigure --force" testEric Sunshine, Jun 26, 2018
  53. Stefan BellerJun 27, 2018
  54. 10/29 t9001: fix broken "invoke hook" testEric Sunshine, Jun 26, 2018
  55. Jonathan TanJun 26, 2018
  56. 11/29 t9104: use "{...}" block around "||" expression rather than subshellEric Sunshine, Jun 26, 2018
  57. 06/29 t6036: fix broken "merge fails but has appropriate contents" testsEric Sunshine, Jun 26, 2018
  58. Elijah NewrenJun 26, 2018
  59. 05/29 t5505: modernize and simplify hard-to-digest testEric Sunshine, Jun 26, 2018
  60. Elijah NewrenJun 26, 2018
  61. Eric SunshineJun 26, 2018
  62. Elijah NewrenJun 26, 2018
  63. Junio C HamanoJun 26, 2018
  64. Eric SunshineJun 26, 2018
  65. Junio C HamanoJun 26, 2018
  66. Jonathan NiederJun 27, 2018
  67. 00/10 detect broken &&-chains in subshellsEric Sunshine, Jul 11, 2018
  68. 03/10 t/chainlint: add chainlint "basic" test casesEric Sunshine, Jul 11, 2018
  69. 04/10 t/chainlint: add chainlint "whitespace" test casesEric Sunshine, Jul 11, 2018
  70. 05/10 t/chainlint: add chainlint "one-liner" test casesEric Sunshine, Jul 11, 2018
  71. 06/10 t/chainlint: add chainlint "nested subshell" test casesEric Sunshine, Jul 11, 2018
  72. 01/10 t/test-lib: teach --chain-lint to detect broken &&-chains in subshellsEric Sunshine, Jul 11, 2018
  73. Junio C HamanoJul 11, 2018
  74. Eric SunshineJul 12, 2018
  75. Jeff KingJul 12, 2018
  76. Eric SunshineJul 12, 2018
  77. Junio C HamanoJul 12, 2018
  78. Jonathan NiederJul 30, 2018
  79. 0/2 subtree: fix &&-chain and simplify tests (Re: [PATCH v2 01/10] t/test-lib: teach --chain-lint to detect broken &&-chains in subshells)Jonathan Nieder, Jul 30, 2018
  80. 1/2 subtree test: add missing && to &&-chainJonathan Nieder, Jul 30, 2018
  81. 2/2 subtree test: simplify preparation of expected resultsJonathan Nieder, Jul 30, 2018
  82. Eric SunshineJul 30, 2018
  83. Jonathan NiederJul 30, 2018
  84. Eric SunshineJul 30, 2018
  85. Jeff KingJul 31, 2018
  86. Eric SunshineJul 31, 2018
  87. Jeff KingJul 31, 2018
  88. Ævar Arnfjörð BjarmasonAug 23, 2018
  89. Eric SunshineAug 23, 2018
  90. 09/10 t/chainlint: add chainlint "complex" test casesEric Sunshine, Jul 11, 2018
  91. 07/10 t/chainlint: add chainlint "loop" and "conditional" test casesEric Sunshine, Jul 11, 2018
  92. 08/10 t/chainlint: add chainlint "cuddled" test casesEric Sunshine, Jul 11, 2018
  93. 10/10 t/chainlint: add chainlint "specialized" test casesEric Sunshine, Jul 11, 2018
  94. 02/10 t/Makefile: add machinery to check correctness of chainlint.sedEric Sunshine, Jul 11, 2018
  95. 0/5 chainlint: improve robustness against "unusual" shell codingEric Sunshine, Aug 7, 2018
  96. 1/5 chainlint: match arbitrary here-docs tags rather than hard-coded namesEric Sunshine, Aug 7, 2018
  97. Jeff KingAug 8, 2018
  98. Eric SunshineAug 9, 2018
  99. Jeff KingAug 9, 2018
  100. 2/5 chainlint: recognize multi-line $(...) when command cuddled with "$("Eric Sunshine, Aug 7, 2018
  101. 3/5 chainlint: let here-doc and multi-line string commence on same lineEric Sunshine, Aug 7, 2018
  102. 4/5 chainlint: recognize multi-line quoted strings more robustlyEric Sunshine, Aug 7, 2018
  103. 5/5 chainlint: add test of pathological case which triggered false positiveEric Sunshine, Aug 7, 2018
  104. Jeff KingAug 8, 2018
  105. Junio C HamanoAug 9, 2018
  106. 0/6 chainlint: improve robustness against "unusual" shell codingEric Sunshine, Aug 13, 2018
  107. 1/6 chainlint: match arbitrary here-docs tags rather than hard-coded namesEric Sunshine, Aug 13, 2018
  108. 2/6 chainlint: match 'quoted' here-doc tagsEric Sunshine, Aug 13, 2018
  109. Junio C HamanoAug 13, 2018
  110. Eric SunshineAug 13, 2018
  111. 3/6 chainlint: recognize multi-line $(...) when command cuddled with "$("Eric Sunshine, Aug 13, 2018
  112. 4/6 chainlint: let here-doc and multi-line string commence on same lineEric Sunshine, Aug 13, 2018
  113. 5/6 chainlint: recognize multi-line quoted strings more robustlyEric Sunshine, Aug 13, 2018
  114. 6/6 chainlint: add test of pathological case which triggered false positiveEric Sunshine, Aug 13, 2018
  115. 0/6 chainlint: improve robustness against "unusual" shell codingEric Sunshine, Aug 15, 2018
  116. 1/6 chainlint: match arbitrary here-docs tags rather than hard-coded namesEric Sunshine, Aug 15, 2018
  117. 3/6 chainlint: recognize multi-line $(...) when command cuddled with "$("Eric Sunshine, Aug 15, 2018
  118. 4/6 chainlint: let here-doc and multi-line string commence on same lineEric Sunshine, Aug 15, 2018
  119. 5/6 chainlint: recognize multi-line quoted strings more robustlyEric Sunshine, Aug 15, 2018
  120. 6/6 chainlint: add test of pathological case which triggered false positiveEric Sunshine, Aug 15, 2018
  121. 2/6 chainlint: match quoted here-doc tagsEric Sunshine, Aug 15, 2018
  122. chainlint: match "quoted" here-doc tagsEric Sunshine, Aug 29, 2018
  123. Junio C HamanoAug 29, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.