Factor out logic in test_diff_funcname() into two helper functions, these will be useful in a follow-up commit where we'll do this munging in more than one place. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> --- t/t4018-diff-funcname.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index 3ba9d657b1..2efe4e5bdd 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -41,6 +41,17 @@ test_expect_success 'last regexp must not be negated' ' test_i18ngrep ": Last expression must not be negated:" msg ' +do_change_me () { + file=$1 + sed -e "s/ChangeMe/IWasChanged/" <"$file" >tmp && + mv tmp "$file" +} + +last_diff_context_line () { + file=$1 + sed -n -e "s/^.*@@$//p" -e "s/^.*@@ //p" <$file +} + test_diff_funcname () { desc=$1 cat <&8 >arg.header && @@ -51,13 +62,12 @@ test_diff_funcname () { cp arg.test "$what" && cp arg.header expected && git add "$what" && - sed -e "s/ChangeMe/IWasChanged/" <"$what" >tmp && - mv tmp "$what" + do_change_me "$what" ' && test_expect_success "$desc" ' git diff -U1 "$what" >diff && - sed -n -e "s/^.*@@$//p" -e "s/^.*@@ //p" <diff >actual && + last_diff_context_line diff >actual && test_cmp expected actual ' && -- 2.30.0.284.gd98b1dd5eaa7