diff mbox series

[RFC,v2,2/4] t1510-repo-setup: don't use exact matching on traces

Message ID 20210423001539.4059524-3-emilyshaffer@google.com (mailing list archive)
State New, archived
Headers show
Series share a config between submodule and superproject | expand

Commit Message

Emily Shaffer April 23, 2021, 12:15 a.m. UTC
Tests which interrogate the exact underlying behavior of the code under
test, instead of checking for the presence of desired side effects or
calls, are a known testing antipattern. They are flaky as they need to
be updated every time the underlying implementation changes.

By using 'grep --fixed-strings --file <expect>' instead, we can check
for the positive presence of lines we are sure should be happening, and
ignore any additional things which may be happening around us (for
example, additional child processes which are occurring unrelated to the
code under test).

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
 t/t1510-repo-setup.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Phillip Wood April 23, 2021, 9:59 a.m. UTC | #1
Hi Emily

On 23/04/2021 01:15, Emily Shaffer wrote:
> Tests which interrogate the exact underlying behavior of the code under
> test, instead of checking for the presence of desired side effects or
> calls, are a known testing antipattern. They are flaky as they need to
> be updated every time the underlying implementation changes.
> 
> By using 'grep --fixed-strings --file <expect>' instead, we can check
> for the positive presence of lines we are sure should be happening, and
> ignore any additional things which may be happening around us (for
> example, additional child processes which are occurring unrelated to the
> code under test).
 >
> Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
> ---
>   t/t1510-repo-setup.sh | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh
> index bbfe05b8e4..8bd4f54d03 100755
> --- a/t/t1510-repo-setup.sh
> +++ b/t/t1510-repo-setup.sh
> @@ -63,7 +63,7 @@ test_repo () {
>   		rm -f trace &&
>   		GIT_TRACE_SETUP="$(pwd)/trace" git symbolic-ref HEAD >/dev/null &&
>   		grep '^setup: ' trace >result &&
> -		test_cmp expected result
> +		grep -Ff expected result

If there is more than one line in expected (it's not clear from the 
limited context if there is) then grep will succeed if any of the lines 
match rather than requiring all the lines to match as test_cmp does.

Best wishes

Phillip

>   	)
>   }
>   
>
diff mbox series

Patch

diff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh
index bbfe05b8e4..8bd4f54d03 100755
--- a/t/t1510-repo-setup.sh
+++ b/t/t1510-repo-setup.sh
@@ -63,7 +63,7 @@  test_repo () {
 		rm -f trace &&
 		GIT_TRACE_SETUP="$(pwd)/trace" git symbolic-ref HEAD >/dev/null &&
 		grep '^setup: ' trace >result &&
-		test_cmp expected result
+		grep -Ff expected result
 	)
 }