From: SZEDER Gábor Date: Fri, 25 Mar 2016 14:46:38 GMT Subject: Re: [PATCH v9 2/3] t7507-commit-verbose: make test suite use write_script Message-ID: <20160325154638.Horde.LzlsD6cZcQfmt894cll_0Tl@webmail.informatik.kit.edu> In-Reply-To: Quoting Eric Sunshine : > On Thu, Mar 24, 2016 at 7:00 AM, SZEDER Gábor wrote: >>> diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh >>> index 2ddf28c..cf95efb 100755 >>> --- a/t/t7507-commit-verbose.sh >>> +++ b/t/t7507-commit-verbose.sh >>> @@ -3,12 +3,11 @@ >>> test_description='verbose commit template' >>> . ./test-lib.sh >>> >>> -cat >check-for-diff <>> -#!$SHELL_PATH >>> -exec grep '^diff --git' "\$1" >>> +write_script "check-for-diff" <<-\EOF && >>> +grep '^diff --git' "$1" >out && >>> +test $(wc -l > >> Our test lib offers the test_line_count helper function, which >> outputs a helpful error message in case the number of lines do not >> match. > > test_line_count() was mentioned in [2], however, this line counting is > done in the fake "editor" script, not in the test script proper, so > the spelled-out form $(wc ...) was proposed[2]. Ah, yes, of course. But then the question is: why is the line counting in the editor script in the first place? By redirecting grep's output to a file in the editor script, like this patch wanted to, we can count the lines in the test script itself after 'git commit' finished. This way we could use test_line_count, with all its error reporting benefits, and we could use the same editor script for all tests. And if you insist on doing the line counting in the editor script, then why redirecting grep's output and 'wc -l' separately, why not 'grep -c'?