Re: [PATCH 6/6] t4124: fix test for non-compliance diff
- From
Jeff King <peff@peff.net>
- Date
- Mar 20, 2020, 05:23 UTC
- Message-ID
- <20200320052314.GB499858@coredump.intra.peff.net>
- In-Reply-To
- <20200320015223.GG1858@danh.dev>
On Fri, Mar 20, 2020 at 08:52:23AM +0700, Danh Doan wrote:
Show 34 quoted lines
> > diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh
> > index 971a5a7512..15cb0c81b7 100755
> > --- a/t/t4124-apply-ws-rule.sh
> > +++ b/t/t4124-apply-ws-rule.sh
> > @@ -50,8 +50,9 @@ test_fix () {
> > # fix should not barf
> > apply_patch --whitespace=fix || return 1
> >
> > - # find touched lines
> > - $DIFF file target | sed -n -e "s/^> //p" >fixed
> > + # find touched lines; handle either normal or unified
> > + # diff, as system diff may generate either
> > + $DIFF file target | grep '^[>+][^+]' >fixed
> >
> > # the changed lines are all expected to change
> > fixed_cnt=$(wc -l <fixed)
> >
> > seems to work for with both busybox diff and GNU diff.
>
> 3 lines after this one:
>
> ?*) expect_cnt=$(grep "[$1]" <fixed | wc -l) ;;
>
> As of now, we could simply replace sed with grep entirely,
> because ! "$1" ~"[>+]".
>
> Considering the complicated of:
>
> test_expect_success "rule=$rule" '
> git config core.whitespace "$rule" &&
> test_fix "$tt$ts$ti$th"
> '
>
> I think it's better to use sed here.Fair enough. I think it's OK now, but I agree that it puts a pretty subtle assumption into the test_fix function (and that's far removed from what actual tests will call it with, so it's easy to miss). Using sed should be more maintainable.
-Peff