Re: [PATCH v9 2/3] t7507-commit-verbose: make test suite use write_script
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Mar 25, 2016, 17:04 UTC
- Message-ID
- <CAPig+cQLOwAimmHeUmi5+KScgOP0hr9-MiX8gyGcEk6Zj0U_jQ@mail.gmail.com>
- In-Reply-To
- <20160325154638.Horde.LzlsD6cZcQfmt894cll_0Tl@webmail.informatik.kit.edu>
On Fri, Mar 25, 2016 at 10:46 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:
Show 27 quoted lines
> Quoting Eric Sunshine <sunshine@sunshineco.com>: >> On Thu, Mar 24, 2016 at 7:00 AM, SZEDER Gábor <szeder@ira.uka.de> wrote: >>>> -cat >check-for-diff <<EOF >>>> -#!$SHELL_PATH >>>> -exec grep '^diff --git' "\$1" >>>> +write_script "check-for-diff" <<-\EOF && >>>> +grep '^diff --git' "$1" >out && >>>> +test $(wc -l <out) = 1 >>> >>> 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.
That works too, simplifying the overall implementation, and eliminating the need for the introductory patch which moves 'test_set_editor' into each test.
> 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'?
Ugh, I utterly forgot about -c.