On Mon, Jul 2, 2018 at 2:14 PM Stefan Beller <sbel...@google.com> wrote:
> On Sun, Jul 1, 2018 at 5:25 PM Eric Sunshine <sunsh...@sunshineco.com> wrote:
> >  test_expect_success 'grep from a subdirectory to search wider area (2)' '
> >         mkdir -p s &&
> >         (
> > -               cd s || exit 1
> > -               ( git grep xxyyzz .. >out ; echo $? >status )
> > -               ! test -s out &&
> > -               test 1 = $(cat status)
> > +               cd s &&
> > +               test_expect_code 1 git grep xxyyzz .. >out &&
> > +               ! test -s out
> >         )
>
> Further optimisation would be possible if I understand the code correctly:
>
>     test_expect_code git -C s grep xxyyzz .. >../out
>     test_must_be_empty out
>
> (dropping the subshell entirely)

I did consider dropping the subshell in favor of -C, however, decided
to keep it since the subshell has value by making it very explicit to
the reader that this git-grep command is running in a subdirectory
(which is what this test is all about). Contrast that with -C which is
easy to overlook and might not fully convince the reader that the
command's entire execution is within the subdirectory, whereas there
is no question that the entire execution of git-diff in "(cd s &&
git-diff ...)" occurs in the subdirectory.

I can make the test_must_be_empty() change if I re-roll.

Reply via email to