summaryrefslogtreecommitdiff
path: root/t/t4018-diff-funcname.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t4018-diff-funcname.sh')
-rwxr-xr-xt/t4018-diff-funcname.sh36
1 files changed, 36 insertions, 0 deletions
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 38a092a0da..1e80b157d9 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -93,6 +93,29 @@ sed -e '
s/song;/song();/
' <Beer.perl >Beer-correct.perl
+cat >Beer.c <<\EOF
+static int foo(void)
+{
+label:
+ int x = old;
+}
+
+struct foo; /* catch failure below */
+static int
+gnu(int arg)
+{
+ int x = old;
+}
+
+struct foo; /* catch failure below */
+int multiline(int arg,
+ char *arg2)
+{
+ int x = old;
+}
+EOF
+sed s/old/new/ <Beer.c >Beer-correct.c
+
test_expect_funcname () {
lang=${2-java}
test_expect_code 1 git diff --no-index -U1 \
@@ -127,6 +150,7 @@ test_expect_success 'set up .gitattributes declaring drivers to test' '
cat >.gitattributes <<-\EOF
*.java diff=java
*.perl diff=perl
+ *.c diff=cpp
EOF
'
@@ -158,6 +182,18 @@ test_expect_success 'perl pattern is not distracted by forward declaration' '
test_expect_funcname "package Beer;\$" perl
'
+test_expect_success 'c pattern skips labels' '
+ test_expect_funcname "static int foo(void)" c
+'
+
+test_expect_success 'c pattern matches GNU-style functions' '
+ test_expect_funcname "gnu(int arg)\$" c
+'
+
+test_expect_success 'c pattern matches multiline functions' '
+ test_expect_funcname "int multiline(int arg,\$" c
+'
+
test_expect_success 'custom pattern' '
test_config diff.java.funcname "!static
!String