t7810: improve check of -W with user-defined function lines

The check for function context (-W) together with user-defined function line patterns reuses hello.c and pretends it's written in a language in which function lines contain either "printf" or a trailing curly brace. That's a bit obscure. Make the test easier to read by adding a small PowerShell script, using a simple, but meaningful expression, and separating out checks for different aspects into dedicated tests instead of simply matching the whole output byte for byte. Also include a test for showing comments before function lines like git Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Nov 18, 2017 at 19:06 UTC 76e650d7d95662749fa5cbcc9f4faefb510334b0
1 file changed +31 -10
t/t7810-grep.sh
+31 -10
@@ -60,6 +60,18 @@ test_expect_success setup '
60 echo " line with leading space3"
61 echo "line without leading space2"
62 } >space &&
63 + cat >hello.ps1 <<-\EOF &&
64 + # No-op.
65 + function dummy() {}
66 +
67 + # Say hello.
68 + function hello() {
69 + echo "Hello world."
70 + } # hello
71 +
72 + # Still a no-op.
73 + function dummy() {}
74 + EOF
75 git add . &&
76 test_tick &&
77 git commit -m initial
@@ -766,18 +778,27 @@ test_expect_success 'grep -W shows no trailing empty lines' '
778 test_cmp expected actual
779 '
780
769 -cat >expected <<EOF
770 -hello.c= printf("Hello world.\n");
771 -hello.c: return 0;
772 -hello.c- /* char ?? */
773 -EOF
774 -
781 test_expect_success 'grep -W with userdiff' '
782 test_when_finished "rm -f .gitattributes" &&
777 - git config diff.custom.xfuncname "(printf.*|})$" &&
778 - echo "hello.c diff=custom" >.gitattributes &&
779 - git grep -W return >actual &&
780 - test_cmp expected actual
783 + git config diff.custom.xfuncname "^function .*$" &&
784 + echo "hello.ps1 diff=custom" >.gitattributes &&
785 + git grep -W echo >function-context-userdiff-actual
786 +'
787 +
788 +test_expect_failure ' includes preceding comment' '
789 + grep "# Say hello" function-context-userdiff-actual
790 +'
791 +
792 +test_expect_success ' includes function line' '
793 + grep "=function hello" function-context-userdiff-actual
794 +'
795 +
796 +test_expect_success ' includes matching line' '
797 + grep ": echo" function-context-userdiff-actual
798 +'
799 +
800 +test_expect_success ' includes last line of the function' '
801 + grep "} # hello" function-context-userdiff-actual
802 '
803
804 for threads in $(test_seq 0 10)