Re: [PATCH v4 2/8] [Newcomer] t7004: Do not lose exit status to pipe
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Aug 6, 2024, 03:13 UTC
- Message-ID
- <CAPig+cS6-gqZbJSz3wBcummyycJVudKybVZW=D33WHk-Fa9ytQ@mail.gmail.com>
- In-Reply-To
- <20240805235917.190699-3-abdobngad@gmail.com>
On Mon, Aug 5, 2024 at 8:00 PM AbdAlRahman Gad <abdobngad@gmail.com> wrote:
Show 10 quoted lines
> Split "test-tool ... | sed" pipeline into two commands to avoid losing > exit status from test-tool. > > Signed-off-by: AbdAlRahman Gad <abdobngad@gmail.com> > --- > diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh > @@ -97,7 +97,8 @@ test_expect_success 'creating a tag with --create-reflog should create reflog' ' > - test-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog1 | sed -e "s/^.* //" >actual && > + test-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog1 >actual.body && > + sed -e "s/^.* //" actual.body >actual &&
It's not just `test_tool` we care about; we also (importantly) don't want to see `git` itself upstream of a pipe, and there are many such instances remaining in this script. Here are some common examples:
test $(git tag -l | wc -l) -eq 0 &&
git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
git tag -l | grep "^tag-one-line" >actual &&
forged=$(git cat-file tag ... | sed -e ... | git mktag) &&
git tag -l --no-sort "foo*" | sort >actual &&By the way, these days, rather than:
test $(git tag -l | wc -l) -eq 0 &&
we would say:
test_stdout_line_count = 0 git tag -l &&
which nicely avoids placing `git` upstream of a pipe.