blame tests: simplify userdiff driver test

Simplify the test added in 9466e3809d (blame: enable funcname blaming with userdiff driver, 2020-11-01) to use the --author support recently added in 999cfc4f45 (test-lib functions: add --author support to test_commit, 2021-01-12). We also did not need the full fortran-external-function content. Let's cut it down to just the important parts. I'm modifying it to demonstrate that the fortran-specific userdiff function is in effect by adding "DO NOT MATCH ..." and "AS THE ..." lines surrounding the "RIGHT" one. This is to check that we're using the userdiff "fortran" driver, as opposed to the default driver which would match on those lines as part of the general heuristic of matching a line that doesn't begin with whitespace. The test had also been leaving behind a .gitattributes file for later tests to possibly trip over, let's clean it up with "test_when_finished". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Apr 8, 2021 at 17:04 UTC f08b4013c3faf5535ca8d5271ffb1840ce6ddaab
1 file changed +15 -21
t/annotate-tests.sh
+15 -21
@@ -479,32 +479,26 @@ test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
479 check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
480 '
481
482 -test_expect_success 'setup -L :funcname with userdiff driver' '
483 - echo "fortran-* diff=fortran" >.gitattributes &&
484 - fortran_file=fortran-external-function &&
485 - cat >$fortran_file <<-\EOF &&
482 +test_expect_success 'blame -L :funcname with userdiff driver' '
483 + cat >file.template <<-\EOF &&
484 + DO NOT MATCH THIS LINE
485 function RIGHT(a, b) result(c)
486 + AS THE DEFAULT DRIVER WOULD
487
488 integer, intent(in) :: ChangeMe
489 - integer, intent(in) :: b
490 - integer, intent(out) :: c
491 -
492 - c = a+b
493 -
494 - end function RIGHT
489 EOF
496 - git add "$fortran_file" &&
497 - GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" \
498 - git commit -m "add fortran file" &&
499 - sed -e "s/ChangeMe/IWasChanged/" <"$fortran_file" >"$fortran_file".tmp &&
500 - mv "$fortran_file".tmp "$fortran_file" &&
501 - git add "$fortran_file" &&
502 - GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \
503 - git commit -m "change fortran file"
504 -'
490
506 -test_expect_success 'blame -L :funcname with userdiff driver' '
507 - check_count -f fortran-external-function -L:RIGHT A 7 B 1
491 + fortran_file=file.f03 &&
492 + test_when_finished "rm .gitattributes" &&
493 + echo "$fortran_file diff=fortran" >.gitattributes &&
494 +
495 + test_commit --author "A <A@test.git>" \
496 + "add" "$fortran_file" \
497 + "$(cat file.template)" &&
498 + test_commit --author "B <B@test.git>" \
499 + "change" "$fortran_file" \
500 + "$(cat file.template | sed -e s/ChangeMe/IWasChanged/)" &&
501 + check_count -f "$fortran_file" -L:RIGHT A 3 B 1
502 '
503
504 test_expect_success 'setup incremental' '