Skip to content

Commit 76e650d

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]>
1 parent 5c3ed90 commit 76e650d

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

t/t7810-grep.sh

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ test_expect_success setup '
6060
echo " line with leading space3"
6161
echo "line without leading space2"
6262
} >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
6375
git add . &&
6476
test_tick &&
6577
git commit -m initial
@@ -766,18 +778,27 @@ test_expect_success 'grep -W shows no trailing empty lines' '
766778
test_cmp expected actual
767779
'
768780

769-
cat >expected <<EOF
770-
hello.c= printf("Hello world.\n");
771-
hello.c: return 0;
772-
hello.c- /* char ?? */
773-
EOF
774-
775781
test_expect_success 'grep -W with userdiff' '
776782
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
781802
'
782803

783804
for threads in $(test_seq 0 10)

0 commit comments

Comments
 (0)