# [PATCH] t7407: use test_grep

6 messages from 2025-01-07 to 2025-01-07. Participants: Jeff King, Patrick Steinhardt, Kristoffer Haugsbakk, Junio C Hamano, D. Ben Knoble.
Thread: https://gitlist.dev/t/62753

## Jeff King, 2025-01-07 07:18

Subject: [PATCH] t7407: use test_grep
Message-ID: <20250107071824.GA594237@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20250107071824.GA594237%40coredump.intra.peff.net

```
There are a few grep calls here that can benefit from test_grep, which
produces more user-friendly output when it fails.

One of these calls also passes "-sq", which is curious. The "-q" option
suppresses the matched output. But test output is either already
redirected to /dev/null in non-verbose mode, and in verbose mode it's
better to see the output. The "-s" option suppresses errors opening
files, but we are just grepping in the "expected" file we just
generated, so it should not be needed. Neither of these was really
hurting anything, but they are not a style we'd like to see emulated. So
get rid of them.

(It is also curious to grep in the expected file in the first place, but
that is because we are auto-generating the expectation from a Git
command. So this is double-checking it did what we wanted).

Signed-off-by: Jeff King <peff@peff.net>
---
Just something I noticed while working on an unrelated topic.

 t/t7407-submodule-foreach.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
index 8d7b234beb..77b6d0040e 100755
--- a/t/t7407-submodule-foreach.sh
+++ b/t/t7407-submodule-foreach.sh
@@ -426,14 +426,14 @@ test_expect_success 'option-like arguments passed to foreach commands are not lo
 		git submodule foreach "echo be --quiet" > ../expected &&
 		git submodule foreach echo be --quiet > ../actual
 	) &&
-	grep -sq -e "--quiet" expected &&
+	test_grep -e "--quiet" expected &&
 	test_cmp expected actual
 '
 
 test_expect_success 'option-like arguments passed to foreach recurse correctly' '
 	git -C clone2 submodule foreach --recursive "echo be --an-option" >expect &&
 	git -C clone2 submodule foreach --recursive echo be --an-option >actual &&
-	grep -e "--an-option" expect &&
+	test_grep -e "--an-option" expect &&
 	test_cmp expect actual
 '
 
-- 
2.48.0.rc2.377.g0507c08f68

```

## Patrick Steinhardt, 2025-01-07 09:57

Subject: Re: [PATCH] t7407: use test_grep
Message-ID: <Z3z6dKBRjQlsrwjZ@pks.im>
URL: https://gitlist.dev/e/Z3z6dKBRjQlsrwjZ%40pks.im
In-Reply-To: <20250107071824.GA594237@coredump.intra.peff.net>

```
On Tue, Jan 07, 2025 at 02:18:24AM -0500, Jeff King wrote:
> There are a few grep calls here that can benefit from test_grep, which
> produces more user-friendly output when it fails.
> 
> One of these calls also passes "-sq", which is curious. The "-q" option
> suppresses the matched output. But test output is either already
> redirected to /dev/null in non-verbose mode, and in verbose mode it's
> better to see the output. The "-s" option suppresses errors opening
> files, but we are just grepping in the "expected" file we just
> generated, so it should not be needed. Neither of these was really
> hurting anything, but they are not a style we'd like to see emulated. So
> get rid of them.
> 
> (It is also curious to grep in the expected file in the first place, but
> that is because we are auto-generating the expectation from a Git
> command. So this is double-checking it did what we wanted).
> 
> Signed-off-by: Jeff King <peff@peff.net>

Thanks, both of these look obviously good to me.

Patrick

```

## Kristoffer Haugsbakk, 2025-01-07 11:01

Subject: Re: [PATCH] t7407: use test_grep
Message-ID: <f3ab08db-5dff-4da3-a075-7e9b3eaf1f78@app.fastmail.com>
URL: https://gitlist.dev/e/f3ab08db-5dff-4da3-a075-7e9b3eaf1f78%40app.fastmail.com
In-Reply-To: <20250107071824.GA594237@coredump.intra.peff.net>

```
On Tue, Jan 7, 2025, at 08:18, Jeff King wrote:
> get rid of them.
>
> (It is also curious to grep in the expected file in the first place, but
> that is because we are auto-generating the expectation from a Git
> command. So this is double-checking it did what we wanted).

Missing “that”? s/it did/that it did/

```

## Junio C Hamano, 2025-01-07 19:42

Subject: Re: [PATCH] t7407: use test_grep
Message-ID: <xmqq5xmqs95j.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqq5xmqs95j.fsf%40gitster.g
In-Reply-To: <f3ab08db-5dff-4da3-a075-7e9b3eaf1f78@app.fastmail.com>

```
"Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com> writes:

> On Tue, Jan 7, 2025, at 08:18, Jeff King wrote:
>> get rid of them.
>>
>> (It is also curious to grep in the expected file in the first place, but
>> that is because we are auto-generating the expectation from a Git
>> command. So this is double-checking it did what we wanted).
>
> Missing “that”? s/it did/that it did/

It is colloquially correct, isn't it?


```

## Kristoffer Haugsbakk, 2025-01-07 22:09

Subject: Re: [PATCH] t7407: use test_grep
Message-ID: <8aa4e7d9-b77b-4f29-9564-5c1d4ec5be0a@app.fastmail.com>
URL: https://gitlist.dev/e/8aa4e7d9-b77b-4f29-9564-5c1d4ec5be0a%40app.fastmail.com
In-Reply-To: <xmqq5xmqs95j.fsf@gitster.g>

```
On Tue, Jan 7, 2025, at 20:42, Junio C Hamano wrote:
> "Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com> writes:
>
>> On Tue, Jan 7, 2025, at 08:18, Jeff King wrote:
>>> get rid of them.
>>>
>>> (It is also curious to grep in the expected file in the first place, but
>>> that is because we are auto-generating the expectation from a Git
>>> command. So this is double-checking it did what we wanted).
>>
>> Missing “that”? s/it did/that it did/
>
> It is colloquially correct, isn't it?

I’m just going by intuition but I couldn’t make it make
sense in my head/read out loud.

-- 
Kristoffer Haugsbakk


```

## D. Ben Knoble, 2025-01-07 23:36

Subject: Re: [PATCH] t7407: use test_grep
Message-ID: <CALnO6CAUZBB28vCjMF8HRxvdv=N6y6OVyXZF2Yh4rK8c-sQU1A@mail.gmail.com>
URL: https://gitlist.dev/e/CALnO6CAUZBB28vCjMF8HRxvdv%3DN6y6OVyXZF2Yh4rK8c-sQU1A%40mail.gmail.com
In-Reply-To: <xmqq5xmqs95j.fsf@gitster.g>

```
On Tue, Jan 7, 2025 at 2:42 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> "Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com> writes:
>
> > On Tue, Jan 7, 2025, at 08:18, Jeff King wrote:
> >> get rid of them.
> >>
> >> (It is also curious to grep in the expected file in the first place, but
> >> that is because we are auto-generating the expectation from a Git
> >> command. So this is double-checking it did what we wanted).
> >
> > Missing “that”? s/it did/that it did/
>
> It is colloquially correct, isn't it?
>
>

Reads fine to me.


-- 
D. Ben Knoble

```
