Subject: Re: [PATCH v2 3/5] t0041: use test_line_count_cmd to check std{out,err}

From: Đoàn Trần Công Danh <[email-masked]>
Date: Wed, 16 Jun 2021 21:21:54 +0700

On 2021-06-16 12:06:14+0900, Junio C Hamano <[email-masked]> wrote:
> Đoàn Trần Công Danh  <[email-masked]> writes:
> 
> >  test_expect_success 'tag --contains <existent_tag>' '
> > -	git tag --contains "v1.0" >actual 2>actual.err &&
> > -	grep "v1.0" actual &&
> > -	test_line_count = 0 actual.err
> > +	test_line_count_cmd --err = 0 git tag --contains v1.0 >actual &&
> > +	grep "v1.0" actual
> 
> Sorry, but I am not impressed if this is a typical/prime example of
> how the new helper helps in writing our tests.

Yay, reading through the patch again, and I'm become less enthusiastic
with persuading --err. The only useful application of --err is t4068.
----8<---
diff --git a/t/t4068-diff-symmetric-merge-base.sh b/t/t4068-diff-symmetric-merge-base.sh
index 2d650d8f10..33e2327072 100755
--- a/t/t4068-diff-symmetric-merge-base.sh
+++ b/t/t4068-diff-symmetric-merge-base.sh
@@ -61,9 +61,7 @@ test_expect_success 'diff with one merge base' '
 # It should have one of those two, which comes out
 # to seven lines.
 test_expect_success 'diff with two merge bases' '
-	git diff br1...main >tmp 2>err &&
-	test_line_count = 7 tmp &&
-	test_line_count = 1 err
+	test_line_count_cmd --out = 7 --err = 1 git diff br1...main
 '
 
 test_expect_success 'diff with no merge bases' '
----->8----

However, going through all the trouble for a single application is not
really worth it.  I'm going to drop --err, remove --out option, too.
So, its prototype would be:

	test_line_count_cmd <op> <val> [!] cmd [args...]

> Notice that so many tests that you touched only care about 0 lines?
> 
> Instead of this new helper, I think it would be a more useful
> improvement if we check the emptyness in a more direct way, i.e.
> 
> >  test_expect_success 'tag --contains <existent_tag>' '
> > 	git tag --contains "v1.0" >actual 2>actual.err &&
> > 	grep "v1.0" actual &&
> > -	test_line_count = 0 actual.err
> > +	test_must_be_empty actual.err
> 
> I think this helper may be misnamed and test_file_is_empty would sit
> better with test_dir_is_empty and test_file_not_empty that already
> exist, though.

That would be an improvement, but it should be written in a different
series.

> 
> By the way, my opinion would be quite different if example like this
> one ...
> 
> >  test_expect_success 'tag --no-contains <existent_tag>' '
> > -	git tag --no-contains "v1.0" >actual 2>actual.err  &&
> > -	test_line_count = 0 actual &&
> > -	test_line_count = 0 actual.err
> > +	test_line_count_cmd --out = 0 --err = 0 git tag --no-contains v1.0
> >  '
> 
> ... were the majority, but I do not think that is the case.  Most
> tests that employ the new test_line_count_cmd in this patch still
> create either actual or actual.err in the working tree anyway, so I
> do not see much point in adding this new helper---it is hard to
> explain to new test writers when to use it.

I'm not sure if I get your opinion.  Did you mean you wouldn't take
whole helper? Or you meant you still wanted to see a new helper for
checking only stdout?  If it's the former, I'll send a different
series to only clean "git ls-files ... | wc -l" in t6400 and t6402,
if it's the latter, I'll rewrite without --err.

-- 
Danh