Skip to content

Commit 0c7d630

Browse files
peffgitster
authored andcommitted
chainlint.pl: add tests for test body in heredoc
The chainlint.pl script recently learned about the upcoming: test_expect_success 'some test' - <<\EOT TEST_BODY EOT syntax, where TEST_BODY should be checked in the usual way. Let's make sure this works by adding a few tests. The "here-doc-body" file tests the basic syntax, including an embedded here-doc which we should still be able to recognize. Likewise the "here-doc-body-indent" checks the same thing, but using the "<<-" operator. We wouldn't expect this to be used normally, but we would not want to accidentally miss a body that uses it. The "pathological" variant checks the opposite: we don't get confused by an indented tag within the here-doc body. The "here-doc-double" tests the handling of two here-doc tags on the same line. This is not something we'd expect anybody to do in practice, but the code was written defensively to handle this, so let's make sure it works. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a4a5f28 commit 0c7d630

8 files changed

+50
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2 echo "we should find this" ?!AMP?!
2+
3 echo "even though our heredoc has its indent stripped"

t/chainlint/here-doc-body-indent.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test_expect_success 'here-doc-body-indent' - <<-\EOT
2+
echo "we should find this"
3+
echo "even though our heredoc has its indent stripped"
4+
EOT
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2 echo "outer here-doc does not allow indented end-tag" ?!AMP?!
2+
3 cat >file <<-\EOF &&
3+
4 but this inner here-doc
4+
5 does allow indented EOF
5+
6 EOF
6+
7 echo "missing chain after" ?!AMP?!
7+
8 echo "but this line is OK because it's the end"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
test_expect_success 'here-doc-body-pathological' - <<\EOF
2+
echo "outer here-doc does not allow indented end-tag"
3+
cat >file <<-\EOF &&
4+
but this inner here-doc
5+
does allow indented EOF
6+
EOF
7+
echo "missing chain after"
8+
echo "but this line is OK because it's the end"
9+
EOF

t/chainlint/here-doc-body.expect

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2 echo "missing chain before" ?!AMP?!
2+
3 cat >file <<-\EOF &&
3+
4 inside inner here-doc
4+
5 these are not shell commands
5+
6 EOF
6+
7 echo "missing chain after" ?!AMP?!
7+
8 echo "but this line is OK because it's the end"

t/chainlint/here-doc-body.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
test_expect_success 'here-doc-body' - <<\EOT
2+
echo "missing chain before"
3+
cat >file <<-\EOF &&
4+
inside inner here-doc
5+
these are not shell commands
6+
EOF
7+
echo "missing chain after"
8+
echo "but this line is OK because it's the end"
9+
EOT

t/chainlint/here-doc-double.expect

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
8 echo "actual test commands" ?!AMP?!
2+
9 echo "that should be checked"

t/chainlint/here-doc-double.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This is obviously a ridiculous thing to do, but we should be able
2+
# to handle two here-docs on the same line, and attribute them
3+
# correctly.
4+
test_expect_success "$(cat <<END_OF_PREREQS)" 'here-doc-double' - <<\EOT
5+
SOME
6+
PREREQS
7+
END_OF_PREREQS
8+
echo "actual test commands"
9+
echo "that should be checked"
10+
EOT

0 commit comments

Comments
 (0)