here-doc test bodies
cover here-doc test bodies
This is a re-post of an idea from 2021:
https://lore.kernel.org/git/[email protected]/
that people seemed mostly positive on, and I just never got around to following up. Mostly because it's not life-changing, but I think it is a small quality of life improvement, and it came up again recently in:
https://lore.kernel.org/git/[email protected]/
So I thought it was worth considering again.
[1/2]: test-lib: allow test snippets as here-docs [2/2]: t: convert some here-doc test bodies
t/README | 8 ++ t/t0600-reffiles-backend.sh | 38 +++---- t/t1404-update-ref-errors.sh | 196 +++++++++++++++++------------------ t/test-lib-functions.sh | 32 +++++- 4 files changed, 152 insertions(+), 122 deletions(-)
-Peff
PATCH 1/2 test-lib: allow test snippets as here-docs
Most test snippets are wrapped in single quotes, like:
test_expect_success 'some description' '
do_something
'
This sometimes makes the snippets awkward to write, because you can't easily use single quotes within them. We sometimes work around this with $SQ, or by loosening regexes to use "." instead of a literal quote, or by using double quotes when we'd prefer to use single-quotes (and just adding extra backslash-escapes to avoid interpolation).
This commit adds another option: feeding the snippet via the function's stdin. This doesn't conflict with anything the snippet would want to do, because we always redirect its stdin from /dev/null anyway (which we'll continue to do).
A few notes on the implementation:
- it would be nice to push this down into test_run_, but we can't, as test_expect_success and test_expect_failure want to see the actual script content to report it for verbose-mode. A helper function limits the amount of duplication in those callers here.
- The helper function is a little awkward to call, as you feed it the name of the variable you want to set. The more natural thing in shell would be command substitution like:
body=$(body_or_stdin "$2")
but that loses trailing whitespace. There are tricks around this, like:
body=$(body_or_stdin "$2"; printf .)
body=${body%.}
but we'd prefer to keep such tricks in the helper, not in each caller.
- I implemented the helper using a sequence of "read" calls. Together with "-r" and unsetting the IFS, this preserves incoming whitespace. An alternative is to use "cat" (which then requires the gross "." trick above). But this saves us a process, which is probably a good thing. The "read" builtin does use more read() syscalls than necessary (one per byte), but that is almost certainly a win over a separate process.
Both are probably slower than passing a single-quoted string, but the difference is lost in the noise for a script that I converted as an experiment.
- I handle test_expect_success and test_expect_failure here. If we like this style, we could easily extend it to other spots (e.g., lazy_prereq bodies) on top of this patch.
- even though we are using "local", we have to be careful about our variable names. Within test_expect_success, any variable we declare with local will be seen as local by the test snippets themselves (so it wouldn't persist between tests like normal variables would).
--- t/README | 8 ++++++++ t/test-lib-functions.sh | 32 +++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-)
t/README +8 -0
@@ -906,6 +906,14 @@ see test-lib-functions.sh for the full list and their options. 'git-write-tree should be able to write an empty tree.' \ 'tree=$(git-write-tree)' + If <script> is `-` (a single dash), then the script to run is read + from stdin. This lets you more easily use single quotes within the + script by using a here-doc. For example: + + test_expect_success 'output contains expected string' - <<\EOT + grep "this string has 'quotes' in it" output + EOT + If you supply three parameters the first will be taken to be a prerequisite; see the test_set_prereq and test_have_prereq documentation below:
t/test-lib-functions.sh +27 -5
@@ -872,6 +872,24 @@ test_verify_prereq () { BUG "'$test_prereq' does not look like a prereq" } +# assign the variable named by "$1" with the contents of "$2"; +# if "$2" is "-", then read stdin into "$1" instead +test_body_or_stdin () { + if test "$2" != "-" + then + eval "$1=\$2" + return + fi + + # start with a newline, to match hanging newline from open-quote style + eval "$1=\$LF" + local test_line + while IFS= read -r test_line + do + eval "$1=\${$1}\${test_line}\${LF}" + done +} + test_expect_failure () { test_start_ "$@" test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
@@ -881,9 +899,11 @@ test_expect_failure () { export test_prereq if ! test_skip "$@" then + local test_body + test_body_or_stdin test_body "$2" test -n "$test_skip_test_preamble" || - say >&3 "checking known breakage of $TEST_NUMBER.$test_count '$1': $2" - if test_run_ "$2" expecting_failure + say >&3 "checking known breakage of $TEST_NUMBER.$test_count '$1': $test_body" + if test_run_ "$test_body" expecting_failure then test_known_broken_ok_ "$1" else
@@ -902,13 +922,15 @@ test_expect_success () { export test_prereq if ! test_skip "$@" then + local test_body + test_body_or_stdin test_body "$2" test -n "$test_skip_test_preamble" || - say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $2" - if test_run_ "$2" + say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $test_body" + if test_run_ "$test_body" then test_ok_ "$1" else - test_failure_ "$@" + test_failure_ "$1" "$test_body" fi fi test_finish_
Signature · 1 line
2.45.2.1165.ga18b536d12
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
Quoted 10 lines · Jeff King
[...]
This commit adds another option: feeding the snippet via the function's stdin. This doesn't conflict with anything the snippet would want to do, because we always redirect its stdin from/dev/nullanyway (which we'll continue to do).Signed-off-by Jeff King <[email protected]>---
t/README see test-lib-functions.sh for the full list and their options. · line 912
Quoted 7 lines
t/README +7
-0@@ -906,6 +906,14 @@ see test-lib-functions.sh for the full list and their options. + If <script> is `-` (a single dash), then the script to run is read + from stdin. This lets you more easily use single quotes within the + script by using a here-doc. For example: + + test_expect_success 'output contains expected string' - <<\EOT + grep "this string has 'quotes' in it" output + EOT
We lose chainlint functionality for test bodies specified in this manner.
Restoring such functionality will require some (possibly) not-so-subtle changes. There are at least a couple issues which need to be addressed:
(1) chainlint.pl:ScriptParser::parse_cmd() only currently recognizes test_expect_* [prereq] 'title' 'body' but will now also need to recognize test_expect_success [prereq] 'title' - <body-as-here-doc>.
(2) Until now, chainlint.pl has never had to concern itself with the body of a here-doc; it just throws them away. With this new calling convention, here-doc bodies become relevant and must be returned by the lexer. This may involve some not-so-minor surgery.
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
Quoted 1 line · Eric Sunshine
We lose
chainlintfunctionality for test bodies specified in this manner.
Ouch.
Quoted 12 lines
Restoring such functionality will require some (possibly) not-so-subtle changes. There are at least a couple issues which need to be addressed:
(1) chainlint.pl:ScriptParser::parse_cmd() only currently recognizes
test_expect_* [prereq] 'title' 'body'but will now also need to recognizetest_expect_success [prereq] 'title' - <body-as-here-doc>.(2) Until now, chainlint.pl has never had to concern itself with the body of a here-doc; it just throws them away. With this new calling convention, here-doc bodies become relevant and must be returned by the lexer. This may involve some not-so-minor surgery.
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
In reply to Eric SunshineQuoted 15 lines · Eric Sunshine
Review see test-lib-functions.sh for the full list and their options. · line 912
Quoted 8 lines
(quoted diff) +7
-0@@ -906,6 +906,14 @@ see test-lib-functions.sh for the full list and their options. + If <script> is `-` (a single dash), then the script to run is read + from stdin. This lets you more easily use single quotes within the + script by using a here-doc. For example: + + test_expect_success 'output contains expected string' - <<\EOT + grep "this string has 'quotes' in it" output + EOTWe lose
chainlintfunctionality for test bodies specified in this manner.Restoring such functionality will require some (possibly) not-so-subtle changes. There are at least a couple issues which need to be addressed:
Quoted 8 lines
(1) chainlint.pl:ScriptParser::parse_cmd() only currently recognizes
test_expect_* [prereq] 'title' 'body'but will now also need to recognizetest_expect_success [prereq] 'title' - <body-as-here-doc>.(2) Until now, chainlint.pl has never had to concern itself with the body of a here-doc; it just throws them away. With this new calling convention, here-doc bodies become relevant and must be returned by the lexer. This may involve some not-so-minor surgery.
Hmm. The patch below seems to work on a simple test.
The lexer stuffs the heredoc into a special variable. Which at first glance feels like a hack versus returning it from the token stream, but the contents really _aren't_ part of that stream. They're a separate magic thing that is found on the stdin of whatever command the tokens represent.
And then ScriptParser::parse_cmd() just has to recognize that any "<<" token isn't interesting, and that "-" means "read the here-doc".
Obviously we'd want to add to the chainlint tests here. It looks like the current test infrastructure is focused on evaluating snippets, with the test_expect_success part already handled.
t/chainlint.pl +7 -1
@@ -168,12 +168,15 @@ sub swallow_heredocs { my $self = shift @_; my $b = $self->{buff}; my $tags = $self->{heretags}; + $self->{parser}->{heredoc} = ''; while (my $tag = shift @$tags) { my $start = pos($$b); my $indent = $$tag[0] =~ s/^\t// ? '\\s*' : ''; $$b =~ /(?:\G|\n)$indent\Q$$tag[0]\E(?:\n|\z)/gc; if (pos($$b) > $start) { my $body = substr($$b, $start, pos($$b) - $start); + $self->{parser}->{heredoc} .= + substr($body, 0, length($body) - length($&)); $self->{lineno} += () = $body =~ /\n/sg; next; }
@@ -618,6 +621,9 @@ sub check_test { my $self = shift @_; my ($title, $body) = map(unwrap, @_); $self->{ntests}++; + if ($body eq '-') { + $body = $self->{heredoc}; + } my $parser = TestParser->new(\$body); my @tokens = $parser->parse(); my $problems = $parser->{problems};
@@ -648,7 +654,7 @@ sub parse_cmd { my @tokens = $self->SUPER::parse_cmd(); return @tokens unless @tokens && $tokens[0]->[0] =~ /^test_expect_(?:success|failure)$/; my $n = $#tokens; - $n-- while $n >= 0 && $tokens[$n]->[0] =~ /^(?:[;&\n|]|&&|\|\|)$/; + $n-- while $n >= 0 && $tokens[$n]->[0] =~ /^(?:[;&\n|]|&&|\|\||<<[A-Za-z]+)$/; $self->check_test($tokens[1], $tokens[2]) if $n == 2; # title body $self->check_test($tokens[2], $tokens[3]) if $n > 2; # prereq title body return @tokens;
-Peff
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
Quoted 10 lines · Jeff King
Hmm. The patch below seems to work on a simple test.
The lexer stuffs the heredoc into a special variable. Which at first glance feels like a hack versus returning it from the token stream, but the contents really _aren't_ part of that stream. They're a separate magic thing that is found on the stdin of whatever command the tokens represent.
And then
ScriptParser::parse_cmd()just has to recognize that any "<<" token isn't interesting, and that "-" means "read the here-doc".
BTW, there's one non-obvious thing here about why this works. You'd think that:
test_expect_success 'foo' <<\EOT
cat <<-\EOF this is a here-doc EOF echo ok
EOT
wouldn't work, because the lexer only has a single here-doc store, and the inner one is going to overwrite the outer. But we don't lex the inner contents of the test snippet until we've processed the test_expect_success line, at which point we've copied it out.
So I dunno. It feels a bit hacky, but I think it's how you have to do it anyway.
t/chainlint.pl sub parse_cmd { · line 657
Quoted 6 lines
t/chainlint.pl +1
-1@@ -648,7 +654,7 @@ sub parse_cmd { my @tokens = $self->SUPER::parse_cmd(); return @tokens unless @tokens && $tokens[0]->[0] =~ /^test_expect_(?:success|failure)$/; my $n = $#tokens; - $n-- while $n >= 0 && $tokens[$n]->[0] =~ /^(?:[;&\n|]|&&|\|\|)$/; + $n-- while $n >= 0 && $tokens[$n]->[0] =~ /^(?:[;&\n|]|&&|\|\||<<[A-Za-z]+)$/;
One curiosity I noted is that the backslash of my "<<\EOT" seems to be eaten by the lexer (I guess because it doesn't know the special meaning of backslash here, and just does the usual "take the next char literally"). I think that is OK for our purposes here, though we might in the long run want to raise a linting error if you accidentally used an interpolating here-doc (it's not strictly wrong to do so, but I think we generally frown on it as a style thing).
-Peff
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
Quoted 14 lines · Jeff King
Quoted 2 lines · Jeff King
And then
ScriptParser::parse_cmd()just has to recognize that any "<<" token isn't interesting, and that "-" means "read the here-doc".BTW, there's one non-obvious thing here about why this works. You'd think that:
test_expect_success'foo' <<\EOT
cat <<-\EOF
this is a here-doc
EOF
echo ok
EOT
Quoted 7 lines
wouldn't work, because the lexer only has a single here-doc store, and the inner one is going to overwrite the outer. But we don't lex the inner contents of the test snippet until we've processed the
test_expect_successline, at which point we've copied it out.So I dunno. It feels a bit hacky, but I think it's how you have to do it anyway.
It wasn't non-obvious to me, but I suppose it's because I know the author, or I am the author, or something.
Quoted 7 lines
t/chainlint.pl sub parse_cmd { · line 657
Quoted 2 lines
t/chainlint.pl +1
-1- $n-- while $n >= 0 && $tokens[$n]->[0] =~ /^(?:[;&\n|]|&&|\|\|)$/; + $n-- while $n >= 0 && $tokens[$n]->[0] =~ /^(?:[;&\n|]|&&|\|\||<<[A-Za-z]+)$/;One curiosity I noted is that the backslash of my "<<\EOT" seems to be eaten by the lexer (I guess because it doesn't know the special meaning of backslash here, and just does the usual "take the next char literally").
That's not the reason. It actively strips the backslash because it knows that it doesn't care about it after this point and, more importantly, because it needs to extract the raw heredoc tag name (without the slash or other surrounding quotes) so that it can match upon that name (say, "EOF") to find the end of the heredoc body.
It's mostly an accident of implementation (and probably a throwback to chainlint.sed) that it strips the backslash early in Lexer::scan_heredoc_tag() even though it doesn't actually have to be stripped until Lexer::swallow_heredocs() needs to match the tag name to find the end of the heredoc body. Thus, in retrospect, the implementation could have retained the backslash (\EOF) or quotes ('EOF' or "EOF") and left it for swallow_heredocs() to strip them only when needed.
There's another weird throwback to chainlint.sed in Lexer::scan_heredoc_tag() where it transforms <<- into <<\t, which is potentially more than a little confusing, especially since it is (I believe) totally unnecessary in the context of chainlint.pl.
Quoted 4 lines
I think that is OK for our purposes here, though we might
in the long run want to raise a linting error if you accidentally used an interpolating here-doc (it's not strictly wrong to do so, but I think we generally frown on it as a style thing).
Such a linting warning would probably have to be context-sensitive so it only triggers for test_expect_* calls.
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
Quoted 15 lines · Eric Sunshine
Quoted 15 lines
BTW, there's one non-obvious thing here about why this works. You'd think that:
test_expect_success'foo' <<\EOT
cat <<-\EOF
this is a here-doc
EOF
echo ok
EOTwouldn't work, because the lexer only has a single here-doc store, and the inner one is going to overwrite the outer. But we don't lex the inner contents of the test snippet until we've processed the
test_expect_successline, at which point we've copied it out.
Quoted 5 lines
Quoted 2 lines
So I dunno. It feels a bit hacky, but I think it's how you have to do it anyway.
It wasn't non-obvious to me, but I suppose it's because I know the author, or I am the author, or something.
:) I had a brief moment of panic where I thought "wait, what I sent out is going to break in this case!" and then was surprised when it worked.
Quoted 14 lines
Quoted 7 lines
t/chainlint.pl sub parse_cmd { · line 657
Quoted 2 lines
t/chainlint.pl +1
-1- $n-- while $n >= 0 && $tokens[$n]->[0] =~ /^(?:[;&\n|]|&&|\|\|)$/; + $n-- while $n >= 0 && $tokens[$n]->[0] =~ /^(?:[;&\n|]|&&|\|\||<<[A-Za-z]+)$/;One curiosity I noted is that the backslash of my "<<\EOT" seems to be eaten by the lexer (I guess because it doesn't know the special meaning of backslash here, and just does the usual "take the next char literally").
That's not the reason. It actively strips the backslash because it knows that it doesn't care about it after this point and, more importantly, because it needs to extract the raw heredoc tag name (without the slash or other surrounding quotes) so that it can match upon that name (say, "EOF") to find the end of the heredoc body.
Quoted 8 lines
It's mostly an accident of implementation (and probably a throwback to chainlint.sed) that it strips the backslash early in
Lexer::scan_heredoc_tag()even though it doesn't actually have to be stripped untilLexer::swallow_heredocs()needs to match the tag name to find the end of the heredoc body. Thus, in retrospect, the implementation could have retained the backslash (\EOF) or quotes ('EOF'or"EOF") and left it forswallow_heredocs()to strip them only when needed.
OK. I think it does make things easier to normalize this a bit, so that ScriptParser::parse_cmd() doesn't have to worry about all of the various spellings. If we recorded a single bit for "this was quoted" alongside the heredoc contents, that would be plenty. But as I (erroneously) said elsewhere, we can worry about that later if we find something useful to do with it.
Quoted 4 lines
There's another weird throwback to chainlint.sed in
Lexer::scan_heredoc_tag()where it transforms<<-into<<\t, which is potentially more than a little confusing, especially since it is (I believe) totally unnecessary in the context of chainlint.pl.
Ah, I hadn't noticed that. Looks like we use it in swallow_heredocs() to read the tag data itself. But importantly the token stream still has the correct original in it, which we need to correctly match in ScriptParser::parse_cmd().
Quoted 7 lines
Quoted 4 lines
I think that is OK for our purposes here, though we might
in the long run want to raise a linting error if you accidentally used an interpolating here-doc (it's not strictly wrong to do so, but I think we generally frown on it as a style thing).Such a linting warning would probably have to be context-sensitive so it only triggers for test_expect_* calls.
Yes, definitely.
-Peff
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
In reply to Jeff KingQuoted 3 lines · Jeff King
Obviously we'd want to add to the chainlint tests here. It looks like the current test infrastructure is focused on evaluating snippets, with the
test_expect_successpart already handled.
So doing this (with the patch I showed earlier):
t/Makefile +10 -0
@@ -106,18 +106,28 @@ clean: clean-except-prove-cache clean-chainlint: $(RM) -r '$(CHAINLINTTMP_SQ)' +CHAINLINTTESTS_SRC = $(patsubst %,chainlint/%.test,$(CHAINLINTTESTS)) check-chainlint: @mkdir -p '$(CHAINLINTTMP_SQ)' && \ for i in $(CHAINLINTTESTS); do \ echo "test_expect_success '$$i' '" && \ sed -e '/^# LINT: /d' chainlint/$$i.test && \ echo "'"; \ done >'$(CHAINLINTTMP_SQ)'/tests && \ + for i in $$(grep -L "'" $(CHAINLINTTESTS_SRC)); do \ + echo "test_expect_success '$$i' - <<\\\\EOT" && \ + sed -e '/^# LINT: /d' $$i && \ + echo "EOT"; \ + done >>'$(CHAINLINTTMP_SQ)'/tests && \ { \ echo "# chainlint: $(CHAINLINTTMP_SQ)/tests" && \ for i in $(CHAINLINTTESTS); do \ echo "# chainlint: $$i" && \ cat chainlint/$$i.expect; \ + done && \ + for i in $$(grep -L "'" $(CHAINLINTTESTS_SRC)); do \ + echo "# chainlint: $$i" && \ + cat $${i%.test}.expect; \ done \ } >'$(CHAINLINTTMP_SQ)'/expect && \ $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests | \
does pass. It's just running all of the tests inside an "EOT" block. But we have to omit ones that have single quotes in them, because they are making the implicit assumption that they're inside a single-quoted block (so they do things like '"$foo"', or '\'', etc, which behave differently in a here-doc).
It was a nice check that the output is the same in both cases, but it's a bit limiting as a test suite, as there's no room to introduce test cases that vary the test_expect_success lines. I'm thinking the path forward may be:
1. Move the test_expect_success wrapping lines into each chainlint/*.test file. It's a little bit of extra boilerplate, but it makes them a bit easier to reason about on their own.
2. Add a few new tests that use here-docs with a few variations ("<<EOT", "<<\EOT", probably a here-doc inside the test here-doc).
Does that sound OK to you?
-Peff
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
Quoted 9 lines · Jeff King
Quoted 3 lines · Jeff King
Obviously we'd want to add to the chainlint tests here. It looks like the current test infrastructure is focused on evaluating snippets, with the
test_expect_successpart already handled.So doing this (with the patch I showed earlier):
t/Makefile clean: clean-except-prove-cache · line 110
Quoted 5 lines
t/Makefile +5
-0@@ -106,18 +106,28 @@ clean: clean-except-prove-cache + for i in $$(grep -L "'" $(CHAINLINTTESTS_SRC)); do \ + echo "test_expect_success '$$i' - <<\\\\EOT" && \ + sed -e '/^# LINT: /d' $$i && \ + echo "EOT"; \ + done >>'$(CHAINLINTTMP_SQ)'/tests && \
Unfortunately, grep -L is not POSIX.
Quoted 9 lines
does pass. It's just running all of the tests inside an "EOT" block. But we have to omit ones that have single quotes in them, because they are making the implicit assumption that they're inside a single-quoted block (so they do things like '"$foo"', or '\'', etc, which behave differently in a here-doc).
It was a nice check that the output is the same in both cases, but it's a bit limiting as a test suite, as there's no room to introduce test cases that vary the
test_expect_successlines.
Agreed. It feels rather hacky and awfully special-case, as it's only (additionally) checking that the test_expect_* title - <<EOT form works, but doesn't help at all with testing other parsing-related behaviors of chainlint.pl (which is something I definitely wanted to be able to do when implementing the Perl version).
Quoted 5 lines
I'm thinking the path forward may be:
1. Move the
test_expect_successwrapping lines into each chainlint/*.test file. It's a little bit of extra boilerplate, but it makes them a bit easier to reason about on their own.
Yes. This is exactly what I had in mind for moving forward. It's just a one-time noise-patch cost but gives us much more flexibility in terms of testing.
It also makes spot-testing the chainlint self-test files much simpler. We would be able to do this:
./chainlint.pl chainlint/block.test
rather than much more painful:
{ echo "test_expect_success foo '" && cat chainlint/block.test &&echo "'"; } >dummy && ./chainlint.pl dummy; rm dummy
or something similar.
Quoted 4 lines
2. Add a few new tests that use here-docs with a few variations ("<<EOT", "<<\EOT", probably a here-doc inside the test here-doc).
Does that sound OK to you?
Absolutely. I'm very much in favor of these changes.
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
Quoted 9 lines · Eric Sunshine
t/Makefile clean: clean-except-prove-cache · line 110
Quoted 7 lines
t/Makefile +5
-0@@ -106,18 +106,28 @@ clean: clean-except-prove-cache + for i in $$(grep -L "'" $(CHAINLINTTESTS_SRC)); do \ + echo "test_expect_success '$$i' - <<\\\\EOT" && \ + sed -e '/^# LINT: /d' $$i && \ + echo "EOT"; \ + done >>'$(CHAINLINTTMP_SQ)'/tests && \Unfortunately,
grep -Lis not POSIX.
Yeah, this was just for illustration. Even if it were portable, I don't think it's a good direction. :)
Quoted 11 lines
t/Makefile clean: clean-except-prove-cache · line 113
Quoted 3 lines
t/Makefile +0
-01. Move the test_expect_success wrapping lines into each chainlint/*.test file. It's a little bit of extra boilerplate, but it makes them a bit easier to reason about on their own.Yes. This is exactly what I had in mind for moving forward. It's just a one-time noise-patch cost but gives us much more flexibility in terms of testing.
It also makes spot-testing the chainlint self-test files much simpler. We would be able to do this:
Quoted 6 lines
./chainlint.pl chainlint/block.test
rather than much more painful:
{ echo "test_expect_success foo '" && cat chainlint/block.test &&echo "'"; } >dummy && ./chainlint.pl dummy; rm dummy
Oh, nice. Having just written new chainlint tests, this made checking them _way_ easier.
Quoted 6 lines
Quoted 4 lines
t/Makefile +0
-02. Add a few new tests that use here-docs with a few variations ("<<EOT", "<<\EOT", probably a here-doc inside the test here-doc).Does that sound OK to you?
Absolutely. I'm very much in favor of these changes.
Great! I have patches which I'll send out in a moment.
-Peff
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
In reply to Jeff KingQuoted 10 lines · Jeff King
Quoted 1 line · Eric Sunshine
We lose
chainlintfunctionality for test bodies specified in this manner.Hmm. The patch below seems to work on a simple test.
The lexer stuffs the heredoc into a special variable. Which at first glance feels like a hack versus returning it from the token stream, but the contents really _aren't_ part of that stream. They're a separate magic thing that is found on the stdin of whatever command the tokens represent.
I created a white-room fix for this issue, as well, before taking a look at your patch. The two implementations bear a strong similarity which suggests that we agree upon the basic approach.
My implementation, however, takes a more formal and paranoid stance. Rather than squirreling away only the most-recently-seen heredoc body, it stores each heredoc body along with the tag which introduced it. This makes it robust against cases when multiple heredocs are initiated on the same line (even within different parse contexts):
cat <<EOFA && x=$(cat <<EOFB &&
A body
EOFA
B body
EOFBOf course, that's not likely to come up in the context of test_expect_* calls, but I prefer the added robustness over the more lax approach.
Quoted 2 lines
And then
ScriptParser::parse_cmd()just has to recognize that any "<<" token isn't interesting, and that "-" means "read the here-doc".
In my implementation, the << token is "interesting" because the heredoc tag is attached to it, and the tag is needed to pluck the heredoc body from the set of saved bodies (since my implementation doesn't assume most-recently-seen body is the correct one).
Quoted 3 lines
Obviously we'd want to add to the chainlint tests here. It looks like the current test infrastructure is focused on evaluating snippets, with the
test_expect_successpart already handled.
Yes, the "snippet" approach is a throwback to the old chainlint.sed implementation when there wasn't any actual parsing going on. As you note, this unfortunately does not allow for testing parsing-related aspects of the implementation, which is a limitation I most definitely felt when chainlint.pl was implemented. It probably would be a good idea to update the infrastructure to allow for more broad testing but that doesn't need to be part of the changes being discussed here.
t/chainlint.pl sub swallow_heredocs { · line 172
Quoted 7 lines
t/chainlint.pl +2
-0@@ -168,12 +168,15 @@ sub swallow_heredocs { if (pos($$b) > $start) { my $body = substr($$b, $start, pos($$b) - $start); + $self->{parser}->{heredoc} .= + substr($body, 0, length($body) - length($&)); $self->{lineno} += () = $body =~ /\n/sg;
In my implementation, I use regex to strip off the ending tag before storing the heredoc body. When I later looked at your implementation, I noticed that you used substr() -- which seems preferable -- but discovered that it strips too much in some cases. For instance, in t0600, I saw that:
cat >expected <<-\EOF &&
HEAD
PSEUDO_WT_HEAD
refs/bisect/wt-random
refs/heads/main
refs/heads/wt-main
EOFwas getting stripped down to:
HEAD
PSEUDO_WT_HEAD
refs/bisect/wt-random
refs/heads/main
refs/heads/wt-ma{{missing-nl}}It wasn't immediately obvious why this was happening, though I didn't spend a lot of time trying to debug it.
Although I think my implementation is complete, I haven't submitted it yet because I discovered that the changes you made to t1404 are triggering false-positives:
# chainlint: t1404-update-ref-errors.sh
# chainlint: existing loose ref is a simple prefix of new
120 prefix=refs/1l &&
121 test_update_rejected a c e false b c/x d \
122 '$prefix/c' exists; ?!AMP?! cannot create '$prefix/c/x'Unfortunately, I ran out of time, thus haven't tracked down this problem yet. I also haven't tested your implementation yet to determine if this is due to a change I made or due to a deeper existing issue with chainlint.pl.
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
Quoted 10 lines · Eric Sunshine
t/chainlint.pl sub swallow_heredocs { · line 180
Quoted 4 lines · Jeff King
my $body = substr($$b, $start, pos($$b) - $start);t/chainlint.pl +2
-0+ $self->{parser}->{heredoc} .= + substr($body, 0, length($body) - length($&)); $self->{lineno} += () = $body =~ /\n/sg;In my implementation, I use regex to strip off the ending tag before storing the heredoc body. When I later looked at your implementation, I noticed that you used
substr()-- which seems preferable -- but discovered that it strips too much in some cases. [...]
Nevermind this part. I just looked again at the misbehaving code (which I had commented out but not deleted) and noticed that I botched the implementation in two distinct ways. With those botches removed, the substr() approach works just fine.
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
In reply to Eric SunshineQuoted 4 lines · Eric Sunshine
Although I think my implementation is complete, I haven't submitted it yet because I discovered that the changes you made to t1404 are triggering false-positives:
Quoted 8 lines
# chainlint: t1404-update-ref-errors.sh # chainlint: existing loose ref is a simple prefix of new 120 prefix=refs/1l && 121 test_update_rejected a c e false b c/x d \ 122 '$prefix/c' exists; ?!AMP?! cannot create '$prefix/c/x'Unfortunately, I ran out of time, thus haven't tracked down this problem yet.
This is also now fixed. It wasn't any deep problem, just a minor oversight.
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
In reply to Eric SunshineQuoted 16 lines · Eric Sunshine
I created a white-room fix for this issue, as well, before taking a look at your patch. The two implementations bear a strong similarity which suggests that we agree upon the basic approach.
My implementation, however, takes a more formal and paranoid stance. Rather than squirreling away only the most-recently-seen heredoc body, it stores each heredoc body along with the tag which introduced it. This makes it robust against cases when multiple heredocs are initiated on the same line (even within different parse contexts):
cat <<EOFA && x=$(cat <<EOFB && A body EOFA B body EOFB
Quoted 3 lines
Of course, that's not likely to come up in the context of test_expect_* calls, but I prefer the added robustness over the more lax approach.
Yes, that's so much better than what I wrote. I didn't engage my brain very much when I read the in-code comments about multiple tags on the same line, and I thought you meant:
cat <<FOO <<BAR
this is foo
FOO
this is bar
BAR
which is...weird. It does "work" in the sense that "FOO" is a here-doc that should be skipped past. But it is not doing anything useful; cat sees only "this is bar" on stdin. So even for this case, the appending behavior that my patch does would not make sense.
And of course for the actual useful thing, which you wrote above, appending is just nonsense. Recording and accessing by tag is the right thing.
Quoted 7 lines
Quoted 2 lines
And then
ScriptParser::parse_cmd()just has to recognize that any "<<" token isn't interesting, and that "-" means "read the here-doc".In my implementation, the
<<token is "interesting" because the heredoc tag is attached to it, and the tag is needed to pluck the heredoc body from the set of saved bodies (since my implementation doesn't assume most-recently-seen body is the correct one).
Ah, OK. So it would probably not be that big of a deal to record a single bit for "this heredoc is interpolated". But until we have anything useful to do with that information, let's not worry about it for now.
Quoted 5 lines
Quoted 5 lines
t/chainlint.pl +1
-0@@ -168,12 +168,15 @@ sub swallow_heredocs { if (pos($$b) > $start) { my $body = substr($$b, $start, pos($$b) - $start); + $self->{parser}->{heredoc} .=
Quoted 8 lines
t/chainlint.pl sub swallow_heredocs { · line 180
Quoted 2 lines
t/chainlint.pl +1
-0+ substr($body, 0, length($body) - length($&)); $self->{lineno} += () = $body =~ /\n/sg;In my implementation, I use regex to strip off the ending tag before storing the heredoc body. When I later looked at your implementation, I noticed that you used
substr()-- which seems preferable -- but discovered that it strips too much in some cases. For instance, in t0600, I saw that:
Yeah, I was afraid of trying another regex, just because there are optional bits (like indentation) that we'd have to account for. Since $& contains the match already, that's all taken care of by the existing regex. From your follow-up, it sounds like the substr() approach does work (*phew*).
-Peff
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
Quoted 8 lines · Jeff King
Quoted 7 lines
Quoted 2 lines
And then
ScriptParser::parse_cmd()just has to recognize that any "<<" token isn't interesting, and that "-" means "read the here-doc".In my implementation, the
<<token is "interesting" because the heredoc tag is attached to it, and the tag is needed to pluck the heredoc body from the set of saved bodies (since my implementation doesn't assume most-recently-seen body is the correct one).
Quoted 4 lines
Ah, OK. So it would probably not be that big of a deal to record a single bit for "this heredoc is interpolated". But until we have anything useful to do with that information, let's not worry about it for now.
Oh, oops. I attached this response to the wrong message (I read them all through before starting to respond). My response here was about the fact that "<<\EOT" does not record the "\" anywhere from the lexer.
But yes, for your implementation, we do need to recognize "<<\EOT", etc, to pull out "EOT".
-Peff
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
In reply to Jeff KingQuoted 27 lines · Jeff King
Quoted 12 lines · Eric Sunshine
My implementation, however, takes a more formal and paranoid stance. Rather than squirreling away only the most-recently-seen heredoc body, it stores each heredoc body along with the tag which introduced it. This makes it robust against cases when multiple heredocs are initiated on the same line (even within different parse contexts):
cat <<EOFA && x=$(cat <<EOFB && A body EOFA B body EOFBQuoted 3 lines
Of course, that's not likely to come up in the context of test_expect_* calls, but I prefer the added robustness over the more lax approach.
Yes, that's so much better than what I wrote. I didn't engage my brain very much when I read the in-code comments about multiple tags on the same line, and I thought you meant:
cat <<FOO <<BAR
this is foo
FOO
this is bar
BAR
Quoted 8 lines
which is...weird. It does "work" in the sense that "FOO" is a here-doc that should be skipped past. But it is not doing anything useful; cat sees only "this is bar" on stdin. So even for this case, the appending behavior that my patch does would not make sense.
And of course for the actual useful thing, which you wrote above, appending is just nonsense. Recording and accessing by tag is the right thing.
In retrospect, I think my claim is bogus in the context of ScriptParser::parse_cmd(). Specifically, ScriptParser::parse_cmd() calls its parent ShellParser::parse_cmd() to latch one command. ShellParser::parse_cmd() stops parsing as soon as it encounters a command terminator (i.e. ;, &&, ||, |, '&', '\n') and returns the command. Moreover, by definition, given the language specification, the lexer only consumes the heredocs upon encountering \n. Thus, if someone writes:
test_expect_success title - <<\EOT && whatever &&
...test body...
EOTthen ScriptParser::parse_cmd() will receive the command test_expect_success title - from ShellParser::parse_cmd() but the heredoc will not yet have been consumed by the lexer since it hasn't yet encountered the newline[1].
So, the above example simply can't work correctly given the way ScriptParser::parse_cmd() calls ScriptParser::check_test() as soon as it encounters a test_expect_success/failure invocation since it doesn't know if the heredocs have been latched at that point. To make it properly robust, rather than immediately calling check_test(), it would have to continue consuming commands, and saving the ones which match test_expect_success/failure invocation, until it finally hits a \n, and only then call check_test() with each command it saved. But that's probably overkill at this point considering that we never write code like the above, so the submitted patch[2] is probably good enough for now.
FOOTNOTES
[1] One might rightly ask that if ShellParser::parse_cmd() returns immediately upon seeing a command terminator (i.e. ;, &&, etc.), then how is it that even a simple:
test_expect_success title - <<\EOT &&
...test body...
EOTcan work correctly since the \n comes after the &&. The answer is that, as a special case, the very last thing ShellParser::parse_cmd() does is peek ahead to see if a \n follows the command terminator (assuming the terminator is not itself a \n). When the next token is indeed a \n, that peek operation causes the lexer to consume the heredocs.
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
Quoted 11 lines · Eric Sunshine
So, the above example simply can't work correctly given the way
ScriptParser::parse_cmd()callsScriptParser::check_test()as soon as it encounters atest_expect_success/failureinvocation since it doesn't know if the heredocs have been latched at that point. To make it properly robust, rather than immediately callingcheck_test(), it would have to continue consuming commands, and saving the ones which matchtest_expect_success/failureinvocation, until it finally hits a\n, and only then callcheck_test()with each command it saved. But that's probably overkill at this point considering that we never write code like the above, so the submitted patch[2] is probably good enough for now.
Of course, the more I think about it, the more I dislike relying upon what is effectively an accident of implementation; i.e. that in the typical case, the heredoc will already have been latched by the time ScriptParser::parse_cmd() has identified a test_expect_success command, due to the fact that ShellParser::parse_cmd() has that special case which peeks for \n immediately following some other command terminator. As such, fixing ScriptParser::parse_cmd() to only call check_test() once it is sure that a '\n' has been encountered is becoming more appealing, though it is of course a more invasive and fundamental change than the posted patch.
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
Quoted 13 lines · Eric Sunshine
Quoted 11 lines · Eric Sunshine
So, the above example simply can't work correctly given the way
ScriptParser::parse_cmd()callsScriptParser::check_test()as soon as it encounters atest_expect_success/failureinvocation since it doesn't know if the heredocs have been latched at that point. To make it properly robust, rather than immediately callingcheck_test(), it would have to continue consuming commands, and saving the ones which matchtest_expect_success/failureinvocation, until it finally hits a\n, and only then callcheck_test()with each command it saved. But that's probably overkill at this point considering that we never write code like the above, so the submitted patch[2] is probably good enough for now.
Quoted 10 lines
Of course, the more I think about it, the more I dislike relying upon what is effectively an accident of implementation; i.e. that in the typical case, the heredoc will already have been latched by the time
ScriptParser::parse_cmd()has identified atest_expect_successcommand, due to the fact thatShellParser::parse_cmd()has that special case which peeks for\nimmediately following some other command terminator. As such, fixingScriptParser::parse_cmd()to only callcheck_test()once it is sure that a '\n' has been encountered is becoming more appealing, though it is of course a more invasive and fundamental change than the posted patch.
Rats, I just agreed with your earlier email. ;) I am OK with the slightly hacky version we've posted (modulo the fixes I discussed elsewhere). But if you want to take a little time to explore the more robust fix, I am happy to review it.
-Peff
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
Quoted 12 lines · Jeff King
Quoted 10 lines · Eric Sunshine
Of course, the more I think about it, the more I dislike relying upon what is effectively an accident of implementation; i.e. that in the typical case, the heredoc will already have been latched by the time
ScriptParser::parse_cmd()has identified atest_expect_successcommand, due to the fact thatShellParser::parse_cmd()has that special case which peeks for\nimmediately following some other command terminator. As such, fixingScriptParser::parse_cmd()to only callcheck_test()once it is sure that a '\n' has been encountered is becoming more appealing, though it is of course a more invasive and fundamental change than the posted patch.
Quoted 4 lines
Rats, I just agreed with your earlier email. ;) I am OK with the slightly hacky version we've posted (modulo the fixes I discussed elsewhere). But if you want to take a little time to explore the more robust fix, I am happy to review it.
The primary reason I said "the more I dislike relying upon ... an accident of implementation" is that this limitation is not documented anywhere other than in this email thread. That said, I don't mind the posted version of the patch being picked up. The "correct" approach can always be implemented atop it at a later time.
Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
In reply to Eric SunshineQuoted 24 lines · Eric Sunshine
Quoted 5 lines
Quoted 5 lines
cat <<EOFA && x=$(cat <<EOFB && A body EOFA B body EOFB[...]
In retrospect, I think my claim is bogus in the context ofScriptParser::parse_cmd(). Specifically,ScriptParser::parse_cmd()calls its parentShellParser::parse_cmd()to latch one command.ShellParser::parse_cmd()stops parsing as soon as it encounters a command terminator (i.e.;,&&,||,|, '&', '\n') and returns the command. Moreover, by definition, given the language specification, the lexer only consumes the heredocs upon encountering\n. Thus, if someone writes:test_expect_success title - <<\EOT && whatever && ...test body... EOTthen
ScriptParser::parse_cmd()will receive the commandtest_expect_success title -fromShellParser::parse_cmd()but the heredoc will not yet have been consumed by the lexer since it hasn't yet encountered the newline[1].
Quoted 4 lines
So, the above example simply can't work correctly given the way
ScriptParser::parse_cmd()callsScriptParser::check_test()as soon as it encounters atest_expect_success/failureinvocation since it doesn't know if the heredocs have been latched at that point.
Ah, yeah, I think you're right. I had parsed your example in my mind as:
cat <<EOFA $(cat <<EOFB)
without an intervening "&&" (taking the second here-doc as an argument to the original command). Which _does_ work with your patch.
Quoted 7 lines
To make it properly robust, rather than immediately calling
check_test(), it would have to continue consuming commands, and saving the ones which matchtest_expect_success/failureinvocation, until it finally hits a\n, and only then callcheck_test()with each command it saved. But that's probably overkill at this point considering that we never write code like the above, so the submitted patch[2] is probably good enough for now.
Yep, I'd agree with all of that.
-Peff
PATCH 2/2 t: convert some here-doc test bodies
In reply to Jeff KingThe t1404 script checks a lot of output from Git which contains single quotes. Because the test snippets are themselves wrapped in the same single-quotes, we have to resort to using $SQ to match them. This is error-prone and makes the tests harder to read.
Instead, let's use the new here-doc feature added in the previous commit, which lets us write anything in the test body we want (except the here-doc end marker on a line by itself, of course).
Note that we do use "\" in our marker to avoid interpolation (which is the whole point). But we don't use "<<-", as we want to preserve whitespace in the snippet (and running with "-v" before and after shows that we produce the exact same output, except with the ugly $SQ references fixed).
I just converted every test here, even though only some of them use $SQ. But it would be equally correct to mix-and-match styles if we don't mind the inconsistency.
I've also converted a few tests in t0600 which were moved from t1404 (I had written this patch before they were moved, but it seemed worth porting over the changes rather than losing them).
--- t/t0600-reffiles-backend.sh | 38 +++---- t/t1404-update-ref-errors.sh | 196 +++++++++++++++++------------------ 2 files changed, 117 insertions(+), 117 deletions(-)
t/t0600-reffiles-backend.sh +19 -19
@@ -91,82 +91,82 @@ test_expect_success 'empty directory should not fool 1-arg delete' ' git update-ref --stdin ' -test_expect_success 'non-empty directory blocks create' ' +test_expect_success 'non-empty directory blocks create' - <<\EOT prefix=refs/ne-create && mkdir -p .git/$prefix/foo/bar && : >.git/$prefix/foo/bar/baz.lock && test_when_finished "rm -f .git/$prefix/foo/bar/baz.lock" && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/foo$SQ: there is a non-empty directory $SQ.git/$prefix/foo$SQ blocking reference $SQ$prefix/foo$SQ + fatal: cannot lock ref '$prefix/foo': there is a non-empty directory '.git/$prefix/foo' blocking reference '$prefix/foo' EOF printf "%s\n" "update $prefix/foo $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ + fatal: cannot lock ref '$prefix/foo': unable to resolve reference '$prefix/foo' EOF printf "%s\n" "update $prefix/foo $D $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err -' +EOT -test_expect_success 'broken reference blocks create' ' +test_expect_success 'broken reference blocks create' - <<\EOT prefix=refs/broken-create && mkdir -p .git/$prefix && echo "gobbledigook" >.git/$prefix/foo && test_when_finished "rm -f .git/$prefix/foo" && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken + fatal: cannot lock ref '$prefix/foo': unable to resolve reference '$prefix/foo': reference broken EOF printf "%s\n" "update $prefix/foo $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken + fatal: cannot lock ref '$prefix/foo': unable to resolve reference '$prefix/foo': reference broken EOF printf "%s\n" "update $prefix/foo $D $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err -' +EOT -test_expect_success 'non-empty directory blocks indirect create' ' +test_expect_success 'non-empty directory blocks indirect create' - <<\EOT prefix=refs/ne-indirect-create && git symbolic-ref $prefix/symref $prefix/foo && mkdir -p .git/$prefix/foo/bar && : >.git/$prefix/foo/bar/baz.lock && test_when_finished "rm -f .git/$prefix/foo/bar/baz.lock" && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/symref$SQ: there is a non-empty directory $SQ.git/$prefix/foo$SQ blocking reference $SQ$prefix/foo$SQ + fatal: cannot lock ref '$prefix/symref': there is a non-empty directory '.git/$prefix/foo' blocking reference '$prefix/foo' EOF printf "%s\n" "update $prefix/symref $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ + fatal: cannot lock ref '$prefix/symref': unable to resolve reference '$prefix/foo' EOF printf "%s\n" "update $prefix/symref $D $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err -' +EOT -test_expect_success 'broken reference blocks indirect create' ' +test_expect_success 'broken reference blocks indirect create' - <<\EOT prefix=refs/broken-indirect-create && git symbolic-ref $prefix/symref $prefix/foo && echo "gobbledigook" >.git/$prefix/foo && test_when_finished "rm -f .git/$prefix/foo" && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken + fatal: cannot lock ref '$prefix/symref': unable to resolve reference '$prefix/foo': reference broken EOF printf "%s\n" "update $prefix/symref $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken + fatal: cannot lock ref '$prefix/symref': unable to resolve reference '$prefix/foo': reference broken EOF printf "%s\n" "update $prefix/symref $D $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err -' +EOT test_expect_success 'no bogus intermediate values during delete' ' prefix=refs/slow-transaction &&
@@ -224,7 +224,7 @@ test_expect_success 'no bogus intermediate values during delete' ' test_must_fail git rev-parse --verify --quiet $prefix/foo ' -test_expect_success 'delete fails cleanly if packed-refs file is locked' ' +test_expect_success 'delete fails cleanly if packed-refs file is locked' - <<\EOT prefix=refs/locked-packed-refs && # Set up a reference with differing loose and packed versions: git update-ref $prefix/foo $C &&
@@ -236,9 +236,9 @@ test_expect_success 'delete fails cleanly if packed-refs file is locked' ' test_when_finished "rm -f .git/packed-refs.lock" && test_must_fail git update-ref -d $prefix/foo >out 2>err && git for-each-ref $prefix >actual && - test_grep "Unable to create $SQ.*packed-refs.lock$SQ: " err && + test_grep "Unable to create '.*packed-refs.lock': " err && test_cmp unchanged actual -' +EOT test_expect_success 'delete fails cleanly if packed-refs.new write fails' ' # Setup and expectations are similar to the test above.
t/t1404-update-ref-errors.sh +98 -98
395 lines not on this page · raw message
Signature · 1 line
2.45.2.1165.ga18b536d12
PATCH 1/1 chainlint.pl: recognize test bodies defined via heredoc
In reply to Jeff KingFrom: Eric Sunshine <[email protected]>
In order to check tests for semantic problems, chainlint.pl scans test scripts, looking for tests defined as:
test_expect_success [prereq] title '
body
'
where body is a single string which is then treated as a standalone chunk of code and "linted" to detect semantic issues. (The same happens for test_expect_failure definitions.)
The introduction of test definitions in which the test body is instead presented via a heredoc rather than as a single string creates a blind spot in the linting process since such invocations are not recognized by chainlint.pl.
Address this shortcoming by also recognizing tests defined as:
test_expect_success [prereq] title - <<\EOT
body
EOT
A minor complication is that chainlint.pl has never considered heredoc bodies significant since it doesn't scan them for semantic problems, thus it has always simply thrown them away. However, with the new test_expect_success calling sequence, heredoc bodies become meaningful, thus need to be captured.
---
This is a clean-room implementation which serves the same purpose as a change proposed[1] by Peff; it was created before I looked at Peff's proposal. The two independent implementations turned out quite similar, but the one implemented by this patch takes a more formal and paranoid stance. In particular, unlike Peff's patch, it doesn't trust that the most-recently-seen heredoc body is one associated with the test_expect_success invocation.
This patch can sit either at the top or bottom of Peff's series[2].
There was also related discussion of improving the chainlint self-test infrastructure[3], however, such proposed changes needn't hold up Peff's series[2]; such improvements can be applied after the dust settles. On the other hand, Peff, if you plan to reroll for some reason, feel free to incorporate this patch into your series.
[1]: https://lore.kernel.org/git/[email protected]/
[2]: https://lore.kernel.org/git/[email protected]/
[3]: https://lore.kernel.org/git/[email protected]/
t/chainlint.pl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
t/chainlint.pl +14 -4
@@ -174,6 +174,8 @@ sub swallow_heredocs { $$b =~ /(?:\G|\n)$indent\Q$$tag[0]\E(?:\n|\z)/gc; if (pos($$b) > $start) { my $body = substr($$b, $start, pos($$b) - $start); + $self->{parser}->{heredocs}->{$$tag[0]} = + substr($body, 0, length($body) - length($&)); $self->{lineno} += () = $body =~ /\n/sg; next; }
@@ -232,7 +234,8 @@ sub new { my $self = bless { buff => [], stop => [], - output => [] + output => [], + heredocs => {}, } => $class; $self->{lexer} = Lexer->new($self, $s); return $self;
@@ -616,7 +619,9 @@ sub unwrap { sub check_test { my $self = shift @_; - my ($title, $body) = map(unwrap, @_); + my $title = unwrap(shift @_); + my $body = unwrap(shift @_); + $body = shift @_ if $body eq '-'; $self->{ntests}++; my $parser = TestParser->new(\$body); my @tokens = $parser->parse();
@@ -649,8 +654,13 @@ sub parse_cmd { return @tokens unless @tokens && $tokens[0]->[0] =~ /^test_expect_(?:success|failure)$/; my $n = $#tokens; $n-- while $n >= 0 && $tokens[$n]->[0] =~ /^(?:[;&\n|]|&&|\|\|)$/; - $self->check_test($tokens[1], $tokens[2]) if $n == 2; # title body - $self->check_test($tokens[2], $tokens[3]) if $n > 2; # prereq title body + my $herebody; + if ($n >= 2 && $tokens[$n-1]->[0] eq '-' && $tokens[$n]->[0] =~ /^<<-?(.+)$/) { + $herebody = $self->{heredocs}->{$1}; + $n--; + } + $self->check_test($tokens[1], $tokens[2], $herebody) if $n == 2; # title body + $self->check_test($tokens[2], $tokens[3], $herebody) if $n > 2; # prereq title body return @tokens; }
Signature · 1 line
2.45.2
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 7 lines · Eric Sunshine
This is a clean-room implementation which serves the same purpose as a change proposed[1] by Peff; it was created before I looked at Peff's proposal. The two independent implementations turned out quite similar, but the one implemented by this patch takes a more formal and paranoid stance. In particular, unlike Peff's patch, it doesn't trust that the most-recently-seen heredoc body is one associated with the
test_expect_successinvocation.
Thanks for working on this! I think this is better than the patch I showed earlier. But I am still glad to have worked on that one, because there is no way I'd be able to intelligently review that one without having poked at the code so much myself.
Quoted 7 lines
This patch can sit either at the top or bottom of Peff's series[2].
There was also related discussion of improving the chainlint self-test infrastructure[3], however, such proposed changes needn't hold up Peff's series[2]; such improvements can be applied after the dust settles. On the other hand, Peff, if you plan to reroll for some reason, feel free to incorporate this patch into your series.
IMHO we want it all to come together. We should not allow "<<\EOT" without making sure we can chainlint the test bodies, and we should not make such a big change to chainlint.pl without tests to make sure it works.
I'll post some patches in a moment:
[1/3]: chainlint.pl: fix line number reporting
[2/3]: t/chainlint: add test_expect_success call to test snippets [3/3]: t/chainlint: add tests for test body in heredoc
with the idea that we'd apply your patch here on top of what Junio has queued in jk/test-body-in-here-doc, and then these three on top. For Junio's sanity, I'll roll it all up into one series. But I wanted to show it to you incrementally first, especially because I think the fixes from patch 1/3 above should probably just get squashed in (or even rewritten). I'll discuss the bugs they fix below.
t/chainlint.pl sub swallow_heredocs { · line 181
Quoted 13 lines
t/chainlint.pl +2
-0@@ -174,6 +174,8 @@ sub swallow_heredocs { $$b =~ /(?:\G|\n)$indent\Q$$tag[0]\E(?:\n|\z)/gc; if (pos($$b) > $start) { my $body = substr($$b, $start, pos($$b) - $start); + $self->{parser}->{heredocs}->{$$tag[0]} = + substr($body, 0, length($body) - length($&)); $self->{lineno} += () = $body =~ /\n/sg; next; }
OK, this part looks familiar. :)
t/chainlint.pl sub new { · line 241
Quoted 10 lines
t/chainlint.pl +2
-1@@ -232,7 +234,8 @@ sub new { my $self = bless { buff => [], stop => [], - output => [] + output => [], + heredocs => {}, } => $class; $self->{lexer} = Lexer->new($self, $s); return $self;
I think initializing is not strictly necessary here, since we'd only try to read tags if we saw a here-doc. But there might be some invalid cases where we could convince higher-level code to look for tags even though there were none (and generate a perl warning about trying to dereference undef as a hashref).
On the flip side, what about cleaning up? The "heretags" array is emptied as we parse the heredocs in swallow_heredocs(). But I think once a ShellParser's $self->{heredocs}->{FOO} is written, it will hang around forever (even though it's valid only for that one command). Probably not a big deal, but there's probably some correct spot to reset it.
t/chainlint.pl sub unwrap { · line 627
Quoted 11 lines
t/chainlint.pl +3
-1@@ -616,7 +619,9 @@ sub unwrap { sub check_test { my $self = shift @_; - my ($title, $body) = map(unwrap, @_); + my $title = unwrap(shift @_); + my $body = unwrap(shift @_); + $body = shift @_ if $body eq '-'; $self->{ntests}++; my $parser = TestParser->new(\$body); my @tokens = $parser->parse();
This has two problems related to line numbers. You can't see it in the context, but we later do:
my $lineno = $_[1]->[3];
Now that we're shifting @_, that array item is gone.
The second is that the line number for the here-doc is actually one past the initial line number of the test_expect_success. That works automatically for hanging single-quotes, since the newline from that line is inside the quoted area. But for a here-doc, we have to account for it manually. In my original patch I prepended "\n", but you can also just increment $lineno (which is what I did in the fix I'm about to send).
Quoted 5 lines
t/chainlint.pl +0
-1@@ -649,8 +654,13 @@ sub parse_cmd { return @tokens unless @tokens && $tokens[0]->[0] =~ /^test_expect_(?:success|failure)$/; my $n = $#tokens; $n-- while $n >= 0 && $tokens[$n]->[0] =~ /^(?:[;&\n|]|&&|\|\|)$/; - $self->check_test($tokens[1], $tokens[2]) if $n == 2; # title body
t/chainlint.pl sub parse_cmd { · line 665
Quoted 10 lines
t/chainlint.pl +7
-1- $self->check_test($tokens[2], $tokens[3]) if $n > 2; # prereq title body + my $herebody; + if ($n >= 2 && $tokens[$n-1]->[0] eq '-' && $tokens[$n]->[0] =~ /^<<-?(.+)$/) { + $herebody = $self->{heredocs}->{$1}; + $n--; + } + $self->check_test($tokens[1], $tokens[2], $herebody) if $n == 2; # title body + $self->check_test($tokens[2], $tokens[3], $herebody) if $n > 2; # prereq title body return @tokens; }
OK, mostly as expected. I think the check for "-" here is redundant with what's in check_test(). We could just feed the heredoc body either way, and in the nonsense case of:
test_expect_success 'title' 'test body' <<EOT
nobody reads this!
EOT
the heredoc data would just be ignored.
Requiring "<<" at the end is somewhat limiting. E.g. this is valid:
test_expect_success <<EOT 'title' -
the test body
EOT
I don't expect anybody to do that, but it would be nice to be more robust if we can. I think the tokens are still wrapped at this point, so we could read through all of them looking for "<<" anywhere, without getting confused by "$(cat <<INNER_HEREDOC)". I think, anyway (I didn't test).
I didn't address either of those comments in the patches I'm about to send.
-Peff
PATCH 1/3 chainlint.pl: fix line number reporting
The previous commit taught chainlint.pl to handle test bodies in heredocs, but there are two small bugs related to line numbers:
1. Prior to that commit, we'd leave the title and body untouched in @_. So we could later pull the line number out of the $_[1] array element. Now we shift off the front of the array, so we have to remember that element to grab the line number. This is a regression even for regular:
test_expect_success 'title' '
test body
'
invocations; the lines for ever test started fresh at 0.
2. For an invocation like the one above, if the test_expect_success line is X, then "test body" would correctly start at X+1, since the hanging newline at the start of the single-quoted test body increments the count. But for a here-doc, there is an implicit newline at the end of the token stream before the here-doc starts. We have to increment "lineno" to account for this.
Actually, this is not _quite_ correct, as there could be multiple here-docs, like:
test_expect_success "$(cat <<END_OF_TITLE)" - <<END_OF_TEST this is the title
END_OF_TITLE
this is the test
END_OF_TEST
in which case we'd need to skip past END_OF_TITLE. Given how unlikely it is for anybody to do this, and since it would only affect line numbers, it's probably not worth caring about too much. The solution would probably be to record the starting line number of each here-doc section in the lexer/shellparser stage.
---
Note to the maintainer: do not worry about applying these yet! The parent message describes where they'd go in the series, but I'll send a full series once Eric and I have worked out the details. Review comments welcome, of course. :)
I actually suspect the "record the heredoc line number" thing would not be too hard. I.e., turn ShellParser's "heredoc" hash to point to hashrefs like: "{ content => ..., lineno => ... }". And that would give us a good spot to stick an "interpolate" boolean later if we want.
t/chainlint.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
t/chainlint.pl +7 -3
@@ -620,15 +620,19 @@ sub unwrap { sub check_test { my $self = shift @_; my $title = unwrap(shift @_); - my $body = unwrap(shift @_); - $body = shift @_ if $body eq '-'; + my $body = shift @_; + my $lineno = $body->[3]; + $body = unwrap($body); + if ($body eq '-') { + $body = shift @_; + $lineno++; + } $self->{ntests}++; my $parser = TestParser->new(\$body); my @tokens = $parser->parse(); my $problems = $parser->{problems}; return unless $emit_all || @$problems; my $c = main::fd_colors(1); - my $lineno = $_[1]->[3]; my $start = 0; my $checked = ''; for (sort {$a->[1]->[2] <=> $b->[1]->[2]} @$problems) {
Signature · 1 line
2.45.2.1178.gaaad15bb7b
Re: [PATCH 1/3] chainlint.pl: fix line number reporting
Quoted 25 lines · Jeff King
The previous commit taught chainlint.pl to handle test bodies in heredocs, but there are two small bugs related to line numbers:
2. For an invocation like the one above, if the
test_expect_successline is X, then "test body" would correctly start at X+1, since the hanging newline at the start of the single-quoted test body increments the count. But for a here-doc, there is an implicit newline at the end of the token stream before the here-doc starts. We have to increment "lineno" to account for this.Actually, this is not _quite_ correct, as there could be multiple here-docs, like:
test_expect_success"$(cat <<END_OF_TITLE)" - <<END_OF_TESTthis is the titleEND_OF_TITLE
this is the testEND_OF_TESTin which case we'd need to skip past
END_OF_TITLE. Given how unlikely it is for anybody to do this, and since it would only affect line numbers, it's probably not worth caring about too much. The solution would probably be to record the starting line number of each here-doc section in the lexer/shellparser stage.
Quoted 6 lines
Signed-off-by Jeff King <[email protected]>---
I actually suspect the "record the heredoc line number" thing would not be too hard. I.e., turn ShellParser's "heredoc" hash to point to hashrefs like: "{ content => ..., lineno => ... }". And that would give us a good spot to stick an "interpolate" boolean later if we want.
It turned out to be quite easy. See below for an implementation atop your patch [1/3] (modulo Gmail whitespace damage). Given how simple this ended up being, it probably makes sense to squash this change in, as well.
--- >8 ---
t/chainlint.pl +7 -4
@@ -174,8 +174,10 @@ sub swallow_heredocs { $$b =~ /(?:\G|\n)$indent\Q$$tag[0]\E(?:\n|\z)/gc; if (pos($$b) > $start) { my $body = substr($$b, $start, pos($$b) - $start); - $self->{parser}->{heredocs}->{$$tag[0]} = - substr($body, 0, length($body) - length($&)); + $self->{parser}->{heredocs}->{$$tag[0]} = { + content => substr($body, 0, length($body) - length($&)), + start_line => $self->{lineno}, + }; $self->{lineno} += () = $body =~ /\n/sg; next; }
@@ -624,8 +626,9 @@ sub check_test { my $lineno = $body->[3]; $body = unwrap($body); if ($body eq '-') { - $body = shift @_; - $lineno++; + my $herebody = shift @_; + $body = $herebody->{content}; + $lineno = $herebody->{start_line}; } $self->{ntests}++; my $parser = TestParser->new(\$body);
--
Re: [PATCH 1/3] chainlint.pl: fix line number reporting
Quoted 9 lines · Eric Sunshine
Quoted 4 lines
I actually suspect the "record the heredoc line number" thing would not be too hard. I.e., turn ShellParser's "heredoc" hash to point to hashrefs like: "{ content => ..., lineno => ... }". And that would give us a good spot to stick an "interpolate" boolean later if we want.
It turned out to be quite easy. See below for an implementation atop your patch [1/3] (modulo Gmail whitespace damage). Given how simple this ended up being, it probably makes sense to squash this change in, as well.
Very nice! I was hoping it would be something like this. I've squashed this in, and confirmed that it fixes the line numbers in my "double" case:
test_expect_success "$(cat <<END_OF_PREREQS)" 'here-doc-double' - <<\EOT SOME
PREREQS
END_OF_PREREQS
echo "actual test commands"
echo "that should be checked"
EOT
The bogus line was incorrectly reported as line 2, because we did not account for the first here-doc.
-Peff
PATCH 2/3 t/chainlint: add test_expect_success call to test snippets
In reply to Jeff KingThe 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 (and the next patch will add some).
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. A few more things we could do:
a. I left the for-loop in the Makefile for assembling the test file.
This could be collapsed to a single "sed" invocation, though we might hit OS command-line limits (the current set of names is over 2k). And we need to loop anyway to assemble the expected output. Although...
b. We could also stick the test names into the ".expect" files, and
then that loop could go away in favor of "cat". That's more boilerplate for little gain, though.
c. I didn't indent the test bodies themselves, as we would if writing
real tests. I don't think it really matters beyond aesthetics.
---
I'm open to doing any of a-c if you feel strongly.
t/Makefile | 4 +--- t/chainlint/arithmetic-expansion.test | 2 ++ t/chainlint/bash-array.test | 2 ++ t/chainlint/blank-line-before-esac.test | 2 ++ t/chainlint/blank-line.test | 2 ++ t/chainlint/block-comment.test | 2 ++ t/chainlint/block.test | 2 ++ t/chainlint/broken-chain.test | 2 ++ t/chainlint/case-comment.test | 2 ++ t/chainlint/case.test | 2 ++ t/chainlint/chain-break-background.test | 2 ++ t/chainlint/chain-break-continue.test | 2 ++ t/chainlint/chain-break-false.test | 2 ++ t/chainlint/chain-break-return-exit.test | 2 ++ t/chainlint/chain-break-status.test | 2 ++ t/chainlint/chained-block.test | 2 ++ t/chainlint/chained-subshell.test | 2 ++ t/chainlint/close-nested-and-parent-together.test | 2 ++ t/chainlint/close-subshell.test | 2 ++ t/chainlint/command-substitution-subsubshell.test | 2 ++ t/chainlint/command-substitution.test | 2 ++ t/chainlint/comment.test | 2 ++ t/chainlint/complex-if-in-cuddled-loop.test | 2 ++ t/chainlint/cuddled-if-then-else.test | 2 ++ t/chainlint/cuddled-loop.test | 2 ++ t/chainlint/cuddled.test | 2 ++ t/chainlint/double-here-doc.test | 2 ++ t/chainlint/dqstring-line-splice.test | 2 ++ t/chainlint/dqstring-no-interpolate.test | 2 ++ t/chainlint/empty-here-doc.test | 2 ++ t/chainlint/exclamation.test | 2 ++ t/chainlint/exit-loop.test | 2 ++ t/chainlint/exit-subshell.test | 2 ++ t/chainlint/for-loop-abbreviated.test | 2 ++ t/chainlint/for-loop.test | 2 ++ t/chainlint/function.test | 2 ++ t/chainlint/here-doc-close-subshell.test | 2 ++ t/chainlint/here-doc-indent-operator.test | 2 ++ t/chainlint/here-doc-multi-line-command-subst.test | 2 ++ t/chainlint/here-doc-multi-line-string.test | 2 ++ t/chainlint/here-doc.test | 2 ++ t/chainlint/if-condition-split.test | 2 ++ t/chainlint/if-in-loop.test | 2 ++ t/chainlint/if-then-else.test | 2 ++ t/chainlint/incomplete-line.test | 2 ++ t/chainlint/inline-comment.test | 2 ++ t/chainlint/loop-detect-failure.test | 2 ++ t/chainlint/loop-detect-status.test | 2 ++ t/chainlint/loop-in-if.test | 2 ++ t/chainlint/loop-upstream-pipe.test | 2 ++ t/chainlint/multi-line-nested-command-substitution.test | 2 ++ t/chainlint/multi-line-string.test | 2 ++ t/chainlint/negated-one-liner.test | 2 ++ t/chainlint/nested-cuddled-subshell.test | 2 ++ t/chainlint/nested-here-doc.test | 2 ++ t/chainlint/nested-loop-detect-failure.test | 2 ++ t/chainlint/nested-subshell-comment.test | 2 ++ t/chainlint/nested-subshell.test | 2 ++ t/chainlint/not-heredoc.test | 2 ++ t/chainlint/one-liner-for-loop.test | 2 ++ t/chainlint/one-liner.test | 2 ++ t/chainlint/p4-filespec.test | 2 ++ t/chainlint/pipe.test | 2 ++ t/chainlint/return-loop.test | 2 ++ t/chainlint/semicolon.test | 2 ++ t/chainlint/sqstring-in-sqstring.test | 2 ++ t/chainlint/subshell-here-doc.test | 2 ++ t/chainlint/subshell-one-liner.test | 2 ++ t/chainlint/t7900-subtree.test | 2 ++ t/chainlint/token-pasting.test | 2 ++ t/chainlint/unclosed-here-doc-indent.test | 2 ++ t/chainlint/unclosed-here-doc.test | 2 ++ t/chainlint/while-loop.test | 2 ++ 73 files changed, 145 insertions(+), 3 deletions(-)
t/Makefile +1 -3
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 } +'
t/chainlint/blank-line.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'blank-line' ' ( nothing &&
@@ -8,3 +9,4 @@ ) +'
t/chainlint/block-comment.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'block-comment' ' ( { # show a
@@ -6,3 +7,4 @@ echo b } ) +'
t/chainlint/block.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'block' ' ( # LINT: missing "&&" after first "echo" foo &&
@@ -25,3 +26,4 @@ echo "done" } && finis +'
t/chainlint/broken-chain.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'broken-chain' ' ( foo && # LINT: missing "&&" from "bar"
@@ -6,3 +7,4 @@ # LINT: final statement before closing ")" legitimately lacks "&&" wop ) +'
t/chainlint/case-comment.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'case-comment' ' ( case "$x" in # found foo
@@ -9,3 +10,4 @@ ;; esac ) +'
t/chainlint/case.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'case' ' ( # LINT: "...)" arms in "case" not misinterpreted as subshell-closing ")" case "$x" in
@@ -21,3 +22,4 @@ case "$y" in 2) false;; esac foobar ) +'
t/chainlint/chain-break-background.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'chain-break-background' ' JGIT_DAEMON_PID= && git init --bare empty.git && >empty.git/git-daemon-export-ok &&
@@ -8,3 +9,4 @@ mkfifo jgit_daemon_output && JGIT_DAEMON_PID=$! } && test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git +'
t/chainlint/chain-break-continue.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'chain-break-continue' ' git ls-tree --name-only -r refs/notes/many_notes | while read path do
@@ -11,3 +12,4 @@ do return 1 fi done +'
t/chainlint/chain-break-false.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'chain-break-false' ' # LINT: broken &&-chain okay if explicit "false" signals failure if condition not satisified then
@@ -8,3 +9,4 @@ else echo it went okay congratulate user fi +'
t/chainlint/chain-break-return-exit.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'chain-break-return-exit' ' case "$(git ls-files)" in one) echo pass one ;; # LINT: broken &&-chain okay if explicit "return 1" signals failuire
@@ -21,3 +22,4 @@ for i in 1 2 3 4 ; do git checkout main -b $i || return $? test_commit $i $i $i tag$i || return $? done +'
t/chainlint/chain-break-status.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'chain-break-status' ' # LINT: broken &&-chain okay if next command handles "$?" explicitly OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" &&
@@ -9,3 +10,4 @@ test_match_signal 13 "$OUT" && test "$ret" = 3 } && test_cmp expect actual +'
t/chainlint/chained-block.test +2 -0
@@ -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 -0
@@ -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) +'
t/chainlint/close-nested-and-parent-together.test +2 -0
@@ -1,3 +1,5 @@ +test_expect_success 'close-nested-and-parent-together' ' (cd foo && (bar && baz)) +'
t/chainlint/close-subshell.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'close-subshell' ' # LINT: closing ")" with various decorations ("&&", ">", "|", etc.) ( foo
@@ -25,3 +26,4 @@ fuzzle && ( yop ) +'
t/chainlint/command-substitution-subsubshell.test +2 -0
@@ -1,3 +1,5 @@ +test_expect_success 'command-substitution-subsubshell' ' # LINT: subshell nested in subshell nested in command substitution OUT=$( ((large_git 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" +'
t/chainlint/command-substitution.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'command-substitution' ' ( foo && # LINT: closing ")" of $(...) not misinterpreted as subshell-closing ")"
@@ -9,3 +10,4 @@ bar=$(gobble blocks) baz ) +'
t/chainlint/comment.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'comment' ' ( # LINT: swallow comment lines # comment 1
@@ -9,3 +10,4 @@ # comment 3 # comment 4 ) +'
t/chainlint/complex-if-in-cuddled-loop.test +2 -0
@@ -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 -0
@@ -1,7 +1,9 @@ +test_expect_success 'cuddled-if-then-else' ' # LINT: "if" cuddled with "(" and ")"; indented with spaces, not tabs (if test -z ""; then echo empty else echo bizzy fi) && echo foobar +'
t/chainlint/cuddled-loop.test +2 -0
@@ -1,7 +1,9 @@ +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 ( while read x do foobar bop || exit 1 done <file ) && outside subshell +'
t/chainlint/cuddled.test +2 -0
@@ -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 -0
@@ -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 -0
@@ -1,7 +1,9 @@ +test_expect_success 'dqstring-line-splice' ' # LINT: line-splice within DQ-string '" echo 'fatal: reword option of --fixup is mutually exclusive with'\ '--patch/--interactive/--all/--include/--only' >expect && test_must_fail git commit --fixup=reword:HEAD~ $1 2>actual && test_cmp expect actual "' +'
t/chainlint/dqstring-no-interpolate.test +2 -0
@@ -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 "' +'
t/chainlint/empty-here-doc.test +2 -0
@@ -1,5 +1,7 @@ +test_expect_success 'empty-here-doc' ' git ls-tree $tree path >current && # LINT: empty here-doc cat >expected <<\EOF && EOF test_output +'
t/chainlint/exclamation.test +2 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 +'
t/chainlint/here-doc-multi-line-command-subst.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'here-doc-multi-line-command-subst' ' ( # LINT: line contains here-doc and opens multi-line $(...) x=$(bobble <<-\END &&
@@ -7,3 +8,4 @@ wiffle) echo $x ) +'
t/chainlint/here-doc-multi-line-string.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'here-doc-multi-line-string' ' ( # LINT: line contains here-doc and opens multi-line string cat <<-\TXT && echo "multi-line
@@ -6,3 +7,4 @@ TXT bap ) +'
t/chainlint/here-doc.test +2 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -1,3 +1,4 @@ +test_expect_success 'loop-in-if' ' ( if true then
@@ -13,3 +14,4 @@ fi bar ) +'
t/chainlint/loop-upstream-pipe.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'loop-upstream-pipe' ' ( git rev-list --objects --no-object-names base..loose | while read oid
@@ -9,3 +10,4 @@ done | sort -k1 ) >expect && +'
t/chainlint/multi-line-nested-command-substitution.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'multi-line-nested-command-substitution' ' ( foo && x=$(
@@ -16,3 +17,4 @@ sort && fip) && echo fail ) +'
t/chainlint/multi-line-string.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'multi-line-string' ' ( x="line 1 line 2
@@ -13,3 +14,4 @@ ghi" && barfoo ) +'
t/chainlint/negated-one-liner.test +2 -0
@@ -1,7 +1,9 @@ +test_expect_success 'negated-one-liner' ' # LINT: top-level one-liner subshell ! (foo && bar) && ! (foo && bar) >baz && # LINT: top-level one-liner subshell missing internal "&&" ! (foo; bar) && ! (foo; bar) >baz +'
t/chainlint/nested-cuddled-subshell.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'nested-cuddled-subshell' ' ( # LINT: opening "(" cuddled with first nested subshell statement (cd foo &&
@@ -29,3 +30,4 @@ foobar ) +'
t/chainlint/nested-here-doc.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'nested-here-doc' ' # LINT: inner "EOF" not misintrepreted as closing ARBITRARY here-doc cat <<ARBITRARY >foop && naddle
@@ -31,3 +32,4 @@ ARBITRARY foobar ) +'
t/chainlint/nested-loop-detect-failure.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'nested-loop-detect-failure' ' # LINT: neither loop handles failure explicitly with "|| return 1" for i in 0 1 2 3 4 5 6 7 8 9; do
@@ -33,3 +34,4 @@ do echo "$i$j" >"path$i$j" || return 1 done || return 1 done +'
t/chainlint/nested-subshell-comment.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'nested-subshell-comment' ' ( foo && (
@@ -11,3 +12,4 @@ ) fuzzy ) +'
t/chainlint/nested-subshell.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'nested-subshell' ' ( cd foo && (
@@ -11,3 +12,4 @@ echo b ) >file ) +'
t/chainlint/not-heredoc.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'not-heredoc' ' # LINT: "<< ours" inside string is not here-doc echo "<<<<<<< ours" && echo ourside &&
@@ -14,3 +15,4 @@ echo ">>>>>>> theirs" && echo ">>>>>>> theirs" poodle ) >merged +'
t/chainlint/one-liner-for-loop.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'one-liner-for-loop' ' git init dir-rename-and-content && ( cd dir-rename-and-content &&
@@ -8,3 +9,4 @@ git init dir-rename-and-content && git add foo olddir && git commit -m "original" && ) +'
t/chainlint/one-liner.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'one-liner' ' # LINT: top-level one-liner subshell (foo && bar) && (foo && bar) |
@@ -10,3 +11,4 @@ # LINT: ";" in string not misinterpreted as broken &&-chain (foo "bar; baz") +'
t/chainlint/p4-filespec.test +2 -0
@@ -1,5 +1,7 @@ +test_expect_success 'p4-filespec' ' ( # LINT: Perforce revspec in filespec not misinterpreted as in-line comment p4 print -1 //depot/fiddle#42 >file && foobar ) +'
t/chainlint/pipe.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'pipe' ' ( # LINT: no "&&" needed on line ending with "|" foo |
@@ -10,3 +11,4 @@ sunder ) +'
t/chainlint/return-loop.test +2 -0
@@ -1,6 +1,8 @@ +test_expect_success 'return-loop' ' while test $i -lt $((num - 5)) do # LINT: "|| return {n}" valid loop escape outside subshell; no "&&" needed git notes add -m "notes for commit$i" HEAD~$i || return 1 i=$((i + 1)) done +'
t/chainlint/semicolon.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'semicolon' ' ( # LINT: missing internal "&&" and ending "&&" cat foo ; echo bar
@@ -23,3 +24,4 @@ # LINT: semicolon unnecessary but legitimate echo; done) +'
t/chainlint/sqstring-in-sqstring.test +2 -0
@@ -1,5 +1,7 @@ +test_expect_success 'sqstring-in-sqstring' ' # LINT: SQ-string Perl code fragment within SQ-string perl -e '\'' defined($_ = -s $_) or die for @ARGV; exit 1 if $ARGV[0] <= $ARGV[1]; '\'' test-2-$packname_2.pack test-3-$packname_3.pack +'
t/chainlint/subshell-here-doc.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'subshell-here-doc' ' ( # LINT: stitch together incomplete \-ending lines # LINT: swallow here-doc to avoid false positives in content
@@ -33,3 +34,4 @@ EOF ARBITRARY3 meep ) +'
t/chainlint/subshell-one-liner.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'subshell-one-liner' ' ( # LINT: nested one-liner subshell (foo && bar) &&
@@ -22,3 +23,4 @@ foobar ) +'
t/chainlint/t7900-subtree.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 't7900-subtree' ' ( chks="sub1 sub2
@@ -20,3 +21,4 @@ TXT check_equal "$subfiles" "$chkms $chks" ) +'
t/chainlint/token-pasting.test +2 -0
@@ -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 -0
@@ -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 -0
@@ -1,7 +1,9 @@ +test_expect_success 'unclosed-here-doc' ' command_which_is_run && cat >expect <<\EOF && we try to end the here-doc below, but the indentation throws us off since the operator is not "<<-". EOF command_which_is_gobbled +'
t/chainlint/while-loop.test +2 -0
@@ -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 ) +'
Signature · 1 line
2.45.2.1178.gaaad15bb7b
Re: [PATCH 2/3] t/chainlint: add test_expect_success call to test snippets
t/Makefile clean-chainlint: · line 115
Quoted 13 lines · Jeff King
t/Makefile +1
-3@@ -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" && \
BTW, not new in my patch, but I found it ironic that the shell snippet here itself violates &&-chain rules. It should "|| exit 1" inside the loop if a sed call fails.
-Peff
Re: [PATCH 2/3] t/chainlint: add test_expect_success call to test snippets
Quoted 10 lines · Jeff King
t/Makefile clean-chainlint: · line 113
Quoted 6 lines
for i in $(CHAINLINTTESTS); do \t/Makefile +1
-3- echo "test_expect_success '$$i' '" && \ - sed -e '/^# LINT: /d' chainlint/$$i.test && \ - echo "'"; \ + sed -e '/^# LINT: /d' chainlint/$$i.test; \ done >'$(CHAINLINTTMP_SQ)'/tests && \BTW, not new in my patch, but I found it ironic that the shell snippet here itself violates &&-chain rules. It should "|| exit 1" inside the loop if a sed call fails.
Indeed, what an embarrassing oversight, especially since this loop was added in preparation for chainlint.pl which diagnoses missing || exit (or || return) in loops in tests (unlike chainlint.sed which didn't).
PATCH 3/3 t/chainlint: add tests for test body in heredoc
In reply to Jeff KingThe chainlint.pl script recently learned about our new:
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 "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.
---
These could also be squashed into Eric's patch which introduces the new functionality.
t/chainlint/here-doc-body-indent.expect | 2 ++ t/chainlint/here-doc-body-indent.test | 4 ++++ t/chainlint/here-doc-body.expect | 7 +++++++ t/chainlint/here-doc-body.test | 9 +++++++++ t/chainlint/here-doc-double.expect | 2 ++ t/chainlint/here-doc-double.test | 10 ++++++++++ 6 files changed, 34 insertions(+) create mode 100644 t/chainlint/here-doc-body-indent.expect create mode 100644 t/chainlint/here-doc-body-indent.test create mode 100644 t/chainlint/here-doc-body.expect create mode 100644 t/chainlint/here-doc-body.test create mode 100644 t/chainlint/here-doc-double.expect create mode 100644 t/chainlint/here-doc-double.test
t/chainlint/here-doc-body-indent.expect new file +2 -0
@@ -0,0 +1,2 @@ + echo "we should find this" ?!AMP?! + echo "even though our heredoc has its indent stripped"
t/chainlint/here-doc-body-indent.test new file +4 -0
@@ -0,0 +1,4 @@ +test_expect_success 'here-doc-body-indent' - <<-\EOT + echo "we should find this" + echo "even though our heredoc has its indent stripped" +EOT
t/chainlint/here-doc-body.expect new file +7 -0
@@ -0,0 +1,7 @@ + echo "missing chain before" ?!AMP?! + cat >file <<-\EOF && + inside inner here-doc + these are not shell commands + EOF + echo "missing chain after" ?!AMP?! + echo "but this line is OK because it's the end"
t/chainlint/here-doc-body.test new file +9 -0
@@ -0,0 +1,9 @@ +test_expect_success 'here-doc-body' - <<\EOT + echo "missing chain before" + cat >file <<-\EOF && + inside inner here-doc + these are not shell commands + EOF + echo "missing chain after" + echo "but this line is OK because it's the end" +EOT
t/chainlint/here-doc-double.expect new file +2 -0
@@ -0,0 +1,2 @@ + echo "actual test commands" ?!AMP?! + echo "that should be checked"
t/chainlint/here-doc-double.test new file +10 -0
@@ -0,0 +1,10 @@ +# This is obviously a ridiculous thing to do, but we should be able +# to handle two here-docs on the same line, and attribute them +# correctly. +test_expect_success "$(cat <<END_OF_PREREQS)" 'here-doc-double' - <<\EOT +SOME +PREREQS +END_OF_PREREQS + echo "actual test commands" + echo "that should be checked" +EOT
Signature · 1 line
2.45.2.1178.gaaad15bb7b
Re: [PATCH 3/3] t/chainlint: add tests for test body in heredoc
Quoted 6 lines · Jeff King
The chainlint.pl script recently learned about our new:
test_expect_success'some test' - <<\EOT
TEST_BODY
EOT
Quoted 7 lines
syntax, where
TEST_BODYshould be checked in the usual way. Let's make sure this works by adding a few tests. [...]Signed-off-by Jeff King <[email protected]>---
These could also be squashed into Eric's patch which introduces the new functionality.
As the author of these tests, you should get credit, so I'd proposed not squashing this into my patch.
t/chainlint/here-doc-body.test line 9
Quoted 11 lines
t/chainlint/here-doc-body.test +9
-0@@ -0,0 +1,9 @@ +test_expect_success 'here-doc-body' - <<\EOT + echo "missing chain before" + cat >file <<-\EOF && + inside inner here-doc + these are not shell commands + EOF + echo "missing chain after" + echo "but this line is OK because it's the end" +EOT
This one made me think of an additional pathological case, though I'm not sure it's worth having a test:
test_expect_success 'pathological-here-doc-body' - <<\EOF
echo "missing chain before"
cat >file <<-\EOF &&
inside inner here-doc
these are not shell commands
EOF
echo "missing chain after"
echo "but this line is OK because it's the end"
EOF
It's exactly the same as your test except that the same tag ("EOF") is used for both outer and inner heredocs. It works because the outer heredoc is introduced with << whereas the inner with <<-. The opposite case, in which outer is introduced with <<- and inner with <<, obviously would be bogus.
Re: [PATCH 3/3] t/chainlint: add tests for test body in heredoc
Quoted 13 lines · Eric Sunshine
This one made me think of an additional pathological case, though I'm not sure it's worth having a test:
test_expect_success'pathological-here-doc-body' - <<\EOF
echo "missing chain before"
cat >file <<-\EOF &&
inside inner here-doc
these are not shell commands
EOF
echo "missing chain after"
echo "but this line is OK because it's the end"
EOF
Quoted 5 lines
It's exactly the same as your test except that the same tag ("EOF") is used for both outer and inner heredocs. It works because the outer heredoc is introduced with
<<whereas the inner with<<-. The opposite case, in which outer is introduced with<<-and inner with<<, obviously would be bogus.
Ooh, that's devious. I'll add it.
-Peff
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
In reply to Jeff KingQuoted 8 lines · Jeff King
I'll post some patches in a moment:
[1/3]: chainlint.pl: fix line number reporting
[2/3]: t/chainlint: addtest_expect_successcall to test snippets [3/3]: t/chainlint: add tests for test body in heredocwith the idea that we'd apply your patch here on top of what Junio has queued in jk/test-body-in-here-doc, and then these three on top.
Would the final form be to have Eric's preparatory enhancement to chainlint and then these three first, and finally the "here-docs" conversion I queued from you earlier?
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Jeff King
I'll post some patches in a moment:
[1/3]: chainlint.pl: fix line number reporting
[2/3]: t/chainlint: addtest_expect_successcall to test snippets [3/3]: t/chainlint: add tests for test body in heredoc
Quoted 6 lines
Quoted 2 lines
with the idea that we'd apply your patch here on top of what Junio has queued in jk/test-body-in-here-doc, and then these three on top.
Would the final form be to have Eric's preparatory enhancement to chainlint and then these three first, and finally the "here-docs" conversion I queued from you earlier?
I had planned on top (leaving a brief moment where chainlint would ignore the new format), but either way is fine.
My biggest question is around my patch 1 above:
- is it worth squashing in to Eric's patch? I didn't want to do that without getting his OK on the approach.
- instead of bumping the line number in the caller, should the lexer record the line number of the here-doc to be used later?
- the test harness in the Makefile strips the line numbers from the chainlint output, so it's hard to verify those fixes. I saw them only because the combination of the two bugs meant that the here-doc had a "line 0" in it, which was enough to confuse the "sed" invocation in the Makefile.
I did manually verify that it is OK after my fix, but do we want that to be part of the chainlint tests? Just leaving the line numbers in is a maintenance nightmare, since it depends on the order of concatenating all of the tests together (so our "expect" files would depend on all of the previous tests). But if we wanted to get fancy, we could perhaps store relative offsets in the expect file. I think it gets pretty complicated, though, since we print only problematic lines.
I was going to give it a few days for Eric to chime in on those points, and then assemble a final version for you to apply (but I certainly don't mind if you want to pick up what's here in the meantime).
-Peff
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 4 lines · Jeff King
My biggest question is around my patch 1 above:
- is it worth squashing in to Eric's patch? I didn't want to do that without getting his OK on the approach.
Given the effort you put into the commit message and diagnosing my bugs, my knee-jerk response is that it would be nice to keep your patch separate so you retain authorship. But it also would be irresponsible for us to let my buggy patch into the project history as-is since you caught the problems at review time. So, squashing your fixes in seems like the correct approach.
Quoted 2 lines
- instead of bumping the line number in the caller, should the lexer record the line number of the here-doc to be used later?
It would be more robust to do so, but I suspect things will be fine for a long time even without such an enhancement. But I also agree with your commentary in patch [1/3] that it probably would be easy to latch the line number at the point at which the heredoc body is latched.
Quoted 6 lines
- the test harness in the
Makefilestrips the line numbers from the chainlint output, so it's hard to verify those fixes. I saw them only because the combination of the two bugs meant that the here-doc had a "line 0" in it, which was enough to confuse the "sed" invocation in theMakefile.
Quoted 8 lines
I did manually verify that it is OK after my fix, but do we want that to be part of the chainlint tests? Just leaving the line numbers in is a maintenance nightmare, since it depends on the order of concatenating all of the tests together (so our "expect" files would depend on all of the previous tests). But if we wanted to get fancy, we could perhaps store relative offsets in the expect file. I think it gets pretty complicated, though, since we print only problematic lines.
Given the way the Makefile currently concatenates all the self-tests, it would indeed be a nightmare to retain the line numbers. In the long run, we probably ought someday to adopt Ævar's idea of checking the self-test files individually[*] rather than en masse. With that approach, it may make sense to revisit whether or not line numbers should be present in the "expected" files.
[*] https://lore.kernel.org/git/CAPig+cSBjsosRqoAafYN94Cco8+7SdUt0ND_jHS+jVPoM4K0JA@mail.gmail.com/
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 9 lines · Eric Sunshine
Quoted 8 lines
I did manually verify that it is OK after my fix, but do we want that to be part of the chainlint tests? Just leaving the line numbers in is a maintenance nightmare, since it depends on the order of concatenating all of the tests together (so our "expect" files would depend on all of the previous tests). But if we wanted to get fancy, we could perhaps store relative offsets in the expect file. I think it gets pretty complicated, though, since we print only problematic lines.
Quoted 8 lines
Given the way the
Makefilecurrently concatenates all the self-tests, it would indeed be a nightmare to retain the line numbers. In the long run, we probably ought someday to adopt Ævar's idea of checking the self-test files individually[*] rather than en masse. With that approach, it may make sense to revisit whether or not line numbers should be present in the "expected" files.[*] https://lore.kernel.org/git/CAPig+cSBjsosRqoAafYN94Cco8+7SdUt0ND_jHS+jVPoM4K0JA@mail.gmail.com/
I took a look at running each test individually. It's surprisingly quite a bit slower! About 4s instead of 200ms. There's a bit of low-hanging fruit to get it down to ~1.7s (which I'll include in my series). But in the end I punted on that for now, but did add line-number checks. Each expect file just knows its own numbers, and I use a bit of perl to handle the running offset.
-Peff
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 8 lines · Jeff King
Quoted 7 lines · Eric Sunshine
Given the way the
Makefilecurrently concatenates all the self-tests, it would indeed be a nightmare to retain the line numbers. In the long run, we probably ought someday to adopt Ævar's idea of checking the self-test files individually[*] rather than en masse. With that approach, it may make sense to revisit whether or not line numbers should be present in the "expected" files.
Quoted 4 lines
Quoted 1 line
[*] https://lore.kernel.org/git/CAPig+cSBjsosRqoAafYN94Cco8+7SdUt0ND_jHS+jVPoM4K0JA@mail.gmail.com/
I took a look at running each test individually. It's surprisingly quite a bit slower! About 4s instead of 200ms.
I'm not surprised. As currently implemented, make test chainlints the self-tests and the Git test scripts unconditionally, even if none of them have changed. As I understand it, Ævar idea was that the costly initial make test would be offset by subsequent make test invocations since make will only recheck the self-test files and Git test scripts if they have been changed. His particular use-case, as I recall, was when running the full make test repeatedly, such as with git rebase --exec 'make test' HEAD~n to ensure that the entire test suite passes for each patch of a multi-patch series prior to submitting the series; the repeated cost of linting unchanged files adds up, especially when the series is long.
Quoted 5 lines
There's a bit of low-hanging
fruit to get it down to ~1.7s (which I'll include in my series). But in the end I punted on that for now, but did add line-number checks. Each expect file just knows its own numbers, and I use a bit of perl to handle the running offset.
Okay.
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 4 lines · Eric Sunshine
Quoted 2 lines · Jeff King
I took a look at running each test individually. It's surprisingly quite a bit slower! About 4s instead of 200ms.
Quoted 11 lines
I'm not surprised. As currently implemented,
make testchainlints the self-tests and the Git test scripts unconditionally, even if none of them have changed. As I understand it, Ævar idea was that the costly initialmake testwould be offset by subsequentmake testinvocations sincemakewill only recheck the self-test files and Git test scripts if they have been changed. His particular use-case, as I recall, was when running the fullmake testrepeatedly, such as withgit rebase --exec 'make test' HEAD~nto ensure that the entire test suite passes for each patch of a multi-patch series prior to submitting the series; the repeated cost of linting unchanged files adds up, especially when the series is long.
By the way, regarding your 4s instead of 200ms result, I don't think that is necessarily reflective of what can be achieved. In particular, to properly measure the effect, you also need to remove all the threading support from chainlint.pl since using "ithreads" adds a not-insignificant amount of time to script startup, especially on Windows, but even on Unix it is quite noticeable.
To test this, I think you can just replace this block:
unless ($Config{useithreads} && eval {
require threads; threads->import();
require Thread::Queue; Thread::Queue->import();
1;
}) {
push(@stats, check_script(1, sub { shift(@scripts); }, sub {
print(@_); }));
show_stats($start_time, \@stats) if $show_stats;
exit(exit_code(\@stats));
}with:
if (1) {
push(@stats, check_script(1, sub { shift(@scripts); }, sub {
print(@_); }));
show_stats($start_time, \@stats) if $show_stats;
exit(exit_code(\@stats));
}Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 6 lines · Eric Sunshine
By the way, regarding your 4s instead of 200ms result, I don't think that is necessarily reflective of what can be achieved. In particular, to properly measure the effect, you also need to remove all the threading support from chainlint.pl since using "ithreads" adds a not-insignificant amount of time to script startup, especially on Windows, but even on Unix it is quite noticeable.
Yes, that is the low-hanging fruit I found. ;) Just adding:
$jobs = @scripts if @scripts < $jobs;
cuts the time to run all scripts individually from ~4s to ~1.7s.
Removing the threading entirely goes to ~1.1s. I hadn't tried that until now, but it is probably worth doing for the case of $jobs == 1.
-Peff
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
In reply to Jeff KingQuoted 6 lines · Jeff King
I took a look at running each test individually. It's surprisingly quite a bit slower! About 4s instead of 200ms. There's a bit of low-hanging fruit to get it down to ~1.7s (which I'll include in my series). But in the end I punted on that for now, but did add line-number checks. Each expect file just knows its own numbers, and I use a bit of perl to handle the running offset.
By the way, in case you are wondering why I haven't sent out the next iteration of the series: I am stuck trying to figure out some Windows line-ending nonsense.
The chainlint.pl parser chokes on CRLF line endings. So Windows CI produces:
runneradmin@fv-az1390-742 MINGW64 /d/a/git/git/t
# perl chainlint.pl chainlint/for-loop.test 'nternal error scanning character '
(the funny overwrite is because the invalid char is a CR). I tried a few simple things to skip past this error, but the problem is pervasive. We really just want to have perl handle the line endings on read. And doing this works:
# PERLIO=:crlf perl chainlint.pl chainlint/for-loop.test # chainlint: chainlint/for-loop.test
# chainlint: for-loop
[...etc, normal output...]
Which gives me all sorts of questions:
- isn't crlf handling usually the default for perl builds on Windows? I guess this is probably getting into weird mingw vs native Windows distinctions that generally leave me perplexed.
- why wasn't this a problem before? I'm guessing again in the "weird mingw stuff" hand-waving way that when we used "sed" to assemble everything, it stripped the CR's in the "chainlinttmp/tests" file. And in my series, that "cat" is replaced with a perl script (that writes the "tests" and "expect" files together).
- why doesn't "PERLIO=:crlf make check-chainlint" work? It seems that perl spawned from "make" behaves differently. More mingw weirdness?
I'm tempted to just do this:
t/chainlint.pl +1 -1
@@ -779,7 +779,7 @@ sub check_script { while (my $path = $next_script->()) { $nscripts++; my $fh; - unless (open($fh, "<", $path)) { + unless (open($fh, "<:unix:crlf", $path)) { $emit->("?!ERR?! $path: $!\n"); next; }
It feels like a hack, but it makes the parser's assumptions explicit, and it should just work everywhere.
-Peff
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 6 lines · Jeff King
The chainlint.pl parser chokes on CRLF line endings. So Windows CI produces:
runneradmin@fv-az1390-742 MINGW64 /d/a/git/git/t
# perl chainlint.pl chainlint/for-loop.test 'nternal error scanning character '
As far as I understand, chainlint is disabled in the Windows CI. Did you manually re-enable it for testing? Or are you just running it manually in the Windows CI?
Quoted 8 lines
We really just want to have perl handle the line endings on read. And doing this works:
# PERLIO=:crlf perl chainlint.pl chainlint/for-loop.test # chainlint: chainlint/for-loop.test
# chainlint: for-loop
[...etc, normal output...]
Quoted 5 lines
Which gives me all sorts of questions:
- isn't crlf handling usually the default for perl builds on Windows? I guess this is probably getting into weird mingw vs native Windows distinctions that generally leave me perplexed.
Could be. I'm not sure how the Windows CI is provisioned, whether with some native-compiled Perl or with msys2/mingw Perl.
Quoted 5 lines
- why wasn't this a problem before? I'm guessing again in the "weird mingw stuff" hand-waving way that when we used "sed" to assemble everything, it stripped the CR's in the "chainlinttmp/tests" file. And in my series, that "cat" is replaced with a perl script (that writes the "tests" and "expect" files together).
Assuming you manually re-enabled chaintlint in the Windows CI for this testing or are running it manually, it may be the case that chainlint.pl has never been run in the Windows CI. Specifically, chainlint in Windows CI was disabled by a87e427e35 (ci: speed up Windows phase, 2019-01-29) which predates the switchover from chainlint.sed to chainlint.pl by d00113ec34 (t/Makefile: apply chainlint.pl to existing self-tests, 2022-09-01). So, it's quite possible that chainlint.pl has never run in Windows CI. But, perhaps I'm misunderstanding or missing some piece of information.
That said, I did thoroughly test chainlint.pl on Windows using Git For Windows, and it did run in that environment. (But if the Windows CI environment is somehow different, then that might explain the problem?)
Quoted 2 lines
- why doesn't "PERLIO=:crlf make check-chainlint" work? It seems that perl spawned from "make" behaves differently. More mingw weirdness?
That could indeed be an msys2 issue. It will automatically convert colon ":" to semicolon ";" in environment variables since the PATH separator on Windows is ";", not ":" as it is on Unix. Moreover, the ":" to ";" switcheroo logic is not restricted only to PATH since there are other PATH-like variables in common use, so it's applied to all environment variables.
Quoted 10 lines
I'm tempted to just do this:
while (my $path = $next_script->()) { $nscripts++; my $fh;t/chainlint.pl +1
-1- unless (open($fh, "<", $path)) { + unless (open($fh, "<:unix:crlf", $path)) {It feels like a hack, but it makes the parser's assumptions explicit, and it should just work everywhere.
Yep, if this makes it work, then it seems like a good way forward, especially since I don't think there's any obvious way to work around the ":" to ";" switcheroo performed by msys2.
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 11 lines · Eric Sunshine
Quoted 6 lines · Jeff King
The chainlint.pl parser chokes on CRLF line endings. So Windows CI produces:
runneradmin@fv-az1390-742 MINGW64 /d/a/git/git/t
# perl chainlint.pl chainlint/for-loop.test 'nternal error scanning character 'As far as I understand, chainlint is disabled in the Windows CI. Did you manually re-enable it for testing? Or are you just running it manually in the Windows CI?
Neither. As far as I can tell, we still run the "check-chainlint" target as part of "make test", and that's what I saw fail. For instance:
https://github.com/peff/git/actions/runs/9856301557/job/27213352807
Every one of the "win test" jobs failed, with the same outcome: running check-chainlint triggered the "internal scanning error".
Quoted 9 lines
Assuming you manually re-enabled chaintlint in the Windows CI for this testing or are running it manually, it may be the case that chainlint.pl has never been run in the Windows CI. Specifically, chainlint in Windows CI was disabled by
a87e427e35(ci: speed up Windows phase, 2019-01-29) which predates the switchover from chainlint.sed to chainlint.pl byd00113ec34(t/Makefile: apply chainlint.pl to existing self-tests, 2022-09-01). So, it's quite possible that chainlint.pl has never run in Windows CI. But, perhaps I'm misunderstanding or missing some piece of information.
I think that commit would prevent it from running as part of the actual test scripts. But we'd still do check-chainlint to run the chainlint self-tests. And because it only sets "--no-chain-lint" in GIT_TEST_OPTS and not GIT_TEST_CHAIN_LINT=0, I think that the bulk run of chainlint.pl by t/Makefile is still run (and then ironically, when that is run the Makefile manually suppresses the per-script runs, so that --no-chain-lint option is truly doing nothing).
And I think is true even with the ci/run-test-slice.sh approach that the Windows tests use. They still drive it through "make", and just override the $(T) variable.
Quoted 9 lines
Quoted 2 lines
- why doesn't "PERLIO=:crlf make check-chainlint" work? It seems that perl spawned from "make" behaves differently. More mingw weirdness?
That could indeed be an msys2 issue. It will automatically convert colon ":" to semicolon ";" in environment variables since the PATH separator on Windows is ";", not ":" as it is on Unix. Moreover, the ":" to ";" switcheroo logic is not restricted only to PATH since there are other PATH-like variables in common use, so it's applied to all environment variables.
Ah, good thinking. I'm not sure if that's it, though. Just PERLIO=crlf should behave the same way (the ":" is technically a separator, and it is only a style suggestion that you prepend one). Likewise a space is supposed to be OK, too, so PERLIO="unix crlf" should work. But neither seems to work for me. So I'm still puzzled.
Quoted 8 lines
Quoted 8 lines
I'm tempted to just do this:
while (my $path = $next_script->()) { $nscripts++; my $fh;t/chainlint.pl +1
-1- unless (open($fh, "<", $path)) { + unless (open($fh, "<:unix:crlf", $path)) {
Quoted 6 lines
Quoted 2 lines
It feels like a hack, but it makes the parser's assumptions explicit, and it should just work everywhere.
Yep, if this makes it work, then it seems like a good way forward, especially since I don't think there's any obvious way to work around the ":" to ";" switcheroo performed by msys2.
OK, I'll add that to my series, then. The fact that we weren't really _intending_ to run chainlint there makes me tempted to just punt and disable it. But AFAICT we have been running it for a while, and it could benefit people on Windows (though it is a bit funky that we do a full check-chainlint in each slice). And I suspect disabling it reliably might be a trickier change than what I wrote above anyway. ;)
-Peff
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 8 lines · Jeff King
Quoted 6 lines · Eric Sunshine
That could indeed be an msys2 issue. It will automatically convert colon ":" to semicolon ";" in environment variables since the PATH separator on Windows is ";", not ":" as it is on Unix. Moreover, the ":" to ";" switcheroo logic is not restricted only to PATH since there are other PATH-like variables in common use, so it's applied to all environment variables.
Quoted 5 lines
Ah, good thinking. I'm not sure if that's it, though. Just PERLIO=crlf should behave the same way (the ":" is technically a separator, and it is only a style suggestion that you prepend one). Likewise a space is supposed to be OK, too, so PERLIO="unix crlf" should work. But neither seems to work for me. So I'm still puzzled.
Me too. Perhaps Dscho would have more insight(?).
Eric Sunshine
Acked-byRe: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
In reply to Jeff KingQuoted 7 lines · Jeff King
On Tue, Jul 02, 2024 at 07:50:34PM -0400, Eric Sunshine wrote:
I'll post some patches in a moment:[1/3]: chainlint.pl: fix line number reporting
[2/3]: t/chainlint: addtest_expect_successcall to test snippets [3/3]: t/chainlint: add tests for test body in heredoc
Quoted 6 lines
with the idea that we'd apply your patch here on top of what Junio has queued in jk/test-body-in-here-doc, and then these three on top. For Junio's sanity, I'll roll it all up into one series. But I wanted to show it to you incrementally first, especially because I think the fixes from patch 1/3 above should probably just get squashed in (or even rewritten). I'll discuss the bugs they fix below.
Considering the excellent explanation you crafted in your patch, I'd like to say that it should remain separate from mine. However, since you caught the problems in review, it would be irresponsible of us to let my patch into the permanent history as-is. So, feel free to squash your fixes into my patch. Perhaps add a Co-authored-by:? The bit from your [1/3] commit message about incrementing $lineno for the heredoc-body case might be worth squashing in too?
I wrote one minor (perhaps non-actionable) comment in response to patch [3/3]. The patches all looked fine to me, so:
Quoted 8 lines
Quoted 8 lines
t/chainlint.pl +2
-1@@ -232,7 +234,8 @@ sub new { my $self = bless { buff => [], stop => [], - output => [] + output => [], + heredocs => {}, } => $class;
Quoted 8 lines
t/chainlint.pl sub new { · line 241
Quoted 2 lines
t/chainlint.pl +0
-0$self->{lexer} = Lexer->new($self, $s); return $self;I think initializing is not strictly necessary here, since we'd only try to read tags if we saw a here-doc. But there might be some invalid cases where we could convince higher-level code to look for tags even though there were none (and generate a perl warning about trying to dereference undef as a hashref).
You're right, it's not necessary to initialize here, but it feels more consistent to do so. That said, I don't feel strongly either way.
Quoted 5 lines
On the flip side, what about cleaning up? The "heretags" array is emptied as we parse the heredocs in
swallow_heredocs(). But I think once a ShellParser's $self->{heredocs}->{FOO} is written, it will hang around forever (even though it's valid only for that one command). Probably not a big deal, but there's probably some correct spot to reset it.
There are a few reasons I wasn't overly concerned about cleaning up in this case:
(1) The parsers are all short-lived, so the collected heredoc bodies won't stick around long anyhow. For each test checked, a TestParser is created and destroyed. For each script mentioned on the command-line, a ScriptParser is created and destroyed. None of these parsers stick around for long, though, a ScriptParser outlives a TestParser.
(2) The heredoc bodies in question tend to be pretty small, so it's not consuming an inordinate amount of memory even if a single parser latches bodies of multiple heredocs.
(3) We tend to be quite consistent about naming our heredoc tag (i.e. "EOF", "EOT"), so a latched body in the parser's %heredocs hash is very likely to get overwritten, thus the hash is probably not going to eat up a lot of memory. Given the entire test suite, I'd be quite surprised if any one parser ever latches more than three heredoc bodies at a time, and the vast majority of parsers are likely latching zero or one heredoc body.
(4) I couldn't really think of a correct spot to reset %heredocs.
That said, after reading your message, I did try implementing an approach in which the heredoc body gets attached to the << or <<- token. That way, a heredoc body would be cleaned along with its associated lexer token. However, the implementation got too ugly and increased cognitive load too much for my liking, so I abandoned it.
Quoted 10 lines
t/chainlint.pl sub unwrap { · line 627
Quoted 9 lines
sub check_test { my $self = shift @_;t/chainlint.pl +3
-1- my ($title, $body) = map(unwrap, @_); + my $title = unwrap(shift @_); + my $body = unwrap(shift @_); + $body = shift @_ if $body eq '-'; $self->{ntests}++; my $parser = TestParser->new(\$body); my @tokens = $parser->parse();
Quoted 6 lines
This has two problems related to line numbers. You can't see it in the context, but we later do:
my $lineno = $_[1]->[3];Now that we're shifting @_, that array item is gone.
Ugh, this is embarrassing. I did run chainlint.pl on t0600 in which I had intentionally broken some &&-chains, so I saw the output, but somehow I overlooked that it broke the line numbering entirely.
Quoted 7 lines
The second is that the line number for the here-doc is actually one past the initial line number of the
test_expect_success. That works automatically for hanging single-quotes, since the newline from that line is inside the quoted area. But for a here-doc, we have to account for it manually. In my original patch I prepended "\n", but you can also just increment $lineno (which is what I did in the fix I'm about to send).
Nicely spotted. Simply incrementing $lineno does feel a bit hacky, but I agree that it is probably good enough for now; it doesn't seem likely that it will break any time soon. But I also agree with the commentary you wrote in patch [1/3] that it probably would be easy enough to latch the line number of the beginning of the heredoc body and employ that value. That would certainly be more robust.
Quoted 20 lines
Quoted 5 lines
t/chainlint.pl +0
-1@@ -649,8 +654,13 @@ sub parse_cmd { return @tokens unless @tokens && $tokens[0]->[0] =~ /^test_expect_(?:success|failure)$/; my $n = $#tokens; $n-- while $n >= 0 && $tokens[$n]->[0] =~ /^(?:[;&\n|]|&&|\|\|)$/; - $self->check_test($tokens[1], $tokens[2]) if $n == 2; # title bodyt/chainlint.pl sub parse_cmd { · line 665
Quoted 10 lines
t/chainlint.pl +7
-1- $self->check_test($tokens[2], $tokens[3]) if $n > 2; # prereq title body + my $herebody; + if ($n >= 2 && $tokens[$n-1]->[0] eq '-' && $tokens[$n]->[0] =~ /^<<-?(.+)$/) { + $herebody = $self->{heredocs}->{$1}; + $n--; + } + $self->check_test($tokens[1], $tokens[2], $herebody) if $n == 2; # title body + $self->check_test($tokens[2], $tokens[3], $herebody) if $n > 2; # prereq title body return @tokens; }OK, mostly as expected. I think the check for "-" here is redundant with what's in
check_test(). We could just feed the heredoc body either way, and in the nonsense case of:
Quoted 5 lines
test_expect_success'title' 'test body' <<EOT
nobody reads this!
EOTthe heredoc data would just be ignored.
Right. I went back and forth with this, never sure if this code was overkill. On the other hand, we could make this more paranoid and complain if we see either of these cases:
(1) "-" but no heredoc
(2) heredoc present but something other than "-"
Quoted 5 lines
Requiring "<<" at the end is somewhat limiting. E.g. this is valid:
test_expect_success<<EOT 'title' -
the test body
EOT
True, I didn't even think about that.
Quoted 5 lines
I don't expect anybody to do that, but it would be nice to be more robust if we can. I think the tokens are still wrapped at this point, so we could read through all of them looking for "<<" anywhere, without getting confused by "$(cat <<
INNER_HEREDOC)". I think, anyway (I didn't test).
Correct. The stuff inside "$(...)" does get parsed and linted, but by the time ScriptParser::parse_cmd() sees it, $(cat <<INNER_HEREDOC) is just a single (string) token.
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 27 lines · Eric Sunshine
Quoted 5 lines
On the flip side, what about cleaning up? The "heretags" array is emptied as we parse the heredocs in
swallow_heredocs(). But I think once a ShellParser's $self->{heredocs}->{FOO} is written, it will hang around forever (even though it's valid only for that one command). Probably not a big deal, but there's probably some correct spot to reset it.There are a few reasons I wasn't overly concerned about cleaning up in this case:
(1) The parsers are all short-lived, so the collected heredoc bodies won't stick around long anyhow. For each test checked, a TestParser is created and destroyed. For each script mentioned on the command-line, a ScriptParser is created and destroyed. None of these parsers stick around for long, though, a ScriptParser outlives a TestParser.
(2) The heredoc bodies in question tend to be pretty small, so it's not consuming an inordinate amount of memory even if a single parser latches bodies of multiple heredocs.
(3) We tend to be quite consistent about naming our heredoc tag (i.e. "EOF", "EOT"), so a latched body in the parser's %heredocs hash is very likely to get overwritten, thus the hash is probably not going to eat up a lot of memory. Given the entire test suite, I'd be quite surprised if any one parser ever latches more than three heredoc bodies at a time, and the vast majority of parsers are likely latching zero or one heredoc body.
Quoted 1 line
(4) I couldn't really think of a correct spot to reset %heredocs.
All of that makes sense to me, especially (4). :)
Quoted 5 lines
That said, after reading your message, I did try implementing an approach in which the heredoc body gets attached to the
<<or<<-token. That way, a heredoc body would be cleaned along with its associated lexer token. However, the implementation got too ugly and increased cognitive load too much for my liking, so I abandoned it.
OK, thanks for trying. I do think sticking it into the token stream would make sense, but if the implementation got tricky, it is probably not worth the effort. We can always revisit it later if we find some reason that it would be useful to do it that way.
Quoted 8 lines
Quoted 8 lines
OK, mostly as expected. I think the check for "-" here is redundant with what's in
check_test(). We could just feed the heredoc body either way, and in the nonsense case of:
test_expect_success'title' 'test body' <<EOT
nobody reads this!
EOT
Quoted 8 lines
Quoted 1 line
the heredoc data would just be ignored.
Right. I went back and forth with this, never sure if this code was overkill. On the other hand, we could make this more paranoid and complain if we see either of these cases:
(1) "-" but no heredoc
(2) heredoc present but something other than "-"
Those seem like good things to check for, and not too hard to add. I'll see if I can work up some tests.
Quoted 14 lines
Quoted 5 lines
Requiring "<<" at the end is somewhat limiting. E.g. this is valid:
test_expect_success<<EOT 'title' -
the test body
EOTTrue, I didn't even think about that.
Quoted 5 lines
I don't expect anybody to do that, but it would be nice to be more robust if we can. I think the tokens are still wrapped at this point, so we could read through all of them looking for "<<" anywhere, without getting confused by "$(cat <<
INNER_HEREDOC)". I think, anyway (I didn't test).
Quoted 3 lines
Correct. The stuff inside "$(...)" does get parsed and linted, but by the time
ScriptParser::parse_cmd()sees it,$(cat <<INNER_HEREDOC)is just a single (string) token.
OK, I'll see if I can generalize it a bit (and add a test).
-Peff
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 8 lines · Jeff King
Quoted 7 lines · Eric Sunshine
(3) We tend to be quite consistent about naming our heredoc tag (i.e. "EOF", "EOT"), so a latched body in the parser's %heredocs hash is very likely to get overwritten, thus the hash is probably not going to eat up a lot of memory. Given the entire test suite, I'd be quite surprised if any one parser ever latches more than three heredoc bodies at a time, and the vast majority of parsers are likely latching zero or one heredoc body.
One thing we may want to measure is how much extra time we're wasting for the (very) common case of latching heredoc bodies only to then ignore them. In particular, we may want to add a flag to ShellParser telling it whether or not to latch heredoc bodies, and enable that flag in subclass ScriptParser, but leave it disabled in subclass TestParser since only ScriptParser currently cares about the heredoc body.
Quoted 10 lines
Quoted 1 line
(4) I couldn't really think of a correct spot to reset %heredocs.
All of that makes sense to me, especially (4). :)
Quoted 5 lines
That said, after reading your message, I did try implementing an approach in which the heredoc body gets attached to the
<<or<<-token. That way, a heredoc body would be cleaned along with its associated lexer token. However, the implementation got too ugly and increased cognitive load too much for my liking, so I abandoned it.
Quoted 4 lines
OK, thanks for trying. I do think sticking it into the token stream would make sense, but if the implementation got tricky, it is probably not worth the effort. We can always revisit it later if we find some reason that it would be useful to do it that way.
In the long run, I think we probably want to build a full parse tree, attach relevant information (such as a heredoc body) to each node, and then walk the tree, rather than trying to perform on-the-fly lints and other operations on the token stream as is currently the case.
This encapsulation would not only solve the problem of releasing related resources (such as releasing the heredoc body when the << or <<- node is released), but it would also make it possible to perform other lints I've had in mind. For instance, a while ago, I added (but did not submit) a lint to check for cd outside of a subshell. After implementing that, I realized that the cd-outside-subshell lint would be useful, not just within test bodies, but also at the script level itself. However, because actual linting functionality resides entirely in TestParser, I wasn't able to reuse the code for detecting cd-outside-subshell at the script level, and ended up having to write duplicate linting code in ScriptParser. If, on the other hand, the linting code was just handed a parse tree, then it wouldn't matter if that parse tree came from parsing a test body or parsing a script.
All (or most) of the checks in t/check-non-portable-shell.pl could also be incorporated into chainlint.pl (though that makes the name "chainlint.pl" even more of an anachronism than it already is since it outgrew "chain linting" when it starting checking for missing || return, if not before then.)
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 7 lines · Eric Sunshine
One thing we may want to measure is how much extra time we're wasting for the (very) common case of latching heredoc bodies only to then ignore them. In particular, we may want to add a flag to ShellParser telling it whether or not to latch heredoc bodies, and enable that flag in subclass ScriptParser, but leave it disabled in subclass TestParser since only ScriptParser currently cares about the heredoc body.
I doubt it's much to hold on to a few extra small buffers. But it should be easy to measure. Here are hyperfine results for checking all of our test scripts both before (old.pl) and after (new.pl) your chainlint.pl, with threading disabled:
Benchmark 1: perl old.pl t[0-9]*.sh
Time (mean ± σ): 4.215 s ± 0.052 s [User: 4.187 s, System: 0.028 s]
Range (min … max): 4.124 s … 4.288 s 10 runsBenchmark 2: perl new.pl t[0-9]*.sh
Time (mean ± σ): 4.295 s ± 0.060 s [User: 4.264 s, System: 0.031 s]
Range (min … max): 4.229 s … 4.419 s 10 runsSummary
perl old.pl t[0-9]*.sh ran
1.02 ± 0.02 times faster than perl new.pl t[0-9]*.shSo it does seem to make a small difference, but we're within the noise.
Quoted 5 lines
In the long run, I think we probably want to build a full parse tree, attach relevant information (such as a heredoc body) to each node, and then walk the tree, rather than trying to perform on-the-fly lints and other operations on the token stream as is currently the case. [...]
Yeah, all of that sounds very sensible long term, but probably not worth worrying about for this topic.
-Peff
Re: [PATCH] chainlint.pl: recognize test bodies defined via heredoc
Quoted 10 lines · Jeff King
Quoted 7 lines · Eric Sunshine
One thing we may want to measure is how much extra time we're wasting for the (very) common case of latching heredoc bodies only to then ignore them. In particular, we may want to add a flag to ShellParser telling it whether or not to latch heredoc bodies, and enable that flag in subclass ScriptParser, but leave it disabled in subclass TestParser since only ScriptParser currently cares about the heredoc body.
I doubt it's much to hold on to a few extra small buffers.
I was more concerned about the extra substr() consuming additional CPU time and inflating wall-clock time.
Quoted 1 line
So it does seem to make a small difference, but we're within the noise.
Okay. Thanks for measuring.
Quoted 8 lines
Quoted 5 lines
In the long run, I think we probably want to build a full parse tree, attach relevant information (such as a heredoc body) to each node, and then walk the tree, rather than trying to perform on-the-fly lints and other operations on the token stream as is currently the case. [...]
Yeah, all of that sounds very sensible long term, but probably not worth worrying about for this topic.
Agreed.
v2 cover here-doc test bodies (now with 100% more chainlinting)
In reply to Jeff KingQuoted 11 lines · Jeff King
This is a re-post of an idea from 2021:
https://lore.kernel.org/git/[email protected]/
that people seemed mostly positive on, and I just never got around to following up. Mostly because it's not life-changing, but I think it is a small quality of life improvement, and it came up again recently in:
https://lore.kernel.org/git/[email protected]/
So I thought it was worth considering again.
And here's a v2 that addresses the chainlint issue mentioned by Eric. There were a lot of patches flying around, but this is only the second posting of the whole topic. This can replace all of what's in jk/test-body-in-here-doc.
I bailed on trying to notice:
test_expect_success 'oops, forgot the dash' <<\EOT
or:
test_expect_success 'oops, forgot the here doc' -
or:
test_expect_success <<\EOT 'here-doc tag comes first' -
As those all require some big refactoring ScriptParser::check_test(), etc, and this topic has already grown quite a lot.
I won't bother with a range diff; patches 8 and 9 are just the original v1 patches verbatim, and everything else is new.
[1/9]: chainlint.pl: add test_expect_success call to test snippets
Test refactoring for chainlint before we change it.
[2/9]: chainlint.pl: only start threads if jobs > 1 [3/9]: chainlint.pl: do not spawn more threads than we have scripts
These two aren't strictly necessary, but some easy speedups I hit along the way (they depend on patch 1 for showing the speedup).
[4/9]: chainlint.pl: force CRLF conversion when opening input files [5/9]: chainlint.pl: check line numbers in expected output
These two make the chainlint tests more robust against the line-number bugs we hit while developing patch 6.
[6/9]: chainlint.pl: recognize test bodies defined via heredoc
This is Eric's fix (thanks!) for chainlint to recognize the new format, including the line-number fixes that we discussed.
[7/9]: chainlint.pl: add tests for test body in heredoc
And then I kept my tests of the new feature split into their own commit.
[8/9]: test-lib: allow test snippets as here-docs [9/9]: t: convert some here-doc test bodies
And then this is the actual purpose of the series. ;)
t/Makefile | 16 +- t/README | 8 + t/chainlint-cat.pl | 29 +++ t/chainlint.pl | 33 ++- t/chainlint/arithmetic-expansion.expect | 18 +- t/chainlint/arithmetic-expansion.test | 2 + t/chainlint/bash-array.expect | 20 +- t/chainlint/bash-array.test | 2 + t/chainlint/blank-line-before-esac.expect | 36 ++-- t/chainlint/blank-line-before-esac.test | 2 + t/chainlint/blank-line.expect | 16 +- t/chainlint/blank-line.test | 2 + t/chainlint/block-comment.expect | 16 +- t/chainlint/block-comment.test | 2 + t/chainlint/block.expect | 46 ++-- t/chainlint/block.test | 2 + t/chainlint/broken-chain.expect | 12 +- t/chainlint/broken-chain.test | 2 + t/chainlint/case-comment.expect | 22 +- t/chainlint/case-comment.test | 2 + t/chainlint/case.expect | 38 ++-- t/chainlint/case.test | 2 + t/chainlint/chain-break-background.expect | 18 +- t/chainlint/chain-break-background.test | 2 + t/chainlint/chain-break-continue.expect | 24 +-- t/chainlint/chain-break-continue.test | 2 + t/chainlint/chain-break-false.expect | 18 +- t/chainlint/chain-break-false.test | 2 + t/chainlint/chain-break-return-exit.expect | 38 ++-- t/chainlint/chain-break-return-exit.test | 2 + t/chainlint/chain-break-status.expect | 18 +- t/chainlint/chain-break-status.test | 2 + t/chainlint/chained-block.expect | 18 +- t/chainlint/chained-block.test | 2 + t/chainlint/chained-subshell.expect | 20 +- t/chainlint/chained-subshell.test | 2 + .../close-nested-and-parent-together.expect | 6 +- .../close-nested-and-parent-together.test | 2 + t/chainlint/close-subshell.expect | 52 ++--- t/chainlint/close-subshell.test | 2 + .../command-substitution-subsubshell.expect | 4 +- .../command-substitution-subsubshell.test | 2 + t/chainlint/command-substitution.expect | 18 +- t/chainlint/command-substitution.test | 2 + t/chainlint/comment.expect | 16 +- t/chainlint/comment.test | 2 + t/chainlint/complex-if-in-cuddled-loop.expect | 18 +- t/chainlint/complex-if-in-cuddled-loop.test | 2 + t/chainlint/cuddled-if-then-else.expect | 12 +- t/chainlint/cuddled-if-then-else.test | 2 + t/chainlint/cuddled-loop.expect | 8 +- t/chainlint/cuddled-loop.test | 2 + t/chainlint/cuddled.expect | 34 +-- t/chainlint/cuddled.test | 2 + t/chainlint/double-here-doc.expect | 24 +-- t/chainlint/double-here-doc.test | 2 + t/chainlint/dqstring-line-splice.expect | 10 +- t/chainlint/dqstring-line-splice.test | 2 + t/chainlint/dqstring-no-interpolate.expect | 24 +-- t/chainlint/dqstring-no-interpolate.test | 2 + t/chainlint/empty-here-doc.expect | 8 +- t/chainlint/empty-here-doc.test | 2 + t/chainlint/exclamation.expect | 8 +- t/chainlint/exclamation.test | 2 + t/chainlint/exit-loop.expect | 48 ++--- t/chainlint/exit-loop.test | 2 + t/chainlint/exit-subshell.expect | 10 +- t/chainlint/exit-subshell.test | 2 + t/chainlint/for-loop-abbreviated.expect | 10 +- t/chainlint/for-loop-abbreviated.test | 2 + t/chainlint/for-loop.expect | 28 +-- t/chainlint/for-loop.test | 2 + t/chainlint/function.expect | 22 +- t/chainlint/function.test | 2 + t/chainlint/here-doc-body-indent.expect | 2 + t/chainlint/here-doc-body-indent.test | 4 + t/chainlint/here-doc-body-pathological.expect | 7 + t/chainlint/here-doc-body-pathological.test | 9 + t/chainlint/here-doc-body.expect | 7 + t/chainlint/here-doc-body.test | 9 + t/chainlint/here-doc-close-subshell.expect | 8 +- t/chainlint/here-doc-close-subshell.test | 2 + t/chainlint/here-doc-double.expect | 2 + t/chainlint/here-doc-double.test | 10 + t/chainlint/here-doc-indent-operator.expect | 22 +- t/chainlint/here-doc-indent-operator.test | 2 + .../here-doc-multi-line-command-subst.expect | 16 +- .../here-doc-multi-line-command-subst.test | 2 + t/chainlint/here-doc-multi-line-string.expect | 14 +- t/chainlint/here-doc-multi-line-string.test | 2 + t/chainlint/here-doc.expect | 50 ++--- t/chainlint/here-doc.test | 2 + t/chainlint/if-condition-split.expect | 14 +- t/chainlint/if-condition-split.test | 2 + t/chainlint/if-in-loop.expect | 24 +-- t/chainlint/if-in-loop.test | 2 + t/chainlint/if-then-else.expect | 44 ++-- t/chainlint/if-then-else.test | 2 + t/chainlint/incomplete-line.expect | 20 +- t/chainlint/incomplete-line.test | 2 + t/chainlint/inline-comment.expect | 16 +- t/chainlint/inline-comment.test | 2 + t/chainlint/loop-detect-failure.expect | 30 +-- t/chainlint/loop-detect-failure.test | 2 + t/chainlint/loop-detect-status.expect | 36 ++-- t/chainlint/loop-detect-status.test | 2 + t/chainlint/loop-in-if.expect | 24 +-- t/chainlint/loop-in-if.test | 2 + t/chainlint/loop-upstream-pipe.expect | 20 +- t/chainlint/loop-upstream-pipe.test | 2 + ...ti-line-nested-command-substitution.expect | 36 ++-- ...ulti-line-nested-command-substitution.test | 2 + t/chainlint/multi-line-string.expect | 28 +-- t/chainlint/multi-line-string.test | 2 + t/chainlint/negated-one-liner.expect | 10 +- t/chainlint/negated-one-liner.test | 2 + t/chainlint/nested-cuddled-subshell.expect | 50 ++--- t/chainlint/nested-cuddled-subshell.test | 2 + t/chainlint/nested-here-doc.expect | 60 +++--- t/chainlint/nested-here-doc.test | 2 + t/chainlint/nested-loop-detect-failure.expect | 62 +++--- t/chainlint/nested-loop-detect-failure.test | 2 + t/chainlint/nested-subshell-comment.expect | 22 +- t/chainlint/nested-subshell-comment.test | 2 + t/chainlint/nested-subshell.expect | 26 +-- t/chainlint/nested-subshell.test | 2 + t/chainlint/not-heredoc.expect | 28 +-- t/chainlint/not-heredoc.test | 2 + t/chainlint/one-liner-for-loop.expect | 18 +- t/chainlint/one-liner-for-loop.test | 2 + t/chainlint/one-liner.expect | 18 +- t/chainlint/one-liner.test | 2 + t/chainlint/p4-filespec.expect | 8 +- t/chainlint/p4-filespec.test | 2 + t/chainlint/pipe.expect | 20 +- t/chainlint/pipe.test | 2 + t/chainlint/return-loop.expect | 10 +- t/chainlint/return-loop.test | 2 + t/chainlint/semicolon.expect | 38 ++-- t/chainlint/semicolon.test | 2 + t/chainlint/sqstring-in-sqstring.expect | 8 +- t/chainlint/sqstring-in-sqstring.test | 2 + t/chainlint/subshell-here-doc.expect | 60 +++--- t/chainlint/subshell-here-doc.test | 2 + t/chainlint/subshell-one-liner.expect | 38 ++-- t/chainlint/subshell-one-liner.test | 2 + t/chainlint/t7900-subtree.expect | 44 ++-- t/chainlint/t7900-subtree.test | 2 + t/chainlint/token-pasting.expect | 54 ++--- t/chainlint/token-pasting.test | 2 + t/chainlint/unclosed-here-doc-indent.expect | 8 +- t/chainlint/unclosed-here-doc-indent.test | 2 + t/chainlint/unclosed-here-doc.expect | 14 +- t/chainlint/unclosed-here-doc.test | 2 + t/chainlint/while-loop.expect | 28 +-- t/chainlint/while-loop.test | 2 + t/t0600-reffiles-backend.sh | 38 ++-- t/t1404-update-ref-errors.sh | 196 +++++++++--------- t/test-lib-functions.sh | 32 ++- 159 files changed, 1285 insertions(+), 1025 deletions(-) create mode 100644 t/chainlint-cat.pl create mode 100644 t/chainlint/here-doc-body-indent.expect create mode 100644 t/chainlint/here-doc-body-indent.test create mode 100644 t/chainlint/here-doc-body-pathological.expect create mode 100644 t/chainlint/here-doc-body-pathological.test create mode 100644 t/chainlint/here-doc-body.expect create mode 100644 t/chainlint/here-doc-body.test create mode 100644 t/chainlint/here-doc-double.expect create mode 100644 t/chainlint/here-doc-double.test
PATCH v2 1/9 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.
--- t/Makefile | 4 +--- t/chainlint/arithmetic-expansion.test | 2 ++ t/chainlint/bash-array.test | 2 ++ t/chainlint/blank-line-before-esac.test | 2 ++ t/chainlint/blank-line.test | 2 ++ t/chainlint/block-comment.test | 2 ++ t/chainlint/block.test | 2 ++ t/chainlint/broken-chain.test | 2 ++ t/chainlint/case-comment.test | 2 ++ t/chainlint/case.test | 2 ++ t/chainlint/chain-break-background.test | 2 ++ t/chainlint/chain-break-continue.test | 2 ++ t/chainlint/chain-break-false.test | 2 ++ t/chainlint/chain-break-return-exit.test | 2 ++ t/chainlint/chain-break-status.test | 2 ++ t/chainlint/chained-block.test | 2 ++ t/chainlint/chained-subshell.test | 2 ++ t/chainlint/close-nested-and-parent-together.test | 2 ++ t/chainlint/close-subshell.test | 2 ++ t/chainlint/command-substitution-subsubshell.test | 2 ++ t/chainlint/command-substitution.test | 2 ++ t/chainlint/comment.test | 2 ++ t/chainlint/complex-if-in-cuddled-loop.test | 2 ++ t/chainlint/cuddled-if-then-else.test | 2 ++ t/chainlint/cuddled-loop.test | 2 ++ t/chainlint/cuddled.test | 2 ++ t/chainlint/double-here-doc.test | 2 ++ t/chainlint/dqstring-line-splice.test | 2 ++ t/chainlint/dqstring-no-interpolate.test | 2 ++ t/chainlint/empty-here-doc.test | 2 ++ t/chainlint/exclamation.test | 2 ++ t/chainlint/exit-loop.test | 2 ++ t/chainlint/exit-subshell.test | 2 ++ t/chainlint/for-loop-abbreviated.test | 2 ++ t/chainlint/for-loop.test | 2 ++ t/chainlint/function.test | 2 ++ t/chainlint/here-doc-close-subshell.test | 2 ++ t/chainlint/here-doc-indent-operator.test | 2 ++ t/chainlint/here-doc-multi-line-command-subst.test | 2 ++ t/chainlint/here-doc-multi-line-string.test | 2 ++ t/chainlint/here-doc.test | 2 ++ t/chainlint/if-condition-split.test | 2 ++ t/chainlint/if-in-loop.test | 2 ++ t/chainlint/if-then-else.test | 2 ++ t/chainlint/incomplete-line.test | 2 ++ t/chainlint/inline-comment.test | 2 ++ t/chainlint/loop-detect-failure.test | 2 ++ t/chainlint/loop-detect-status.test | 2 ++ t/chainlint/loop-in-if.test | 2 ++ t/chainlint/loop-upstream-pipe.test | 2 ++ t/chainlint/multi-line-nested-command-substitution.test | 2 ++ t/chainlint/multi-line-string.test | 2 ++ t/chainlint/negated-one-liner.test | 2 ++ t/chainlint/nested-cuddled-subshell.test | 2 ++ t/chainlint/nested-here-doc.test | 2 ++ t/chainlint/nested-loop-detect-failure.test | 2 ++ t/chainlint/nested-subshell-comment.test | 2 ++ t/chainlint/nested-subshell.test | 2 ++ t/chainlint/not-heredoc.test | 2 ++ t/chainlint/one-liner-for-loop.test | 2 ++ t/chainlint/one-liner.test | 2 ++ t/chainlint/p4-filespec.test | 2 ++ t/chainlint/pipe.test | 2 ++ t/chainlint/return-loop.test | 2 ++ t/chainlint/semicolon.test | 2 ++ t/chainlint/sqstring-in-sqstring.test | 2 ++ t/chainlint/subshell-here-doc.test | 2 ++ t/chainlint/subshell-one-liner.test | 2 ++ t/chainlint/t7900-subtree.test | 2 ++ t/chainlint/token-pasting.test | 2 ++ t/chainlint/unclosed-here-doc-indent.test | 2 ++ t/chainlint/unclosed-here-doc.test | 2 ++ t/chainlint/while-loop.test | 2 ++ 73 files changed, 145 insertions(+), 3 deletions(-)
t/Makefile +1 -3
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 } +'
t/chainlint/blank-line.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'blank-line' ' ( nothing &&
@@ -8,3 +9,4 @@ ) +'
t/chainlint/block-comment.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'block-comment' ' ( { # show a
@@ -6,3 +7,4 @@ echo b } ) +'
t/chainlint/block.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'block' ' ( # LINT: missing "&&" after first "echo" foo &&
@@ -25,3 +26,4 @@ echo "done" } && finis +'
t/chainlint/broken-chain.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'broken-chain' ' ( foo && # LINT: missing "&&" from "bar"
@@ -6,3 +7,4 @@ # LINT: final statement before closing ")" legitimately lacks "&&" wop ) +'
t/chainlint/case-comment.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'case-comment' ' ( case "$x" in # found foo
@@ -9,3 +10,4 @@ ;; esac ) +'
t/chainlint/case.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'case' ' ( # LINT: "...)" arms in "case" not misinterpreted as subshell-closing ")" case "$x" in
@@ -21,3 +22,4 @@ case "$y" in 2) false;; esac foobar ) +'
t/chainlint/chain-break-background.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'chain-break-background' ' JGIT_DAEMON_PID= && git init --bare empty.git && >empty.git/git-daemon-export-ok &&
@@ -8,3 +9,4 @@ mkfifo jgit_daemon_output && JGIT_DAEMON_PID=$! } && test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git +'
t/chainlint/chain-break-continue.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'chain-break-continue' ' git ls-tree --name-only -r refs/notes/many_notes | while read path do
@@ -11,3 +12,4 @@ do return 1 fi done +'
t/chainlint/chain-break-false.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'chain-break-false' ' # LINT: broken &&-chain okay if explicit "false" signals failure if condition not satisified then
@@ -8,3 +9,4 @@ else echo it went okay congratulate user fi +'
t/chainlint/chain-break-return-exit.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'chain-break-return-exit' ' case "$(git ls-files)" in one) echo pass one ;; # LINT: broken &&-chain okay if explicit "return 1" signals failuire
@@ -21,3 +22,4 @@ for i in 1 2 3 4 ; do git checkout main -b $i || return $? test_commit $i $i $i tag$i || return $? done +'
t/chainlint/chain-break-status.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'chain-break-status' ' # LINT: broken &&-chain okay if next command handles "$?" explicitly OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" &&
@@ -9,3 +10,4 @@ test_match_signal 13 "$OUT" && test "$ret" = 3 } && test_cmp expect actual +'
t/chainlint/chained-block.test +2 -0
@@ -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 -0
@@ -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) +'
t/chainlint/close-nested-and-parent-together.test +2 -0
@@ -1,3 +1,5 @@ +test_expect_success 'close-nested-and-parent-together' ' (cd foo && (bar && baz)) +'
t/chainlint/close-subshell.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'close-subshell' ' # LINT: closing ")" with various decorations ("&&", ">", "|", etc.) ( foo
@@ -25,3 +26,4 @@ fuzzle && ( yop ) +'
t/chainlint/command-substitution-subsubshell.test +2 -0
@@ -1,3 +1,5 @@ +test_expect_success 'command-substitution-subsubshell' ' # LINT: subshell nested in subshell nested in command substitution OUT=$( ((large_git 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" +'
t/chainlint/command-substitution.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'command-substitution' ' ( foo && # LINT: closing ")" of $(...) not misinterpreted as subshell-closing ")"
@@ -9,3 +10,4 @@ bar=$(gobble blocks) baz ) +'
t/chainlint/comment.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'comment' ' ( # LINT: swallow comment lines # comment 1
@@ -9,3 +10,4 @@ # comment 3 # comment 4 ) +'
t/chainlint/complex-if-in-cuddled-loop.test +2 -0
@@ -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 -0
@@ -1,7 +1,9 @@ +test_expect_success 'cuddled-if-then-else' ' # LINT: "if" cuddled with "(" and ")"; indented with spaces, not tabs (if test -z ""; then echo empty else echo bizzy fi) && echo foobar +'
t/chainlint/cuddled-loop.test +2 -0
@@ -1,7 +1,9 @@ +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 ( while read x do foobar bop || exit 1 done <file ) && outside subshell +'
t/chainlint/cuddled.test +2 -0
@@ -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 -0
@@ -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 -0
@@ -1,7 +1,9 @@ +test_expect_success 'dqstring-line-splice' ' # LINT: line-splice within DQ-string '" echo 'fatal: reword option of --fixup is mutually exclusive with'\ '--patch/--interactive/--all/--include/--only' >expect && test_must_fail git commit --fixup=reword:HEAD~ $1 2>actual && test_cmp expect actual "' +'
t/chainlint/dqstring-no-interpolate.test +2 -0
@@ -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 "' +'
t/chainlint/empty-here-doc.test +2 -0
@@ -1,5 +1,7 @@ +test_expect_success 'empty-here-doc' ' git ls-tree $tree path >current && # LINT: empty here-doc cat >expected <<\EOF && EOF test_output +'
t/chainlint/exclamation.test +2 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 +'
t/chainlint/here-doc-multi-line-command-subst.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'here-doc-multi-line-command-subst' ' ( # LINT: line contains here-doc and opens multi-line $(...) x=$(bobble <<-\END &&
@@ -7,3 +8,4 @@ wiffle) echo $x ) +'
t/chainlint/here-doc-multi-line-string.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'here-doc-multi-line-string' ' ( # LINT: line contains here-doc and opens multi-line string cat <<-\TXT && echo "multi-line
@@ -6,3 +7,4 @@ TXT bap ) +'
t/chainlint/here-doc.test +2 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -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 -0
@@ -1,3 +1,4 @@ +test_expect_success 'loop-in-if' ' ( if true then
@@ -13,3 +14,4 @@ fi bar ) +'
t/chainlint/loop-upstream-pipe.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'loop-upstream-pipe' ' ( git rev-list --objects --no-object-names base..loose | while read oid
@@ -9,3 +10,4 @@ done | sort -k1 ) >expect && +'
t/chainlint/multi-line-nested-command-substitution.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'multi-line-nested-command-substitution' ' ( foo && x=$(
@@ -16,3 +17,4 @@ sort && fip) && echo fail ) +'
t/chainlint/multi-line-string.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'multi-line-string' ' ( x="line 1 line 2
@@ -13,3 +14,4 @@ ghi" && barfoo ) +'
t/chainlint/negated-one-liner.test +2 -0
@@ -1,7 +1,9 @@ +test_expect_success 'negated-one-liner' ' # LINT: top-level one-liner subshell ! (foo && bar) && ! (foo && bar) >baz && # LINT: top-level one-liner subshell missing internal "&&" ! (foo; bar) && ! (foo; bar) >baz +'
t/chainlint/nested-cuddled-subshell.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'nested-cuddled-subshell' ' ( # LINT: opening "(" cuddled with first nested subshell statement (cd foo &&
@@ -29,3 +30,4 @@ foobar ) +'
t/chainlint/nested-here-doc.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'nested-here-doc' ' # LINT: inner "EOF" not misintrepreted as closing ARBITRARY here-doc cat <<ARBITRARY >foop && naddle
@@ -31,3 +32,4 @@ ARBITRARY foobar ) +'
t/chainlint/nested-loop-detect-failure.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'nested-loop-detect-failure' ' # LINT: neither loop handles failure explicitly with "|| return 1" for i in 0 1 2 3 4 5 6 7 8 9; do
@@ -33,3 +34,4 @@ do echo "$i$j" >"path$i$j" || return 1 done || return 1 done +'
t/chainlint/nested-subshell-comment.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'nested-subshell-comment' ' ( foo && (
@@ -11,3 +12,4 @@ ) fuzzy ) +'
t/chainlint/nested-subshell.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'nested-subshell' ' ( cd foo && (
@@ -11,3 +12,4 @@ echo b ) >file ) +'
t/chainlint/not-heredoc.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'not-heredoc' ' # LINT: "<< ours" inside string is not here-doc echo "<<<<<<< ours" && echo ourside &&
@@ -14,3 +15,4 @@ echo ">>>>>>> theirs" && echo ">>>>>>> theirs" poodle ) >merged +'
t/chainlint/one-liner-for-loop.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'one-liner-for-loop' ' git init dir-rename-and-content && ( cd dir-rename-and-content &&
@@ -8,3 +9,4 @@ git init dir-rename-and-content && git add foo olddir && git commit -m "original" && ) +'
t/chainlint/one-liner.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'one-liner' ' # LINT: top-level one-liner subshell (foo && bar) && (foo && bar) |
@@ -10,3 +11,4 @@ # LINT: ";" in string not misinterpreted as broken &&-chain (foo "bar; baz") +'
t/chainlint/p4-filespec.test +2 -0
@@ -1,5 +1,7 @@ +test_expect_success 'p4-filespec' ' ( # LINT: Perforce revspec in filespec not misinterpreted as in-line comment p4 print -1 //depot/fiddle#42 >file && foobar ) +'
t/chainlint/pipe.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'pipe' ' ( # LINT: no "&&" needed on line ending with "|" foo |
@@ -10,3 +11,4 @@ sunder ) +'
t/chainlint/return-loop.test +2 -0
@@ -1,6 +1,8 @@ +test_expect_success 'return-loop' ' while test $i -lt $((num - 5)) do # LINT: "|| return {n}" valid loop escape outside subshell; no "&&" needed git notes add -m "notes for commit$i" HEAD~$i || return 1 i=$((i + 1)) done +'
t/chainlint/semicolon.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'semicolon' ' ( # LINT: missing internal "&&" and ending "&&" cat foo ; echo bar
@@ -23,3 +24,4 @@ # LINT: semicolon unnecessary but legitimate echo; done) +'
t/chainlint/sqstring-in-sqstring.test +2 -0
@@ -1,5 +1,7 @@ +test_expect_success 'sqstring-in-sqstring' ' # LINT: SQ-string Perl code fragment within SQ-string perl -e '\'' defined($_ = -s $_) or die for @ARGV; exit 1 if $ARGV[0] <= $ARGV[1]; '\'' test-2-$packname_2.pack test-3-$packname_3.pack +'
t/chainlint/subshell-here-doc.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'subshell-here-doc' ' ( # LINT: stitch together incomplete \-ending lines # LINT: swallow here-doc to avoid false positives in content
@@ -33,3 +34,4 @@ EOF ARBITRARY3 meep ) +'
t/chainlint/subshell-one-liner.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 'subshell-one-liner' ' ( # LINT: nested one-liner subshell (foo && bar) &&
@@ -22,3 +23,4 @@ foobar ) +'
t/chainlint/t7900-subtree.test +2 -0
@@ -1,3 +1,4 @@ +test_expect_success 't7900-subtree' ' ( chks="sub1 sub2
@@ -20,3 +21,4 @@ TXT check_equal "$subfiles" "$chkms $chks" ) +'
t/chainlint/token-pasting.test +2 -0
@@ -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 -0
@@ -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 -0
@@ -1,7 +1,9 @@ +test_expect_success 'unclosed-here-doc' ' command_which_is_run && cat >expect <<\EOF && we try to end the here-doc below, but the indentation throws us off since the operator is not "<<-". EOF command_which_is_gobbled +'
t/chainlint/while-loop.test +2 -0
@@ -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 ) +'
Signature · 1 line
2.45.2.1249.gb036353db5
PATCH v2 2/9 chainlint.pl: only start threads if jobs > 1
In reply to Jeff KingIf the system supports threads, chainlint.pl will always spawn worker threads to do the real work. But when --jobs=1, this is pointless, since we could just do the work in the main thread. And spawning even a single thread has a high overhead. For example, on my Linux system, running:
for i in chainlint/*.test; do
perl chainlint.pl --jobs=1 $i
done >/dev/null
takes ~1.7s without this patch, and ~1.1s after. We don't usually spawn a bunch of individual chainlint.pl processes (instead we feed several scripts at once, and the parallelism outweighs the setup cost). But it's something we've considered doing, and since we already have fallback code for systems without thread support, it's pretty easy to make this work.
--- t/chainlint.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
t/chainlint.pl +2 -1
@@ -807,7 +807,8 @@ sub exit_code { exit; } -unless ($Config{useithreads} && eval { +unless ($jobs > 1 && + $Config{useithreads} && eval { require threads; threads->import(); require Thread::Queue; Thread::Queue->import(); 1;
Signature · 1 line
2.45.2.1249.gb036353db5
PATCH v2 3/9 chainlint.pl: do not spawn more threads than we have scripts
In reply to Jeff KingThe chainlint.pl script spawns worker threads to check many scripts in parallel. This is good if you feed it a lot of scripts. But if you give it few (or one), then the overhead of spawning the threads dominates. We can easily notice that we have fewer scripts than threads and scale back as appropriate.
This patch reduces the time to run:
time for i in chainlint/*.test; do
perl chainlint.pl $i
done >/dev/null
on my system from ~4.1s to ~1.1s, where I have 8+8 cores.
As with the previous patch, this isn't the usual way we run chainlint (we feed many scripts at once, which is why it supports threading in the first place). So this won't make a big difference in the real world, but it may help us out in the future, and it makes experimenting with and debugging the chainlint tests a bit more pleasant.
--- t/chainlint.pl | 1 + 1 file changed, 1 insertion(+)
t/chainlint.pl +1 -0
@@ -806,6 +806,7 @@ sub exit_code { show_stats($start_time, \@stats) if $show_stats; exit; } +$jobs = @scripts if @scripts < $jobs; unless ($jobs > 1 && $Config{useithreads} && eval {
Signature · 1 line
2.45.2.1249.gb036353db5
PATCH v2 4/9 chainlint.pl: force CRLF conversion when opening input files
In reply to Jeff KingThe lexer in chainlint.pl can't handle CRLF line endings; it complains about an internal error in scan_token() if we see one. For example, in our Windows CI environment:
$ perl chainlint.pl chainlint/for-loop.test | cat -v Thread 2 terminated abnormally: internal error scanning character '^M'
This doesn't break "make check-chainlint" (yet), because we assemble a concatenated input by passing the contents of each file through "sed". And the "sed" we use will strip out the CRLFs. But the next patch is going to rework this a bit, which does break check-chainlint on Windows. Plus it's probably nicer to folks on Windows who might work on chainlint itself and write new tests.
In theory we could fix the parser to handle this, but it's not really worth the trouble. We should be able to ask the input layer to translate the line endings for us. In fact, I'd expect this to happen by default, as perl's documentation claims Win32 uses the ":unix:crlf" PERLIO layer by default ("unix" here just refers to using read/write syscalls, and then "crlf" layers the translation on top). However, this doesn't seem to be the case in our Windows CI environment. I didn't dig into the exact reason, but it is perhaps because we are using an msys build of perl rather than a "true" Win32 build.
At any rate, it is easy-ish to just ask explicitly for the conversion. In the above example, setting PERLIO=crlf in the environment is enough to make it work. Curiously, though, this doesn't work when invoking chainlint via "make". Again, I didn't dig into it, but it may have to do with msys programs calling Windows programs or vice versa.
We can make it work consistently by just explicitly asking for CRLF translation when we open the files. This will even work on non-Windows platforms, though we wouldn't really expect to find CRLF files there.
--- t/chainlint.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/chainlint.pl +1 -1
@@ -762,7 +762,7 @@ sub check_script { while (my $path = $next_script->()) { $nscripts++; my $fh; - unless (open($fh, "<", $path)) { + unless (open($fh, "<:unix:crlf", $path)) { $emit->("?!ERR?! $path: $!\n"); next; }
Signature · 1 line
2.45.2.1249.gb036353db5
PATCH v2 5/9 chainlint.pl: check line numbers in expected output
In reply to Jeff KingWhile working on chainlint.pl recently, we introduced some bugs that showed incorrect line numbers in the output. But it was hard to notice, since we sanitize the output by removing all of the line numbers! It would be nice to retain these so we can catch any regressions.
The main reason we sanitize is for maintainability: we concatenate all of the test snippets into a single file, so it's hard for each ".expect" file to know at which offset its test input will be found. We can handle that by storing the per-test line numbers in the ".expect" files, and then dynamically offsetting them as we build the concatenated test and expect files together.
The changes to the ".expect" files look like tedious boilerplate, but it actually makes adding new tests easier. You can now just run:
perl chainlint.pl chainlint/foo.test |
tail -n +2 >chainlint/foo.expect
to save the output of the script minus the comment headers (after checking that it is correct, of course). Whereas before you had to strip the line numbers. The conversions here were done mechanically using something like the script above, and then spot-checked manually.
It would be possible to do all of this in shell via the Makefile, but it gets a bit complicated (and requires a lot of extra processes). Instead, I've written a short perl script that generates the concatenated files (we already depend on perl, since chainlint.pl uses it). Incidentally, this improves a few other things:
- we incorrectly used $(CHAINLINTTMP_SQ) inside a double-quoted string. So if your test directory required quoting, like:
make "TEST_OUTPUT_DIRECTORY=/tmp/h'orrible"
we'd fail the chainlint tests.
- the shell in the Makefile didn't handle &&-chaining correctly in its loops (though in practice the "sed" and "cat" invocations are not likely to fail).
- likewise, the sed invocation to strip numbers was hiding the exit code of chainlint.pl itself. In practice this isn't a big deal; since there are linter violations in the test files, we expect it to exit non-zero. But we could later use exit codes to distinguish serious errors from expected ones.
- we now use a constant number of processes, instead of scaling with the number of test scripts. So it should be a little faster (on my machine, "make check-chainlint" goes from 133ms to 73ms).
There are some alternatives to this approach, but I think this is still a good intermediate step:
1. We could invoke chainlint.pl individually on each test file, and compare it to the expected output (and possibly using "make" to avoid repeating already-done checks). This is a much bigger change (and we'd have to figure out what to do with the "# LINT" lines in the inputs). But in this case we'd still want the "expect" files to be annotated with line numbers. So most of what's in this patch would be needed anyway.
2. Likewise, we could run a single chainlint.pl and feed it all of the scripts (with "--jobs=1" to get deterministic output). But we'd still need to annotate the scripts as we did here, and we'd still need to either assemble the "expect" file, or break apart the script output to compare to each individual ".expect" file.
So we may pursue those in the long run, but this patch gives us more robust tests without too much extra work or moving in a useless direction.
--- t/Makefile | 14 +---- t/chainlint-cat.pl | 29 +++++++++ t/chainlint/arithmetic-expansion.expect | 18 +++--- t/chainlint/bash-array.expect | 20 +++--- t/chainlint/blank-line-before-esac.expect | 36 +++++------ t/chainlint/blank-line.expect | 16 ++--- t/chainlint/block-comment.expect | 16 ++--- t/chainlint/block.expect | 46 +++++++------- t/chainlint/broken-chain.expect | 12 ++-- t/chainlint/case-comment.expect | 22 +++---- t/chainlint/case.expect | 38 ++++++------ t/chainlint/chain-break-background.expect | 18 +++--- t/chainlint/chain-break-continue.expect | 24 +++---- t/chainlint/chain-break-false.expect | 18 +++--- t/chainlint/chain-break-return-exit.expect | 38 ++++++------ t/chainlint/chain-break-status.expect | 18 +++--- t/chainlint/chained-block.expect | 18 +++--- t/chainlint/chained-subshell.expect | 20 +++--- .../close-nested-and-parent-together.expect | 6 +- t/chainlint/close-subshell.expect | 52 ++++++++-------- .../command-substitution-subsubshell.expect | 4 +- t/chainlint/command-substitution.expect | 18 +++--- t/chainlint/comment.expect | 16 ++--- t/chainlint/complex-if-in-cuddled-loop.expect | 18 +++--- t/chainlint/cuddled-if-then-else.expect | 12 ++-- t/chainlint/cuddled-loop.expect | 8 +-- t/chainlint/cuddled.expect | 34 +++++----- t/chainlint/double-here-doc.expect | 24 +++---- t/chainlint/dqstring-line-splice.expect | 10 +-- t/chainlint/dqstring-no-interpolate.expect | 24 +++---- t/chainlint/empty-here-doc.expect | 8 +-- t/chainlint/exclamation.expect | 8 +-- t/chainlint/exit-loop.expect | 48 +++++++------- t/chainlint/exit-subshell.expect | 10 +-- t/chainlint/for-loop-abbreviated.expect | 10 +-- t/chainlint/for-loop.expect | 28 ++++----- t/chainlint/function.expect | 22 +++---- t/chainlint/here-doc-close-subshell.expect | 8 +-- t/chainlint/here-doc-indent-operator.expect | 22 +++---- .../here-doc-multi-line-command-subst.expect | 16 ++--- t/chainlint/here-doc-multi-line-string.expect | 14 ++--- t/chainlint/here-doc.expect | 50 +++++++-------- t/chainlint/if-condition-split.expect | 14 ++--- t/chainlint/if-in-loop.expect | 24 +++---- t/chainlint/if-then-else.expect | 44 ++++++------- t/chainlint/incomplete-line.expect | 20 +++--- t/chainlint/inline-comment.expect | 16 ++--- t/chainlint/loop-detect-failure.expect | 30 ++++----- t/chainlint/loop-detect-status.expect | 36 +++++------ t/chainlint/loop-in-if.expect | 24 +++---- t/chainlint/loop-upstream-pipe.expect | 20 +++--- ...ti-line-nested-command-substitution.expect | 36 +++++------ t/chainlint/multi-line-string.expect | 28 ++++----- t/chainlint/negated-one-liner.expect | 10 +-- t/chainlint/nested-cuddled-subshell.expect | 50 +++++++-------- t/chainlint/nested-here-doc.expect | 60 +++++++++--------- t/chainlint/nested-loop-detect-failure.expect | 62 +++++++++---------- t/chainlint/nested-subshell-comment.expect | 22 +++---- t/chainlint/nested-subshell.expect | 26 ++++---- t/chainlint/not-heredoc.expect | 28 ++++----- t/chainlint/one-liner-for-loop.expect | 18 +++--- t/chainlint/one-liner.expect | 18 +++--- t/chainlint/p4-filespec.expect | 8 +-- t/chainlint/pipe.expect | 20 +++--- t/chainlint/return-loop.expect | 10 +-- t/chainlint/semicolon.expect | 38 ++++++------ t/chainlint/sqstring-in-sqstring.expect | 8 +-- t/chainlint/subshell-here-doc.expect | 60 +++++++++--------- t/chainlint/subshell-one-liner.expect | 38 ++++++------ t/chainlint/t7900-subtree.expect | 44 ++++++------- t/chainlint/token-pasting.expect | 54 ++++++++-------- t/chainlint/unclosed-here-doc-indent.expect | 8 +-- t/chainlint/unclosed-here-doc.expect | 14 ++--- t/chainlint/while-loop.expect | 28 ++++----- 74 files changed, 913 insertions(+), 894 deletions(-) create mode 100644 t/chainlint-cat.pl
t/Makefile +2 -12
@@ -108,18 +108,8 @@ clean-chainlint: check-chainlint: @mkdir -p '$(CHAINLINTTMP_SQ)' && \ - for i in $(CHAINLINTTESTS); do \ - sed -e '/^# LINT: /d' chainlint/$$i.test; \ - done >'$(CHAINLINTTMP_SQ)'/tests && \ - { \ - echo "# chainlint: $(CHAINLINTTMP_SQ)/tests" && \ - for i in $(CHAINLINTTESTS); do \ - echo "# chainlint: $$i" && \ - cat chainlint/$$i.expect; \ - done \ - } >'$(CHAINLINTTMP_SQ)'/expect && \ - $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests | \ - sed -e 's/^[1-9][0-9]* //' >'$(CHAINLINTTMP_SQ)'/actual && \ + '$(PERL_PATH_SQ)' chainlint-cat.pl '$(CHAINLINTTMP_SQ)' $(CHAINLINTTESTS) && \ + { $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests >'$(CHAINLINTTMP_SQ)'/actual || true; } && \ diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
t/chainlint-cat.pl new file +29 -0
@@ -0,0 +1,29 @@ +#!/usr/bin/env perl + +my $outdir = shift; +open(my $tests, '>', "$outdir/tests") + or die "unable to open $outdir/tests: $!"; +open(my $expect, '>', "$outdir/expect") + or die "unable to open $outdir/expect: $!"; + +print $expect "# chainlint: $outdir/tests\n"; + +my $offset = 0; +for my $script (@ARGV) { + print $expect "# chainlint: $script\n"; + + open(my $expect_in, '<', "chainlint/$script.expect") + or die "unable to open chainlint/$script.expect: $!"; + while (<$expect_in>) { + s/^\d+/$& + $offset/e; + print $expect $_; + } + + open(my $test_in, '<', "chainlint/$script.test") + or die "unable to open chainlint/$script.test: $!"; + while (<$test_in>) { + /^# LINT: / and next; + print $tests $_; + $offset++; + } +}
t/chainlint/arithmetic-expansion.expect +9 -9
@@ -1,9 +1,9 @@ -( - foo && - bar=$((42 + 1)) && - baz -) && -( - bar=$((42 + 1)) ?!AMP?! - baz -) +2 ( +3 foo && +4 bar=$((42 + 1)) && +5 baz +6 ) && +7 ( +8 bar=$((42 + 1)) ?!AMP?! +9 baz +10 )
t/chainlint/bash-array.expect +10 -10
@@ -1,10 +1,10 @@ -( - foo && - bar=(gumbo stumbo wumbo) && - baz -) && -( - foo && - bar=${#bar[@]} && - baz -) +2 ( +3 foo && +4 bar=(gumbo stumbo wumbo) && +5 baz +6 ) && +7 ( +8 foo && +9 bar=${#bar[@]} && +10 baz +11 )
t/chainlint/blank-line-before-esac.expect +18 -18
@@ -1,18 +1,18 @@ -test_done () { - case "$test_failure" in - 0) - test_at_end_hook_ - - exit 0 ;; - - *) - if test $test_external_has_tap -eq 0 - then - say_color error "# failed $test_failure among $msg" - say "1..$test_count" - fi - - exit 1 ;; - - esac -} +2 test_done () { +3 case "$test_failure" in +4 0) +5 test_at_end_hook_ +6 +7 exit 0 ;; +8 +9 *) +10 if test $test_external_has_tap -eq 0 +11 then +12 say_color error "# failed $test_failure among $msg" +13 say "1..$test_count" +14 fi +15 +16 exit 1 ;; +17 +18 esac +19 }
t/chainlint/blank-line.expect +8 -8
@@ -1,8 +1,8 @@ -( - - nothing && - - something - - -) +2 ( +3 +4 nothing && +5 +6 something +7 +8 +9 )
t/chainlint/block-comment.expect +8 -8
@@ -1,8 +1,8 @@ -( - { - # show a - echo a && - # show b - echo b - } -) +2 ( +3 { +4 # show a +5 echo a && +6 # show b +7 echo b +8 } +9 )
t/chainlint/block.expect +23 -23
46 lines not on this page · raw message
t/chainlint/broken-chain.expect +6 -6
@@ -1,6 +1,6 @@ -( - foo && - bar ?!AMP?! - baz && - wop -) +2 ( +3 foo && +4 bar ?!AMP?! +5 baz && +6 wop +7 )
t/chainlint/case-comment.expect +11 -11
@@ -1,11 +1,11 @@ -( - case "$x" in - # found foo - x) foo ;; - # found other - *) - # treat it as bar - bar - ;; - esac -) +2 ( +3 case "$x" in +4 # found foo +5 x) foo ;; +6 # found other +7 *) +8 # treat it as bar +9 bar +10 ;; +11 esac +12 )
t/chainlint/case.expect +19 -19
@@ -1,19 +1,19 @@ -( - case "$x" in - x) foo ;; - *) bar ;; - esac && - foobar -) && -( - case "$x" in - x) foo ;; - *) bar ;; - esac ?!AMP?! - foobar -) && -( - case "$x" in 1) true;; esac && - case "$y" in 2) false;; esac ?!AMP?! - foobar -) +2 ( +3 case "$x" in +4 x) foo ;; +5 *) bar ;; +6 esac && +7 foobar +8 ) && +9 ( +10 case "$x" in +11 x) foo ;; +12 *) bar ;; +13 esac ?!AMP?! +14 foobar +15 ) && +16 ( +17 case "$x" in 1) true;; esac && +18 case "$y" in 2) false;; esac ?!AMP?! +19 foobar +20 )
t/chainlint/chain-break-background.expect +9 -9
@@ -1,9 +1,9 @@ -JGIT_DAEMON_PID= && -git init --bare empty.git && ->empty.git/git-daemon-export-ok && -mkfifo jgit_daemon_output && -{ - jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output & - JGIT_DAEMON_PID=$! -} && -test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git +2 JGIT_DAEMON_PID= && +3 git init --bare empty.git && +4 >empty.git/git-daemon-export-ok && +5 mkfifo jgit_daemon_output && +6 { +7 jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output & +8 JGIT_DAEMON_PID=$! +9 } && +10 test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git
t/chainlint/chain-break-continue.expect +12 -12
@@ -1,12 +1,12 @@ -git ls-tree --name-only -r refs/notes/many_notes | -while read path -do - test "$path" = "foobar/non-note.txt" && continue - test "$path" = "deadbeef" && continue - test "$path" = "de/adbeef" && continue - - if test $(expr length "$path") -ne $hexsz - then - return 1 - fi -done +2 git ls-tree --name-only -r refs/notes/many_notes | +3 while read path +4 do +5 test "$path" = "foobar/non-note.txt" && continue +6 test "$path" = "deadbeef" && continue +7 test "$path" = "de/adbeef" && continue +8 +9 if test $(expr length "$path") -ne $hexsz +10 then +11 return 1 +12 fi +13 done
t/chainlint/chain-break-false.expect +9 -9
@@ -1,9 +1,9 @@ -if condition not satisified -then - echo it did not work... - echo failed! - false -else - echo it went okay ?!AMP?! - congratulate user -fi +2 if condition not satisified +3 then +4 echo it did not work... +5 echo failed! +6 false +7 else +8 echo it went okay ?!AMP?! +9 congratulate user +10 fi
t/chainlint/chain-break-return-exit.expect +19 -19
@@ -1,19 +1,19 @@ -case "$(git ls-files)" in -one) echo pass one ;; -*) echo bad one; return 1 ;; -esac && -( - case "$(git ls-files)" in - two) echo pass two ;; - *) echo bad two; exit 1 ;; - esac -) && -case "$(git ls-files)" in -dir/two"$LF"one) echo pass both ;; -*) echo bad; return 1 ;; -esac && - -for i in 1 2 3 4 ; do - git checkout main -b $i || return $? - test_commit $i $i $i tag$i || return $? -done +2 case "$(git ls-files)" in +3 one) echo pass one ;; +4 *) echo bad one; return 1 ;; +5 esac && +6 ( +7 case "$(git ls-files)" in +8 two) echo pass two ;; +9 *) echo bad two; exit 1 ;; +10 esac +11 ) && +12 case "$(git ls-files)" in +13 dir/two"$LF"one) echo pass both ;; +14 *) echo bad; return 1 ;; +15 esac && +16 +17 for i in 1 2 3 4 ; do +18 git checkout main -b $i || return $? +19 test_commit $i $i $i tag$i || return $? +20 done
t/chainlint/chain-break-status.expect +9 -9
@@ -1,9 +1,9 @@ -OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) && -test_match_signal 13 "$OUT" && - -{ test-tool sigchain >actual; ret=$?; } && -{ - test_match_signal 15 "$ret" || - test "$ret" = 3 -} && -test_cmp expect actual +2 OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) && +3 test_match_signal 13 "$OUT" && +4 +5 { test-tool sigchain >actual; ret=$?; } && +6 { +7 test_match_signal 15 "$ret" || +8 test "$ret" = 3 +9 } && +10 test_cmp expect actual
t/chainlint/chained-block.expect +9 -9
@@ -1,9 +1,9 @@ -echo nobody home && { - test the doohicky ?!AMP?! - right now -} && - -GIT_EXTERNAL_DIFF=echo git diff | { - read path oldfile oldhex oldmode newfile newhex newmode && - test "z$oh" = "z$oldhex" -} +2 echo nobody home && { +3 test the doohicky ?!AMP?! +4 right now +5 } && +6 +7 GIT_EXTERNAL_DIFF=echo git diff | { +8 read path oldfile oldhex oldmode newfile newhex newmode && +9 test "z$oh" = "z$oldhex" +10 }
t/chainlint/chained-subshell.expect +10 -10
@@ -1,10 +1,10 @@ -mkdir sub && ( - cd sub && - foo the bar ?!AMP?! - nuff said -) && - -cut "-d " -f actual | (read s1 s2 s3 && -test -f $s1 ?!AMP?! -test $(cat $s2) = tree2path1 && -test $(cat $s3) = tree3path1) +2 mkdir sub && ( +3 cd sub && +4 foo the bar ?!AMP?! +5 nuff said +6 ) && +7 +8 cut "-d " -f actual | (read s1 s2 s3 && +9 test -f $s1 ?!AMP?! +10 test $(cat $s2) = tree2path1 && +11 test $(cat $s3) = tree3path1)
t/chainlint/close-nested-and-parent-together.expect +3 -3
@@ -1,3 +1,3 @@ -(cd foo && - (bar && - baz)) +2 (cd foo && +3 (bar && +4 baz))
t/chainlint/close-subshell.expect +26 -26
52 lines not on this page · raw message
t/chainlint/command-substitution-subsubshell.expect +2 -2
@@ -1,2 +1,2 @@ -OUT=$( ((large_git 1>&3) | :) 3>&1 ) && -test_match_signal 13 "$OUT" +2 OUT=$( ((large_git 1>&3) | :) 3>&1 ) && +3 test_match_signal 13 "$OUT"
t/chainlint/command-substitution.expect +9 -9
@@ -1,9 +1,9 @@ -( - foo && - bar=$(gobble) && - baz -) && -( - bar=$(gobble blocks) ?!AMP?! - baz -) +2 ( +3 foo && +4 bar=$(gobble) && +5 baz +6 ) && +7 ( +8 bar=$(gobble blocks) ?!AMP?! +9 baz +10 )
t/chainlint/comment.expect +8 -8
@@ -1,8 +1,8 @@ -( - # comment 1 - nothing && - # comment 2 - something - # comment 3 - # comment 4 -) +2 ( +3 # comment 1 +4 nothing && +5 # comment 2 +6 something +7 # comment 3 +8 # comment 4 +9 )
t/chainlint/complex-if-in-cuddled-loop.expect +9 -9
@@ -1,9 +1,9 @@ -(for i in a b c; do - if test "$(echo $(waffle bat))" = "eleventeen" && - test "$x" = "$y"; then - : - else - echo >file - fi ?!LOOP?! - done) && -test ! -f file +2 (for i in a b c; do +3 if test "$(echo $(waffle bat))" = "eleventeen" && +4 test "$x" = "$y"; then +5 : +6 else +7 echo >file +8 fi ?!LOOP?! +9 done) && +10 test ! -f file
t/chainlint/cuddled-if-then-else.expect +6 -6
@@ -1,6 +1,6 @@ -(if test -z ""; then - echo empty - else - echo bizzy - fi) && -echo foobar +2 (if test -z ""; then +3 echo empty +4 else +5 echo bizzy +6 fi) && +7 echo foobar
t/chainlint/cuddled-loop.expect +4 -4
@@ -1,4 +1,4 @@ -( while read x - do foobar bop || exit 1 - done <file ) && -outside subshell +2 ( while read x +3 do foobar bop || exit 1 +4 done <file ) && +5 outside subshell
t/chainlint/cuddled.expect +17 -17
@@ -1,17 +1,17 @@ -(cd foo && - bar -) && - -(cd foo ?!AMP?! - bar -) && - -( - cd foo && - bar) && - -(cd foo && - bar) && - -(cd foo ?!AMP?! - bar) +2 (cd foo && +3 bar +4 ) && +5 +6 (cd foo ?!AMP?! +7 bar +8 ) && +9 +10 ( +11 cd foo && +12 bar) && +13 +14 (cd foo && +15 bar) && +16 +17 (cd foo ?!AMP?! +18 bar)
t/chainlint/double-here-doc.expect +12 -12
@@ -1,12 +1,12 @@ -run_sub_test_lib_test_err run-inv-range-start \ - "--run invalid range start" \ - --run="a-5" <<-\EOF && -test_expect_success "passing test #1" "true" -test_done -EOF -check_sub_test_lib_test_err run-inv-range-start \ - <<-\EOF_OUT 3<<-EOF_ERR -> FATAL: Unexpected exit with code 1 -EOF_OUT -> error: --run: invalid non-numeric in range start: ${SQ}a-5${SQ} -EOF_ERR +2 run_sub_test_lib_test_err run-inv-range-start \ +3 "--run invalid range start" \ +4 --run="a-5" <<-\EOF && +5 test_expect_success "passing test #1" "true" +6 test_done +7 EOF +8 check_sub_test_lib_test_err run-inv-range-start \ +9 <<-\EOF_OUT 3<<-EOF_ERR +10 > FATAL: Unexpected exit with code 1 +11 EOF_OUT +12 > error: --run: invalid non-numeric in range start: ${SQ}a-5${SQ} +13 EOF_ERR
t/chainlint/dqstring-line-splice.expect +5 -5
@@ -1,5 +1,5 @@ - -echo 'fatal: reword option of --fixup is mutually exclusive with' '--patch/--interactive/--all/--include/--only' >expect && -test_must_fail git commit --fixup=reword:HEAD~ $1 2>actual && -test_cmp expect actual - +2 +3 echo 'fatal: reword option of --fixup is mutually exclusive with' '--patch/--interactive/--all/--include/--only' >expect && +4 test_must_fail git commit --fixup=reword:HEAD~ $1 2>actual && +5 test_cmp expect actual +6
t/chainlint/dqstring-no-interpolate.expect +12 -12
@@ -1,12 +1,12 @@ -grep "^ ! [rejected][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" out && - -grep "^\.git$" output.txt && - - -( - cd client$version && - GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. $(cat ../input) -) >output && - cut -d ' ' -f 2 <output | sort >actual && - test_cmp expect actual - +2 grep "^ ! [rejected][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" out && +3 +4 grep "^\.git$" output.txt && +5 +6 +7 ( +8 cd client$version && +9 GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. $(cat ../input) +10 ) >output && +11 cut -d ' ' -f 2 <output | sort >actual && +12 test_cmp expect actual +13
t/chainlint/empty-here-doc.expect +4 -4
@@ -1,4 +1,4 @@ -git ls-tree $tree path >current && -cat >expected <<\EOF && -EOF -test_output +2 git ls-tree $tree path >current && +3 cat >expected <<\EOF && +4 EOF +5 test_output
t/chainlint/exclamation.expect +4 -4
@@ -1,4 +1,4 @@ -if ! condition; then echo nope; else yep; fi && -test_prerequisite !MINGW && -mail uucp!address && -echo !whatever! +2 if ! condition; then echo nope; else yep; fi && +3 test_prerequisite !MINGW && +4 mail uucp!address && +5 echo !whatever!
t/chainlint/exit-loop.expect +24 -24
48 lines not on this page · raw message
t/chainlint/exit-subshell.expect +5 -5
@@ -1,5 +1,5 @@ -( - foo || exit 1 - bar && - baz -) +2 ( +3 foo || exit 1 +4 bar && +5 baz +6 )
t/chainlint/for-loop-abbreviated.expect +5 -5
@@ -1,5 +1,5 @@ -for it -do - path=$(expr "$it" : ([^:]*)) && - git update-index --add "$path" || exit -done +2 for it +3 do +4 path=$(expr "$it" : ([^:]*)) && +5 git update-index --add "$path" || exit +6 done
t/chainlint/for-loop.expect +14 -14
@@ -1,14 +1,14 @@ -( - for i in a b c - do - echo $i ?!AMP?! - cat <<-\EOF ?!LOOP?! - bar - EOF - done ?!AMP?! - - for i in a b c; do - echo $i && - cat $i ?!LOOP?! - done -) +2 ( +3 for i in a b c +4 do +5 echo $i ?!AMP?! +6 cat <<-\EOF ?!LOOP?! +7 bar +8 EOF +9 done ?!AMP?! +10 +11 for i in a b c; do +12 echo $i && +13 cat $i ?!LOOP?! +14 done +15 )
t/chainlint/function.expect +11 -11
@@ -1,11 +1,11 @@ -sha1_file() { - echo "$*" | sed "s#..#.git/objects/&/#" -} && - -remove_object() { - file=$(sha1_file "$*") && - test -e "$file" ?!AMP?! - rm -f "$file" -} ?!AMP?! - -sha1_file arg && remove_object arg +2 sha1_file() { +3 echo "$*" | sed "s#..#.git/objects/&/#" +4 } && +5 +6 remove_object() { +7 file=$(sha1_file "$*") && +8 test -e "$file" ?!AMP?! +9 rm -f "$file" +10 } ?!AMP?! +11 +12 sha1_file arg && remove_object arg
t/chainlint/here-doc-close-subshell.expect +4 -4
@@ -1,4 +1,4 @@ -( - cat <<-\INPUT) - fizz - INPUT +2 ( +3 cat <<-\INPUT) +4 fizz +5 INPUT
t/chainlint/here-doc-indent-operator.expect +11 -11
@@ -1,11 +1,11 @@ -cat >expect <<- EOF && -header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0 -num_commits: $1 -chunks: oid_fanout oid_lookup commit_metadata generation_data bloom_indexes bloom_data -EOF - -cat >expect << -EOF ?!AMP?! -this is not indented --EOF - -cleanup +2 cat >expect <<- EOF && +3 header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0 +4 num_commits: $1 +5 chunks: oid_fanout oid_lookup commit_metadata generation_data bloom_indexes bloom_data +6 EOF +7 +8 cat >expect << -EOF ?!AMP?! +9 this is not indented +10 -EOF +11 +12 cleanup
t/chainlint/here-doc-multi-line-command-subst.expect +8 -8
@@ -1,8 +1,8 @@ -( - x=$(bobble <<-\END && - fossil - vegetable - END - wiffle) ?!AMP?! - echo $x -) +2 ( +3 x=$(bobble <<-\END && +4 fossil +5 vegetable +6 END +7 wiffle) ?!AMP?! +8 echo $x +9 )
t/chainlint/here-doc-multi-line-string.expect +7 -7
@@ -1,7 +1,7 @@ -( - cat <<-\TXT && echo "multi-line - string" ?!AMP?! - fizzle - TXT - bap -) +2 ( +3 cat <<-\TXT && echo "multi-line +4 string" ?!AMP?! +5 fizzle +6 TXT +7 bap +8 )
t/chainlint/here-doc.expect +25 -25
50 lines not on this page · raw message
t/chainlint/if-condition-split.expect +7 -7
@@ -1,7 +1,7 @@ -if bob && - marcia || - kevin -then - echo "nomads" ?!AMP?! - echo "for sure" -fi +2 if bob && +3 marcia || +4 kevin +5 then +6 echo "nomads" ?!AMP?! +7 echo "for sure" +8 fi
t/chainlint/if-in-loop.expect +12 -12
@@ -1,12 +1,12 @@ -( - for i in a b c - do - if false - then - echo "err" - exit 1 - fi ?!AMP?! - foo - done ?!AMP?! - bar -) +2 ( +3 for i in a b c +4 do +5 if false +6 then +7 echo "err" +8 exit 1 +9 fi ?!AMP?! +10 foo +11 done ?!AMP?! +12 bar +13 )
t/chainlint/if-then-else.expect +22 -22
44 lines not on this page · raw message
t/chainlint/incomplete-line.expect +10 -10
@@ -1,10 +1,10 @@ -line 1 \ -line 2 \ -line 3 \ -line 4 && -( - line 5 \ - line 6 \ - line 7 \ - line 8 -) +2 line 1 \ +3 line 2 \ +4 line 3 \ +5 line 4 && +6 ( +7 line 5 \ +8 line 6 \ +9 line 7 \ +10 line 8 +11 )
t/chainlint/inline-comment.expect +8 -8
@@ -1,8 +1,8 @@ -( - foobar && # comment 1 - barfoo ?!AMP?! # wrong position for && - flibble "not a # comment" -) && - -(cd foo && - flibble "not a # comment") +2 ( +3 foobar && # comment 1 +4 barfoo ?!AMP?! # wrong position for && +5 flibble "not a # comment" +6 ) && +7 +8 (cd foo && +9 flibble "not a # comment")
t/chainlint/loop-detect-failure.expect +15 -15
@@ -1,15 +1,15 @@ -git init r1 && -for n in 1 2 3 4 5 -do - echo "This is file: $n" > r1/file.$n && - git -C r1 add file.$n && - git -C r1 commit -m "$n" || return 1 -done && - -git init r2 && -for n in 1000 10000 -do - printf "%"$n"s" X > r2/large.$n && - git -C r2 add large.$n && - git -C r2 commit -m "$n" ?!LOOP?! -done +2 git init r1 && +3 for n in 1 2 3 4 5 +4 do +5 echo "This is file: $n" > r1/file.$n && +6 git -C r1 add file.$n && +7 git -C r1 commit -m "$n" || return 1 +8 done && +9 +10 git init r2 && +11 for n in 1000 10000 +12 do +13 printf "%"$n"s" X > r2/large.$n && +14 git -C r2 add large.$n && +15 git -C r2 commit -m "$n" ?!LOOP?! +16 done
t/chainlint/loop-detect-status.expect +18 -18
@@ -1,18 +1,18 @@ -(while test $i -le $blobcount - do - printf "Generating blob $i/$blobcount\r" >&2 && - printf "blob\nmark :$i\ndata $blobsize\n" && - #test-tool genrandom $i $blobsize && - printf "%-${blobsize}s" $i && - echo "M 100644 :$i $i" >> commit && - i=$(($i+1)) || - echo $? > exit-status - done && - echo "commit refs/heads/main" && - echo "author A U Thor <[email protected]> 123456789 +0000" && - echo "committer C O Mitter <[email protected]> 123456789 +0000" && - echo "data 5" && - echo ">2gb" && - cat commit) | -git fast-import --big-file-threshold=2 && -test ! -f exit-status +2 (while test $i -le $blobcount +3 do +4 printf "Generating blob $i/$blobcount\r" >&2 && +5 printf "blob\nmark :$i\ndata $blobsize\n" && +6 #test-tool genrandom $i $blobsize && +7 printf "%-${blobsize}s" $i && +8 echo "M 100644 :$i $i" >> commit && +9 i=$(($i+1)) || +10 echo $? > exit-status +11 done && +12 echo "commit refs/heads/main" && +13 echo "author A U Thor <[email protected]> 123456789 +0000" && +14 echo "committer C O Mitter <[email protected]> 123456789 +0000" && +15 echo "data 5" && +16 echo ">2gb" && +17 cat commit) | +18 git fast-import --big-file-threshold=2 && +19 test ! -f exit-status
t/chainlint/loop-in-if.expect +12 -12
@@ -1,12 +1,12 @@ -( - if true - then - while true - do - echo "pop" ?!AMP?! - echo "glup" ?!LOOP?! - done ?!AMP?! - foo - fi ?!AMP?! - bar -) +2 ( +3 if true +4 then +5 while true +6 do +7 echo "pop" ?!AMP?! +8 echo "glup" ?!LOOP?! +9 done ?!AMP?! +10 foo +11 fi ?!AMP?! +12 bar +13 )
t/chainlint/loop-upstream-pipe.expect +10 -10
@@ -1,10 +1,10 @@ -( - git rev-list --objects --no-object-names base..loose | - while read oid - do - path="$objdir/$(test_oid_to_path "$oid")" && - printf "%s %d\n" "$oid" "$(test-tool chmtime --get "$path")" || - echo "object list generation failed for $oid" - done | - sort -k1 -) >expect && +2 ( +3 git rev-list --objects --no-object-names base..loose | +4 while read oid +5 do +6 path="$objdir/$(test_oid_to_path "$oid")" && +7 printf "%s %d\n" "$oid" "$(test-tool chmtime --get "$path")" || +8 echo "object list generation failed for $oid" +9 done | +10 sort -k1 +11 ) >expect &&
t/chainlint/multi-line-nested-command-substitution.expect +18 -18
@@ -1,18 +1,18 @@ -( - foo && - x=$( - echo bar | - cat - ) && - echo ok -) | -sort && -( - bar && - x=$(echo bar | - cat - ) && - y=$(echo baz | - fip) && - echo fail -) +2 ( +3 foo && +4 x=$( +5 echo bar | +6 cat +7 ) && +8 echo ok +9 ) | +10 sort && +11 ( +12 bar && +13 x=$(echo bar | +14 cat +15 ) && +16 y=$(echo baz | +17 fip) && +18 echo fail +19 )
t/chainlint/multi-line-string.expect +14 -14
@@ -1,14 +1,14 @@ -( - x="line 1 - line 2 - line 3" && - y="line 1 - line2" ?!AMP?! - foobar -) && -( - echo "xyz" "abc - def - ghi" && - barfoo -) +2 ( +3 x="line 1 +4 line 2 +5 line 3" && +6 y="line 1 +7 line2" ?!AMP?! +8 foobar +9 ) && +10 ( +11 echo "xyz" "abc +12 def +13 ghi" && +14 barfoo +15 )
t/chainlint/negated-one-liner.expect +5 -5
@@ -1,5 +1,5 @@ -! (foo && bar) && -! (foo && bar) >baz && - -! (foo; ?!AMP?! bar) && -! (foo; ?!AMP?! bar) >baz +2 ! (foo && bar) && +3 ! (foo && bar) >baz && +4 +5 ! (foo; ?!AMP?! bar) && +6 ! (foo; ?!AMP?! bar) >baz
t/chainlint/nested-cuddled-subshell.expect +25 -25
50 lines not on this page · raw message
t/chainlint/nested-here-doc.expect +30 -30
60 lines not on this page · raw message
t/chainlint/nested-loop-detect-failure.expect +31 -31
62 lines not on this page · raw message
t/chainlint/nested-subshell-comment.expect +11 -11
@@ -1,11 +1,11 @@ -( - foo && - ( - bar && - # bottles wobble while fiddles gobble - # minor numbers of cows (or do they?) - baz && - snaff - ) ?!AMP?! - fuzzy -) +2 ( +3 foo && +4 ( +5 bar && +6 # bottles wobble while fiddles gobble +7 # minor numbers of cows (or do they?) +8 baz && +9 snaff +10 ) ?!AMP?! +11 fuzzy +12 )
t/chainlint/nested-subshell.expect +13 -13
@@ -1,13 +1,13 @@ -( - cd foo && - ( - echo a && - echo b - ) >file && - - cd foo && - ( - echo a ?!AMP?! - echo b - ) >file -) +2 ( +3 cd foo && +4 ( +5 echo a && +6 echo b +7 ) >file && +8 +9 cd foo && +10 ( +11 echo a ?!AMP?! +12 echo b +13 ) >file +14 )
t/chainlint/not-heredoc.expect +14 -14
@@ -1,14 +1,14 @@ -echo "<<<<<<< ours" && -echo ourside && -echo "=======" && -echo theirside && -echo ">>>>>>> theirs" && - -( - echo "<<<<<<< ours" && - echo ourside && - echo "=======" && - echo theirside && - echo ">>>>>>> theirs" ?!AMP?! - poodle -) >merged +2 echo "<<<<<<< ours" && +3 echo ourside && +4 echo "=======" && +5 echo theirside && +6 echo ">>>>>>> theirs" && +7 +8 ( +9 echo "<<<<<<< ours" && +10 echo ourside && +11 echo "=======" && +12 echo theirside && +13 echo ">>>>>>> theirs" ?!AMP?! +14 poodle +15 ) >merged
t/chainlint/one-liner-for-loop.expect +9 -9
@@ -1,9 +1,9 @@ -git init dir-rename-and-content && -( - cd dir-rename-and-content && - test_write_lines 1 2 3 4 5 >foo && - mkdir olddir && - for i in a b c; do echo $i >olddir/$i; ?!LOOP?! done ?!AMP?! - git add foo olddir && - git commit -m "original" && -) +2 git init dir-rename-and-content && +3 ( +4 cd dir-rename-and-content && +5 test_write_lines 1 2 3 4 5 >foo && +6 mkdir olddir && +7 for i in a b c; do echo $i >olddir/$i; ?!LOOP?! done ?!AMP?! +8 git add foo olddir && +9 git commit -m "original" && +10 )
t/chainlint/one-liner.expect +9 -9
@@ -1,9 +1,9 @@ -(foo && bar) && -(foo && bar) | -(foo && bar) >baz && - -(foo; ?!AMP?! bar) && -(foo; ?!AMP?! bar) | -(foo; ?!AMP?! bar) >baz && - -(foo "bar; baz") +2 (foo && bar) && +3 (foo && bar) | +4 (foo && bar) >baz && +5 +6 (foo; ?!AMP?! bar) && +7 (foo; ?!AMP?! bar) | +8 (foo; ?!AMP?! bar) >baz && +9 +10 (foo "bar; baz")
t/chainlint/p4-filespec.expect +4 -4
@@ -1,4 +1,4 @@ -( - p4 print -1 //depot/fiddle#42 >file && - foobar -) +2 ( +3 p4 print -1 //depot/fiddle#42 >file && +4 foobar +5 )
t/chainlint/pipe.expect +10 -10
@@ -1,10 +1,10 @@ -( - foo | - bar | - baz && - - fish | - cow ?!AMP?! - - sunder -) +2 ( +3 foo | +4 bar | +5 baz && +6 +7 fish | +8 cow ?!AMP?! +9 +10 sunder +11 )
t/chainlint/return-loop.expect +5 -5
@@ -1,5 +1,5 @@ -while test $i -lt $((num - 5)) -do - git notes add -m "notes for commit$i" HEAD~$i || return 1 - i=$((i + 1)) -done +2 while test $i -lt $((num - 5)) +3 do +4 git notes add -m "notes for commit$i" HEAD~$i || return 1 +5 i=$((i + 1)) +6 done
t/chainlint/semicolon.expect +19 -19
@@ -1,19 +1,19 @@ -( - cat foo ; ?!AMP?! echo bar ?!AMP?! - cat foo ; ?!AMP?! echo bar -) && -( - cat foo ; ?!AMP?! echo bar && - cat foo ; ?!AMP?! echo bar -) && -( - echo "foo; bar" && - cat foo; ?!AMP?! echo bar -) && -( - foo; -) && -(cd foo && - for i in a b c; do - echo; ?!LOOP?! - done) +2 ( +3 cat foo ; ?!AMP?! echo bar ?!AMP?! +4 cat foo ; ?!AMP?! echo bar +5 ) && +6 ( +7 cat foo ; ?!AMP?! echo bar && +8 cat foo ; ?!AMP?! echo bar +9 ) && +10 ( +11 echo "foo; bar" && +12 cat foo; ?!AMP?! echo bar +13 ) && +14 ( +15 foo; +16 ) && +17 (cd foo && +18 for i in a b c; do +19 echo; ?!LOOP?! +20 done)
t/chainlint/sqstring-in-sqstring.expect +4 -4
@@ -1,4 +1,4 @@ -perl -e ' - defined($_ = -s $_) or die for @ARGV; - exit 1 if $ARGV[0] <= $ARGV[1]; -' test-2-$packname_2.pack test-3-$packname_3.pack +2 perl -e ' +3 defined($_ = -s $_) or die for @ARGV; +4 exit 1 if $ARGV[0] <= $ARGV[1]; +5 ' test-2-$packname_2.pack test-3-$packname_3.pack
t/chainlint/subshell-here-doc.expect +30 -30
60 lines not on this page · raw message
t/chainlint/subshell-one-liner.expect +19 -19
@@ -1,19 +1,19 @@ -( - (foo && bar) && - (foo && bar) | - (foo && bar) >baz && - - (foo; ?!AMP?! bar) && - (foo; ?!AMP?! bar) | - (foo; ?!AMP?! bar) >baz && - - (foo || exit 1) && - (foo || exit 1) | - (foo || exit 1) >baz && - - (foo && bar) ?!AMP?! - - (foo && bar; ?!AMP?! baz) ?!AMP?! - - foobar -) +2 ( +3 (foo && bar) && +4 (foo && bar) | +5 (foo && bar) >baz && +6 +7 (foo; ?!AMP?! bar) && +8 (foo; ?!AMP?! bar) | +9 (foo; ?!AMP?! bar) >baz && +10 +11 (foo || exit 1) && +12 (foo || exit 1) | +13 (foo || exit 1) >baz && +14 +15 (foo && bar) ?!AMP?! +16 +17 (foo && bar; ?!AMP?! baz) ?!AMP?! +18 +19 foobar +20 )
t/chainlint/t7900-subtree.expect +22 -22
44 lines not on this page · raw message
t/chainlint/token-pasting.expect +27 -27
54 lines not on this page · raw message
t/chainlint/unclosed-here-doc-indent.expect +4 -4
@@ -1,4 +1,4 @@ -command_which_is_run && -cat >expect <<-\EOF ?!UNCLOSED-HEREDOC?! && -we forget to end the here-doc -command_which_is_gobbled +2 command_which_is_run && +3 cat >expect <<-\EOF ?!UNCLOSED-HEREDOC?! && +4 we forget to end the here-doc +5 command_which_is_gobbled
t/chainlint/unclosed-here-doc.expect +7 -7
@@ -1,7 +1,7 @@ -command_which_is_run && -cat >expect <<\EOF ?!UNCLOSED-HEREDOC?! && - we try to end the here-doc below, - but the indentation throws us off - since the operator is not "<<-". - EOF -command_which_is_gobbled +2 command_which_is_run && +3 cat >expect <<\EOF ?!UNCLOSED-HEREDOC?! && +4 we try to end the here-doc below, +5 but the indentation throws us off +6 since the operator is not "<<-". +7 EOF +8 command_which_is_gobbled
t/chainlint/while-loop.expect +14 -14
@@ -1,14 +1,14 @@ -( - while true - do - echo foo ?!AMP?! - cat <<-\EOF ?!LOOP?! - bar - EOF - done ?!AMP?! - - while true; do - echo foo && - cat bar ?!LOOP?! - done -) +2 ( +3 while true +4 do +5 echo foo ?!AMP?! +6 cat <<-\EOF ?!LOOP?! +7 bar +8 EOF +9 done ?!AMP?! +10 +11 while true; do +12 echo foo && +13 cat bar ?!LOOP?! +14 done +15 )
Signature · 1 line
2.45.2.1249.gb036353db5
Re: [PATCH v2 5/9] chainlint.pl: check line numbers in expected output
Quoted 28 lines · Jeff King
[...]
It would be possible to do all of this in shell via theMakefile, but it gets a bit complicated (and requires a lot of extra processes). Instead, I've written a short perl script that generates the concatenated files (we already depend on perl, since chainlint.pl uses it). Incidentally, this improves a few other things:
[...]t/chainlint-cat.pl +19
-0@@ -0,0 +1,29 @@ +#!/usr/bin/env perl + +my $outdir = shift; +open(my $tests, '>', "$outdir/tests") + or die "unable to open $outdir/tests: $!"; +open(my $expect, '>', "$outdir/expect") + or die "unable to open $outdir/expect: $!"; + +print $expect "# chainlint: $outdir/tests\n"; + +my $offset = 0; +for my $script (@ARGV) { + print $expect "# chainlint: $script\n"; + + open(my $expect_in, '<', "chainlint/$script.expect") + or die "unable to open chainlint/$script.expect: $!"; + while (<$expect_in>) { + s/^\d+/$& + $offset/e; + print $expect $_;
t/chainlint-cat.pl line 29
Quoted 10 lines
t/chainlint-cat.pl +10
-0+ } + + open(my $test_in, '<', "chainlint/$script.test") + or die "unable to open chainlint/$script.test: $!"; + while (<$test_in>) { + /^# LINT: / and next; + print $tests $_; + $offset++; + } +}
I'm surprised that we're not closing the two file handles opened on each iteration of this loop. Is that intentional? Or am I forgetting my Perl and they are somehow getting closed anyhow (for instance, by the <...> operator hitting EOF)?
Re: [PATCH v2 5/9] chainlint.pl: check line numbers in expected output
Quoted 15 lines · Eric Sunshine
Quoted 15 lines
t/chainlint-cat.pl new file +15
-0+for my $script (@ARGV) { + print $expect "# chainlint: $script\n"; + + open(my $expect_in, '<', "chainlint/$script.expect") + or die "unable to open chainlint/$script.expect: $!"; + while (<$expect_in>) { + s/^\d+/$& + $offset/e; + print $expect $_; + } + + open(my $test_in, '<', "chainlint/$script.test") + or die "unable to open chainlint/$script.test: $!"; + while (<$test_in>) { + /^# LINT: / and next; + print $tests $_;
Quoted 8 lines
t/chainlint-cat.pl line 29
Quoted 3 lines
t/chainlint-cat.pl new file +3
-0+ $offset++; + } +}I'm surprised that we're not closing the two file handles opened on each iteration of this loop. Is that intentional? Or am I forgetting my Perl and they are somehow getting closed anyhow (for instance, by the <...> operator hitting EOF)?
They're scoped to the loop with "my", so they'll both be closed for each iteration of the outer loop when the handles go out of scope.
You can verify with something like:
touch foo bar baz
strace -e openat,write,close \
perl -e '
for my $script (@ARGV) {
syswrite(STDOUT, "opening $script");
open(my $in, "<", $script);
syswrite(STDOUT, "finished $script");
}' foo bar baz >/dev/null
which should show:
write(1, "opening foo", 11) = 11
openat(AT_FDCWD, "foo", O_RDONLY|O_CLOEXEC) = 3
write(1, "finished foo", 12) = 12 close(3) = 0 write(1, "opening bar", 11) = 11
[...etc...]
-Peff
Re: [PATCH v2 5/9] chainlint.pl: check line numbers in expected output
Quoted 8 lines · Jeff King
Quoted 4 lines · Eric Sunshine
I'm surprised that we're not closing the two file handles opened on each iteration of this loop. Is that intentional? Or am I forgetting my Perl and they are somehow getting closed anyhow (for instance, by the <...> operator hitting EOF)?
They're scoped to the loop with "my", so they'll both be closed for each iteration of the outer loop when the handles go out of scope.
Makes sense. I thought that might be the case but it's been years since I read the "camel book" (thus may have forgotten it), and wasn't able to find any Perl documentation which stated so (which is not to say such documentation doesn't exist, but rather that I couldn't find it).
Quoted 12 lines
You can verify with something like:
touch foo bar baz strace -e openat,write,close \ perl -e ' for my $script (@ARGV) { syswrite(STDOUT, "opening $script"); open(my $in, "<", $script); syswrite(STDOUT, "finished $script"); } ' foo bar baz >/dev/null
Quoted 7 lines
which should show:
write(1, "opening foo", 11)= 11
openat(AT_FDCWD, "foo", O_RDONLY|O_CLOEXEC)= 3write(1, "finished foo", 12) = 12 close(3) = 0 write(1, "opening bar", 11) = 11
Thanks for illustrating. I did think of strace but I never use it because it doesn't exist on macOS and I was too lazy to spin up a Linux VM and read the strace documentation to figure out how to do what you did above.
PATCH v2 6/9 chainlint.pl: recognize test bodies defined via heredoc
In reply to Jeff KingFrom: Eric Sunshine <[email protected]>
In order to check tests for semantic problems, chainlint.pl scans test scripts, looking for tests defined as:
test_expect_success [prereq] title '
body
'
where body is a single string which is then treated as a standalone chunk of code and "linted" to detect semantic issues. (The same happens for test_expect_failure definitions.)
The introduction of test definitions in which the test body is instead presented via a heredoc rather than as a single string creates a blind spot in the linting process since such invocations are not recognized by chainlint.pl.
Prepare for this new style by also recognizing tests defined as:
test_expect_success [prereq] title - <<\EOT
body
EOT
A minor complication is that chainlint.pl has never considered heredoc bodies significant since it doesn't scan them for semantic problems, thus it has always simply thrown them away. However, with the new test_expect_success calling sequence, heredoc bodies become meaningful, thus need to be captured.
--- t/chainlint.pl | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
t/chainlint.pl +22 -5
@@ -174,6 +174,10 @@ sub swallow_heredocs { $$b =~ /(?:\G|\n)$indent\Q$$tag[0]\E(?:\n|\z)/gc; if (pos($$b) > $start) { my $body = substr($$b, $start, pos($$b) - $start); + $self->{parser}->{heredocs}->{$$tag[0]} = { + content => substr($body, 0, length($body) - length($&)), + start_line => $self->{lineno}, + }; $self->{lineno} += () = $body =~ /\n/sg; next; }
@@ -232,7 +236,8 @@ sub new { my $self = bless { buff => [], stop => [], - output => [] + output => [], + heredocs => {}, } => $class; $self->{lexer} = Lexer->new($self, $s); return $self;
@@ -616,14 +621,21 @@ sub unwrap { sub check_test { my $self = shift @_; - my ($title, $body) = map(unwrap, @_); + my $title = unwrap(shift @_); + my $body = shift @_; + my $lineno = $body->[3]; + $body = unwrap($body); + if ($body eq '-') { + my $herebody = shift @_; + $body = $herebody->{content}; + $lineno = $herebody->{start_line}; + } $self->{ntests}++; my $parser = TestParser->new(\$body); my @tokens = $parser->parse(); my $problems = $parser->{problems}; return unless $emit_all || @$problems; my $c = main::fd_colors(1); - my $lineno = $_[1]->[3]; my $start = 0; my $checked = ''; for (sort {$a->[1]->[2] <=> $b->[1]->[2]} @$problems) {
@@ -649,8 +661,13 @@ sub parse_cmd { return @tokens unless @tokens && $tokens[0]->[0] =~ /^test_expect_(?:success|failure)$/; my $n = $#tokens; $n-- while $n >= 0 && $tokens[$n]->[0] =~ /^(?:[;&\n|]|&&|\|\|)$/; - $self->check_test($tokens[1], $tokens[2]) if $n == 2; # title body - $self->check_test($tokens[2], $tokens[3]) if $n > 2; # prereq title body + my $herebody; + if ($n >= 2 && $tokens[$n-1]->[0] eq '-' && $tokens[$n]->[0] =~ /^<<-?(.+)$/) { + $herebody = $self->{heredocs}->{$1}; + $n--; + } + $self->check_test($tokens[1], $tokens[2], $herebody) if $n == 2; # title body + $self->check_test($tokens[2], $tokens[3], $herebody) if $n > 2; # prereq title body return @tokens; }
Signature · 1 line
2.45.2.1249.gb036353db5
PATCH v2 7/9 chainlint.pl: add tests for test body in heredoc
In reply to Jeff KingThe 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.
--- t/chainlint/here-doc-body-indent.expect | 2 ++ t/chainlint/here-doc-body-indent.test | 4 ++++ t/chainlint/here-doc-body-pathological.expect | 7 +++++++ t/chainlint/here-doc-body-pathological.test | 9 +++++++++ t/chainlint/here-doc-body.expect | 7 +++++++ t/chainlint/here-doc-body.test | 9 +++++++++ t/chainlint/here-doc-double.expect | 2 ++ t/chainlint/here-doc-double.test | 10 ++++++++++ 8 files changed, 50 insertions(+) create mode 100644 t/chainlint/here-doc-body-indent.expect create mode 100644 t/chainlint/here-doc-body-indent.test create mode 100644 t/chainlint/here-doc-body-pathological.expect create mode 100644 t/chainlint/here-doc-body-pathological.test create mode 100644 t/chainlint/here-doc-body.expect create mode 100644 t/chainlint/here-doc-body.test create mode 100644 t/chainlint/here-doc-double.expect create mode 100644 t/chainlint/here-doc-double.test
t/chainlint/here-doc-body-indent.expect new file +2 -0
@@ -0,0 +1,2 @@ +2 echo "we should find this" ?!AMP?! +3 echo "even though our heredoc has its indent stripped"
t/chainlint/here-doc-body-indent.test new file +4 -0
@@ -0,0 +1,4 @@ +test_expect_success 'here-doc-body-indent' - <<-\EOT + echo "we should find this" + echo "even though our heredoc has its indent stripped" +EOT
t/chainlint/here-doc-body-pathological.expect new file +7 -0
@@ -0,0 +1,7 @@ +2 echo "outer here-doc does not allow indented end-tag" ?!AMP?! +3 cat >file <<-\EOF && +4 but this inner here-doc +5 does allow indented EOF +6 EOF +7 echo "missing chain after" ?!AMP?! +8 echo "but this line is OK because it's the end"
t/chainlint/here-doc-body-pathological.test new file +9 -0
@@ -0,0 +1,9 @@ +test_expect_success 'here-doc-body-pathological' - <<\EOF + echo "outer here-doc does not allow indented end-tag" + cat >file <<-\EOF && + but this inner here-doc + does allow indented EOF + EOF + echo "missing chain after" + echo "but this line is OK because it's the end" +EOF
t/chainlint/here-doc-body.expect new file +7 -0
@@ -0,0 +1,7 @@ +2 echo "missing chain before" ?!AMP?! +3 cat >file <<-\EOF && +4 inside inner here-doc +5 these are not shell commands +6 EOF +7 echo "missing chain after" ?!AMP?! +8 echo "but this line is OK because it's the end"
t/chainlint/here-doc-body.test new file +9 -0
@@ -0,0 +1,9 @@ +test_expect_success 'here-doc-body' - <<\EOT + echo "missing chain before" + cat >file <<-\EOF && + inside inner here-doc + these are not shell commands + EOF + echo "missing chain after" + echo "but this line is OK because it's the end" +EOT
t/chainlint/here-doc-double.expect new file +2 -0
@@ -0,0 +1,2 @@ +8 echo "actual test commands" ?!AMP?! +9 echo "that should be checked"
t/chainlint/here-doc-double.test new file +10 -0
@@ -0,0 +1,10 @@ +# This is obviously a ridiculous thing to do, but we should be able +# to handle two here-docs on the same line, and attribute them +# correctly. +test_expect_success "$(cat <<END_OF_PREREQS)" 'here-doc-double' - <<\EOT +SOME +PREREQS +END_OF_PREREQS + echo "actual test commands" + echo "that should be checked" +EOT
Signature · 1 line
2.45.2.1249.gb036353db5
PATCH v2 8/9 test-lib: allow test snippets as here-docs
In reply to Jeff KingMost test snippets are wrapped in single quotes, like:
test_expect_success 'some description' '
do_something
'
This sometimes makes the snippets awkward to write, because you can't easily use single quotes within them. We sometimes work around this with $SQ, or by loosening regexes to use "." instead of a literal quote, or by using double quotes when we'd prefer to use single-quotes (and just adding extra backslash-escapes to avoid interpolation).
This commit adds another option: feeding the snippet via the function's stdin. This doesn't conflict with anything the snippet would want to do, because we always redirect its stdin from /dev/null anyway (which we'll continue to do).
A few notes on the implementation:
- it would be nice to push this down into test_run_, but we can't, as test_expect_success and test_expect_failure want to see the actual script content to report it for verbose-mode. A helper function limits the amount of duplication in those callers here.
- The helper function is a little awkward to call, as you feed it the name of the variable you want to set. The more natural thing in shell would be command substitution like:
body=$(body_or_stdin "$2")
but that loses trailing whitespace. There are tricks around this, like:
body=$(body_or_stdin "$2"; printf .)
body=${body%.}
but we'd prefer to keep such tricks in the helper, not in each caller.
- I implemented the helper using a sequence of "read" calls. Together with "-r" and unsetting the IFS, this preserves incoming whitespace. An alternative is to use "cat" (which then requires the gross "." trick above). But this saves us a process, which is probably a good thing. The "read" builtin does use more read() syscalls than necessary (one per byte), but that is almost certainly a win over a separate process.
Both are probably slower than passing a single-quoted string, but the difference is lost in the noise for a script that I converted as an experiment.
- I handle test_expect_success and test_expect_failure here. If we like this style, we could easily extend it to other spots (e.g., lazy_prereq bodies) on top of this patch.
- even though we are using "local", we have to be careful about our variable names. Within test_expect_success, any variable we declare with local will be seen as local by the test snippets themselves (so it wouldn't persist between tests like normal variables would).
--- t/README | 8 ++++++++ t/test-lib-functions.sh | 32 +++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-)
t/README +8 -0
@@ -906,6 +906,14 @@ see test-lib-functions.sh for the full list and their options. 'git-write-tree should be able to write an empty tree.' \ 'tree=$(git-write-tree)' + If <script> is `-` (a single dash), then the script to run is read + from stdin. This lets you more easily use single quotes within the + script by using a here-doc. For example: + + test_expect_success 'output contains expected string' - <<\EOT + grep "this string has 'quotes' in it" output + EOT + If you supply three parameters the first will be taken to be a prerequisite; see the test_set_prereq and test_have_prereq documentation below:
t/test-lib-functions.sh +27 -5
@@ -872,6 +872,24 @@ test_verify_prereq () { BUG "'$test_prereq' does not look like a prereq" } +# assign the variable named by "$1" with the contents of "$2"; +# if "$2" is "-", then read stdin into "$1" instead +test_body_or_stdin () { + if test "$2" != "-" + then + eval "$1=\$2" + return + fi + + # start with a newline, to match hanging newline from open-quote style + eval "$1=\$LF" + local test_line + while IFS= read -r test_line + do + eval "$1=\${$1}\${test_line}\${LF}" + done +} + test_expect_failure () { test_start_ "$@" test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
@@ -881,9 +899,11 @@ test_expect_failure () { export test_prereq if ! test_skip "$@" then + local test_body + test_body_or_stdin test_body "$2" test -n "$test_skip_test_preamble" || - say >&3 "checking known breakage of $TEST_NUMBER.$test_count '$1': $2" - if test_run_ "$2" expecting_failure + say >&3 "checking known breakage of $TEST_NUMBER.$test_count '$1': $test_body" + if test_run_ "$test_body" expecting_failure then test_known_broken_ok_ "$1" else
@@ -902,13 +922,15 @@ test_expect_success () { export test_prereq if ! test_skip "$@" then + local test_body + test_body_or_stdin test_body "$2" test -n "$test_skip_test_preamble" || - say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $2" - if test_run_ "$2" + say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $test_body" + if test_run_ "$test_body" then test_ok_ "$1" else - test_failure_ "$@" + test_failure_ "$1" "$test_body" fi fi test_finish_
Signature · 1 line
2.45.2.1249.gb036353db5
PATCH v2 9/9 t: convert some here-doc test bodies
In reply to Jeff KingThe t1404 script checks a lot of output from Git which contains single quotes. Because the test snippets are themselves wrapped in the same single-quotes, we have to resort to using $SQ to match them. This is error-prone and makes the tests harder to read.
Instead, let's use the new here-doc feature added in the previous commit, which lets us write anything in the test body we want (except the here-doc end marker on a line by itself, of course).
Note that we do use "\" in our marker to avoid interpolation (which is the whole point). But we don't use "<<-", as we want to preserve whitespace in the snippet (and running with "-v" before and after shows that we produce the exact same output, except with the ugly $SQ references fixed).
I just converted every test here, even though only some of them use $SQ. But it would be equally correct to mix-and-match styles if we don't mind the inconsistency.
I've also converted a few tests in t0600 which were moved from t1404 (I had written this patch before they were moved, but it seemed worth porting over the changes rather than losing them).
--- t/t0600-reffiles-backend.sh | 38 +++---- t/t1404-update-ref-errors.sh | 196 +++++++++++++++++------------------ 2 files changed, 117 insertions(+), 117 deletions(-)
t/t0600-reffiles-backend.sh +19 -19
@@ -91,82 +91,82 @@ test_expect_success 'empty directory should not fool 1-arg delete' ' git update-ref --stdin ' -test_expect_success 'non-empty directory blocks create' ' +test_expect_success 'non-empty directory blocks create' - <<\EOT prefix=refs/ne-create && mkdir -p .git/$prefix/foo/bar && : >.git/$prefix/foo/bar/baz.lock && test_when_finished "rm -f .git/$prefix/foo/bar/baz.lock" && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/foo$SQ: there is a non-empty directory $SQ.git/$prefix/foo$SQ blocking reference $SQ$prefix/foo$SQ + fatal: cannot lock ref '$prefix/foo': there is a non-empty directory '.git/$prefix/foo' blocking reference '$prefix/foo' EOF printf "%s\n" "update $prefix/foo $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ + fatal: cannot lock ref '$prefix/foo': unable to resolve reference '$prefix/foo' EOF printf "%s\n" "update $prefix/foo $D $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err -' +EOT -test_expect_success 'broken reference blocks create' ' +test_expect_success 'broken reference blocks create' - <<\EOT prefix=refs/broken-create && mkdir -p .git/$prefix && echo "gobbledigook" >.git/$prefix/foo && test_when_finished "rm -f .git/$prefix/foo" && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken + fatal: cannot lock ref '$prefix/foo': unable to resolve reference '$prefix/foo': reference broken EOF printf "%s\n" "update $prefix/foo $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken + fatal: cannot lock ref '$prefix/foo': unable to resolve reference '$prefix/foo': reference broken EOF printf "%s\n" "update $prefix/foo $D $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err -' +EOT -test_expect_success 'non-empty directory blocks indirect create' ' +test_expect_success 'non-empty directory blocks indirect create' - <<\EOT prefix=refs/ne-indirect-create && git symbolic-ref $prefix/symref $prefix/foo && mkdir -p .git/$prefix/foo/bar && : >.git/$prefix/foo/bar/baz.lock && test_when_finished "rm -f .git/$prefix/foo/bar/baz.lock" && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/symref$SQ: there is a non-empty directory $SQ.git/$prefix/foo$SQ blocking reference $SQ$prefix/foo$SQ + fatal: cannot lock ref '$prefix/symref': there is a non-empty directory '.git/$prefix/foo' blocking reference '$prefix/foo' EOF printf "%s\n" "update $prefix/symref $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ + fatal: cannot lock ref '$prefix/symref': unable to resolve reference '$prefix/foo' EOF printf "%s\n" "update $prefix/symref $D $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err -' +EOT -test_expect_success 'broken reference blocks indirect create' ' +test_expect_success 'broken reference blocks indirect create' - <<\EOT prefix=refs/broken-indirect-create && git symbolic-ref $prefix/symref $prefix/foo && echo "gobbledigook" >.git/$prefix/foo && test_when_finished "rm -f .git/$prefix/foo" && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken + fatal: cannot lock ref '$prefix/symref': unable to resolve reference '$prefix/foo': reference broken EOF printf "%s\n" "update $prefix/symref $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err && cat >expected <<-EOF && - fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken + fatal: cannot lock ref '$prefix/symref': unable to resolve reference '$prefix/foo': reference broken EOF printf "%s\n" "update $prefix/symref $D $C" | test_must_fail git update-ref --stdin 2>output.err && test_cmp expected output.err -' +EOT test_expect_success 'no bogus intermediate values during delete' ' prefix=refs/slow-transaction &&
@@ -224,7 +224,7 @@ test_expect_success 'no bogus intermediate values during delete' ' test_must_fail git rev-parse --verify --quiet $prefix/foo ' -test_expect_success 'delete fails cleanly if packed-refs file is locked' ' +test_expect_success 'delete fails cleanly if packed-refs file is locked' - <<\EOT prefix=refs/locked-packed-refs && # Set up a reference with differing loose and packed versions: git update-ref $prefix/foo $C &&
@@ -236,9 +236,9 @@ test_expect_success 'delete fails cleanly if packed-refs file is locked' ' test_when_finished "rm -f .git/packed-refs.lock" && test_must_fail git update-ref -d $prefix/foo >out 2>err && git for-each-ref $prefix >actual && - test_grep "Unable to create $SQ.*packed-refs.lock$SQ: " err && + test_grep "Unable to create '.*packed-refs.lock': " err && test_cmp unchanged actual -' +EOT test_expect_success 'delete fails cleanly if packed-refs.new write fails' ' # Setup and expectations are similar to the test above.
t/t1404-update-ref-errors.sh +98 -98
395 lines not on this page · raw message
Signature · 1 line
2.45.2.1249.gb036353db5
[PATCH v2 10/9] t/.gitattributes: ignore whitespace in chainlint expect files
In reply to Jeff KingQuoted 1 line · Jeff King
[5/9]: chainlint.pl: check line numbers in expected output
I just noticed that this one throws off a bunch of whitespace errors when you apply it. We might want this on top of the series:
-- >8 --
Subject: t/.gitattributes: ignore whitespace in chainlint expect files
The ".expect" files in t/chainlint/ are snippets of expected output from the chainlint script, and do not necessarily conform to our usual code style. Especially with the recent change to retain line numbers, blank lines in the input script end up with trailing whitespace as we print "3 " for line 3, for example. The point of these files is to match the output verbatim, so let's not complain about the trailing spaces.
--- t/.gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/.gitattributes +1 -1
@@ -1,5 +1,5 @@ t[0-9][0-9][0-9][0-9]/* -whitespace -/chainlint/*.expect eol=lf +/chainlint/*.expect eol=lf -whitespace /t0110/url-* binary /t3206/* eol=lf /t3900/*.txt eol=lf
Signature · 1 line
2.45.2.1249.gb036353db5
Re: [PATCH v2 10/9] t/.gitattributes: ignore whitespace in chainlint expect files
Quoted 6 lines · Jeff King
Quoted 1 line · Jeff King
[5/9]: chainlint.pl: check line numbers in expected output
I just noticed that this one throws off a bunch of whitespace errors when you apply it. We might want this on top of the series:
Or at the bottom ;-) I do agree with the reasoning.
Thanks.
Quoted 26 lines
-- >8 --
Subject: t/.gitattributes: ignore whitespace in chainlint expect filesThe ".expect" files in t/chainlint/ are snippets of expected output from the chainlint script, and do not necessarily conform to our usual code style. Especially with the recent change to retain line numbers, blank lines in the input script end up with trailing whitespace as we print "3 " for line 3, for example. The point of these files is to match the output verbatim, so let's not complain about the trailing spaces.
Signed-off-by Jeff King <[email protected]>--- t/.gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)t/.gitattributes +1
-1@@ -1,5 +1,5 @@ t[0-9][0-9][0-9][0-9]/* -whitespace -/chainlint/*.expect eol=lf +/chainlint/*.expect eol=lf -whitespace /t0110/url-* binary /t3206/* eol=lf /t3900/*.txt eol=lf
Re: [PATCH v2 0/9] here-doc test bodies (now with 100% more chainlinting)
In reply to Jeff KingQuoted 7 lines · Jeff King
And here's a v2 that addresses the chainlint issue mentioned by Eric. There were a lot of patches flying around, but this is only the second posting of the whole topic. This can replace all of what's in jk/test-body-in-here-doc.
I won't bother with a range diff; patches 8 and 9 are just the original v1 patches verbatim, and everything else is new.
Sorry for the late response; I only just got around to reading this series (which, I know, is already in "master").
With the possible exception of one question I asked[*] about patch 5/9, the entire series looks good. Thanks.
[*]: https://lore.kernel.org/git/CAPig+cTACjostXvjJMnLEpgbnfat9cjM63pLXwNJm1=2P3gq8g@mail.gmail.com/