Subject: Re: [PATCH v2 09/27] userdiff tests: match full hunk headers

From: Junio C Hamano <[email-masked]>
Date: Wed, 17 Feb 2021 11:01:32 -0800

Ævar Arnfjörð Bjarmason <[email-masked]> writes:

>>> +		sed -ne "s/^@@[^@]*@@//p" actual |
>>> +		if test -n "$HEAD"
>>> +		then
>>> +			grep -F "$HEAD"
>>> +		else
>>> +			grep "^.*RIGHT"
>>> +		fi
>>> +	'
>>>   done
>>>     test_done
>>
>>> diff --git c/t/t4018/bash-arithmetic-function w/t/t4018/bash-arithmetic-function
>>> index c0b276cb50..935f18d96d 100644
>>> --- c/t/t4018/bash-arithmetic-function
>>> +++ w/t/t4018/bash-arithmetic-function
>>> @@ -2,3 +2,6 @@ RIGHT() ((
>>>         ChangeMe = "$x" + "$y"
>>>   ))
>>> +
>>> +
>>> +# HEADER |right()|
>>> 
>>
>> Clever! Opt-in for those who desire precise tests.
>
> Tests aren't only for testing a subjective "good enough" in the
> estimation of the author of the code in question, but also for others
> who later touch the same area and want to avoid regressions.
>
> Which is why I think it's an anti-pattern to use "grep SOME-SUBSTR" in
> lieu of test_cmp if we can easily do the latter.

Sounds good.  It shouldn't be too hard to satisfy both camps,
i.e. the quoted demonstrates one way to allow test writers to
give expectation in-place in the single test file, and replacing
how it uses "grep" to check the output with test_cmp or whatever
wouldn't make the resulting tests too hard to write and maintain.