Re: [PATCH v3 0/2] [Outreachy][Patch v2] t3404: avoid losing exit status to pipes
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Oct 7, 2024, 08:11 UTC
- Message-ID
- <CAPig+cTGESaCMfCzP7Zt3Y6JmG_uroCn1cd6_12W1QKLU7hk8A@mail.gmail.com>
- In-Reply-To
- <ZwOW96K1_12Kzefo@pks.im>
On Mon, Oct 7, 2024 at 4:08 AM Patrick Steinhardt <ps@pks.im> wrote:
Show 10 quoted lines
> On Mon, Oct 07, 2024 at 07:25:44AM +0000, Usman Akinyemi wrote: > > test $base = $(git rev-parse HEAD^) && > > git show >output && > > grep NEVER output >actual && > > test_must_be_empty actual && > > That makes sense. The expectation here is that `output` shouldn't > contain the string "NEVER" at all. And as grep(1) would fail when it > doesn't find a match the whole test would fail like this. So the below > would likely be the best solution.
Thanks. I was just about to respond with the same answer. As a bit of extra explanation, the &&-chaining means that every command in the chain must return "success" (status 0), but the return code of `grep` depends upon whether or not it matched any lines. In this case, it returned non-zero which caused the test to fail.