> Use a filter when comparing diffs to fix the value of non-zero hashes
> in diff index lines so we're not hard coding sha1 hash values in the
> expected output. This makes it easier to change the expected output if
> a test is edited as we don't need to worry about the exact hash value
> and means the tests will work when the hash algorithm is transitioned
> away from sha1.
> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> index 836ce346ed..f95714230b 100755
> --- a/t/t3701-add-interactive.sh
> +++ b/t/t3701-add-interactive.sh
> @@ -10,6 +10,19 @@ then
> test_done
> fi
>
> +diff_cmp () {
> + for x
> + do
> + sed -e '/^index/s/[0-9a-f]*[1-9a-f][0-9a-f]*\.\./1234567../' \
> + -e '/^index/s/\.\.[0-9a-f]*[1-9a-f][0-9a-f]*/..9abcdef/' \
> + -e '/^index/s/ 00*\.\./ 0000000../' \
> + -e '/^index/s/\.\.00*$/..0000000/' \
> + -e '/^index/s/\.\.00* /..0000000 /' \
> + "$x" >"$x.filtered"
> + done
> + test_cmp "$1.filtered" "$2.filtered"
> +}
t3701 is not the only test script comparing diffs, many other
tests do so:
$ git grep 'diff --git' t/ |wc -l
835
It's totally inaccurate, but a good ballpark figure.
I think this function should be a widely available test helper
function in 'test-lib-functions.sh', perhaps renamed to
'test_cmp_diff', so those other tests could use it as well.