24eb1a35d63bfe38aff06740f7f4b3131e06c227
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Johannes E. Schindelin
4 #
6 test_description='Test custom diff function name patterns'
8 . ./test-lib.sh
10 LF='
11 '
13 cat > Beer.java << EOF
14 public class Beer
15 {
16 int special;
17 public static void main(String args[])
18 {
19 String s=" ";
20 for(int x = 99; x > 0; x--)
21 {
22 System.out.print(x + " bottles of beer on the wall "
23 + x + " bottles of beer\n"
24 + "Take one down, pass it around, " + (x - 1)
25 + " bottles of beer on the wall.\n");
26 }
27 System.out.print("Go to the store, buy some more,\n"
28 + "99 bottles of beer on the wall.\n");
29 }
30 }
31 EOF
33 sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
35 builtin_patterns="bibtex cpp csharp fortran html java objc pascal perl php python ruby tex"
36 for p in $builtin_patterns
37 do
38 test_expect_success "builtin $p pattern compiles" '
39 echo "*.java diff=$p" >.gitattributes &&
40 ! { git diff --no-index Beer.java Beer-correct.java 2>&1 |
41 grep "fatal" > /dev/null; }
42 '
43 test_expect_success "builtin $p wordRegex pattern compiles" '
44 echo "*.java diff=$p" >.gitattributes &&
45 ! { git diff --no-index --word-diff \
46 Beer.java Beer-correct.java 2>&1 |
47 grep "fatal" > /dev/null; }
48 '
49 done
51 test_expect_success 'default behaviour' '
52 rm -f .gitattributes &&
53 git diff --no-index Beer.java Beer-correct.java |
54 grep "^@@.*@@ public class Beer"
55 '
57 test_expect_success 'set up .gitattributes declaring drivers to test' '
58 echo "*.java diff=java" >.gitattributes
59 '
61 test_expect_success 'preset java pattern' '
62 git diff --no-index Beer.java Beer-correct.java |
63 grep "^@@.*@@ public static void main("
64 '
66 git config diff.java.funcname '!static
67 !String
68 [^ ].*s.*'
70 test_expect_success 'custom pattern' '
71 git diff --no-index Beer.java Beer-correct.java |
72 grep "^@@.*@@ int special;$"
73 '
75 test_expect_success 'last regexp must not be negated' '
76 git config diff.java.funcname "!static" &&
77 git diff --no-index Beer.java Beer-correct.java 2>&1 |
78 grep "fatal: Last expression must not be negated:"
79 '
81 test_expect_success 'pattern which matches to end of line' '
82 git config diff.java.funcname "Beer$" &&
83 git diff --no-index Beer.java Beer-correct.java |
84 grep "^@@.*@@ Beer"
85 '
87 test_expect_success 'alternation in pattern' '
88 git config diff.java.xfuncname "^[ ]*((public|static).*)$" &&
89 git diff --no-index Beer.java Beer-correct.java |
90 grep "^@@.*@@ public static void main("
91 '
93 test_done