Message ID | 20210615172038.28917-4-congdanhqx@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | t: new helper test_line_count_cmd | expand |
Đoàn Trần Công Danh <congdanhqx@gmail.com> 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. 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. 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.
On 2021-06-16 12:06:14+0900, Junio C Hamano <gitster@pobox.com> wrote: > Đoàn Trần Công Danh <congdanhqx@gmail.com> 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.
Đoàn Trần Công Danh <congdanhqx@gmail.com> writes: >> 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. I did not see much point in adding test_line_count_cmd with --out and/or --err options; the upside of having it was dubious after looking at the users of it in the patch that we are discussing. I did not consider test_line_count_cmd that only works on the standard output stream. From the patch under discussion, it is not immediately obvious how much such a simplified helper would help clean up the existing tests, so I have no opinion without seeing at least some sample uses.
diff --git a/t/t0041-usage.sh b/t/t0041-usage.sh index c4fc34eb18..24e24f698c 100755 --- a/t/t0041-usage.sh +++ b/t/t0041-usage.sh @@ -12,98 +12,79 @@ test_expect_success 'setup ' ' ' 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 ' test_expect_success 'tag --contains <inexistent_tag>' ' - test_must_fail git tag --contains "notag" >actual 2>actual.err && - test_line_count = 0 actual && + test_line_count_cmd --out = 0 test_must_fail git tag --contains notag 2>actual.err && test_i18ngrep "error" actual.err && test_i18ngrep ! "usage" actual.err ' 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 ' test_expect_success 'tag --no-contains <inexistent_tag>' ' - test_must_fail git tag --no-contains "notag" >actual 2>actual.err && - test_line_count = 0 actual && + test_line_count_cmd --out = 0 test_must_fail git tag --no-contains notag 2>actual.err && test_i18ngrep "error" actual.err && test_i18ngrep ! "usage" actual.err ' test_expect_success 'tag usage error' ' - test_must_fail git tag --noopt >actual 2>actual.err && - test_line_count = 0 actual && + test_line_count_cmd --out = 0 test_must_fail git tag --noopt 2>actual.err && test_i18ngrep "usage" actual.err ' test_expect_success 'branch --contains <existent_commit>' ' - git branch --contains "main" >actual 2>actual.err && - test_i18ngrep "main" actual && - test_line_count = 0 actual.err + test_line_count_cmd --err = 0 git branch --contains main >actual && + test_i18ngrep "main" actual ' test_expect_success 'branch --contains <inexistent_commit>' ' - test_must_fail git branch --no-contains "nocommit" >actual 2>actual.err && - test_line_count = 0 actual && + test_line_count_cmd --out = 0 test_must_fail git branch --no-contains "nocommit" 2>actual.err && test_i18ngrep "error" actual.err && test_i18ngrep ! "usage" actual.err ' test_expect_success 'branch --no-contains <existent_commit>' ' - git branch --no-contains "main" >actual 2>actual.err && - test_line_count = 0 actual && - test_line_count = 0 actual.err + test_line_count_cmd --out = 0 --err = 0 git branch --no-contains main ' test_expect_success 'branch --no-contains <inexistent_commit>' ' - test_must_fail git branch --no-contains "nocommit" >actual 2>actual.err && - test_line_count = 0 actual && + test_line_count_cmd --out = 0 test_must_fail git branch --no-contains "nocommit" 2>actual.err && test_i18ngrep "error" actual.err && test_i18ngrep ! "usage" actual.err ' test_expect_success 'branch usage error' ' - test_must_fail git branch --noopt >actual 2>actual.err && - test_line_count = 0 actual && + test_line_count_cmd --out = 0 test_must_fail git branch --noopt 2>actual.err && test_i18ngrep "usage" actual.err ' test_expect_success 'for-each-ref --contains <existent_object>' ' - git for-each-ref --contains "main" >actual 2>actual.err && - test_line_count = 2 actual && - test_line_count = 0 actual.err + test_line_count_cmd --out = 2 --err = 0 git for-each-ref --contains main ' test_expect_success 'for-each-ref --contains <inexistent_object>' ' - test_must_fail git for-each-ref --no-contains "noobject" >actual 2>actual.err && - test_line_count = 0 actual && + test_line_count_cmd --out = 0 test_must_fail git for-each-ref --no-contains "noobject" 2>actual.err && test_i18ngrep "error" actual.err && test_i18ngrep ! "usage" actual.err ' test_expect_success 'for-each-ref --no-contains <existent_object>' ' - git for-each-ref --no-contains "main" >actual 2>actual.err && - test_line_count = 0 actual && - test_line_count = 0 actual.err + test_line_count_cmd --out = 0 --err = 0 git for-each-ref --no-contains "main" ' test_expect_success 'for-each-ref --no-contains <inexistent_object>' ' - test_must_fail git for-each-ref --no-contains "noobject" >actual 2>actual.err && - test_line_count = 0 actual && + test_line_count_cmd --out = 0 test_must_fail git for-each-ref --no-contains "noobject" 2>actual.err && test_i18ngrep "error" actual.err && test_i18ngrep ! "usage" actual.err ' test_expect_success 'for-each-ref usage error' ' - test_must_fail git for-each-ref --noopt >actual 2>actual.err && - test_line_count = 0 actual && + test_line_count_cmd --out = 0 test_must_fail git for-each-ref --noopt 2>actual.err && test_i18ngrep "usage" actual.err '
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> --- t/t0041-usage.sh | 53 ++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 36 deletions(-)