1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
6test_description='Test custom diff function name patterns'
7
8. ./test-lib.sh
9
10LF='
11'
12
13cat > Beer.java << EOF
14public 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}
31EOF
32
33sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java
34
35test_config () {
36 git config "$1" "$2" &&
37 test_when_finished "git config --unset $1"
38}
39
40builtin_patterns="bibtex cpp csharp fortran html java objc pascal perl php python ruby tex"
41for p in $builtin_patterns
42do
43 test_expect_success "builtin $p pattern compiles" '
44 echo "*.java diff=$p" >.gitattributes &&
45 ! { git diff --no-index Beer.java Beer-correct.java 2>&1 |
46 grep "fatal" > /dev/null; }
47 '
48 test_expect_success "builtin $p wordRegex pattern compiles" '
49 echo "*.java diff=$p" >.gitattributes &&
50 ! { git diff --no-index --word-diff \
51 Beer.java Beer-correct.java 2>&1 |
52 grep "fatal" > /dev/null; }
53 '
54done
55
56test_expect_success 'default behaviour' '
57 rm -f .gitattributes &&
58 git diff --no-index Beer.java Beer-correct.java |
59 grep "^@@.*@@ public class Beer"
60'
61
62test_expect_success 'set up .gitattributes declaring drivers to test' '
63 echo "*.java diff=java" >.gitattributes
64'
65
66test_expect_success 'preset java pattern' '
67 git diff --no-index Beer.java Beer-correct.java |
68 grep "^@@.*@@ public static void main("
69'
70
71test_expect_success 'custom pattern' '
72 test_config diff.java.funcname "!static
73!String
74[^ ].*s.*" &&
75 git diff --no-index Beer.java Beer-correct.java |
76 grep "^@@.*@@ int special;$"
77'
78
79test_expect_success 'last regexp must not be negated' '
80 test_config diff.java.funcname "!static" &&
81 git diff --no-index Beer.java Beer-correct.java 2>&1 |
82 grep "fatal: Last expression must not be negated:"
83'
84
85test_expect_success 'pattern which matches to end of line' '
86 test_config diff.java.funcname "Beer$" &&
87 git diff --no-index Beer.java Beer-correct.java |
88 grep "^@@.*@@ Beer"
89'
90
91test_expect_success 'alternation in pattern' '
92 test_config diff.java.funcname "Beer$" &&
93 test_config diff.java.xfuncname "^[ ]*((public|static).*)$" &&
94 git diff --no-index Beer.java Beer-correct.java |
95 grep "^@@.*@@ public static void main("
96'
97
98test_done