3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description
='Test custom diff function name patterns'
16 public static void main
(String args
[])
19 for(int x
= 99; x
> 0; x--
)
21 System.out.print
(x
+ " bottles of beer on the wall "
22 + x
+ " bottles of beer\n"
23 + "Take one down, pass it around, " + (x
- 1)
24 + " bottles of beer on the wall.\n");
26 System.out.print
("Go to the store, buy some more,\n"
27 + "99 bottles of beer on the wall.\n");
31 sed 's/beer\\/beer,\\/' <Beer.java
>Beer-correct.java
33 test_expect_funcname
() {
35 test_expect_code
1 git
diff --no-index -U1 \
36 "Beer.$lang" "Beer-correct.$lang" >diff &&
37 grep "^@@.*@@ $1" diff
58 for p
in $diffpatterns
60 test_expect_success
"builtin $p pattern compiles" '
61 echo "*.java diff=$p" >.gitattributes &&
62 test_expect_code 1 git diff --no-index \
63 Beer.java Beer-correct.java 2>msg &&
67 test_expect_success
"builtin $p wordRegex pattern compiles" '
68 echo "*.java diff=$p" >.gitattributes &&
69 test_expect_code 1 git diff --no-index --word-diff \
70 Beer.java Beer-correct.java 2>msg &&
76 test_expect_success
'set up .gitattributes declaring drivers to test' '
77 cat >.gitattributes <<-\EOF
82 test_expect_success
'preset java pattern' '
83 test_expect_funcname "public static void main("
86 test_expect_success
'custom pattern' '
87 test_config diff.java.funcname "!static
90 test_expect_funcname "int special;\$"
93 test_expect_success
'last regexp must not be negated' '
94 test_config diff.java.funcname "!static" &&
95 test_expect_code 128 git diff --no-index Beer.java Beer-correct.java 2>msg &&
96 grep ": Last expression must not be negated:" msg
99 test_expect_success
'pattern which matches to end of line' '
100 test_config diff.java.funcname "Beer\$" &&
101 test_expect_funcname "Beer\$"
104 test_expect_success
'alternation in pattern' '
105 test_config diff.java.funcname "Beer$" &&
106 test_config diff.java.xfuncname "^[ ]*((public|static).*)$" &&
107 test_expect_funcname "public static void main("
110 test_expect_success
'setup hunk header tests' '
111 for i in $diffpatterns
114 done > .gitattributes &&
116 # add all test files to the index
118 cd "$TEST_DIRECTORY"/t4018 &&
119 git --git-dir="$TRASH_DIRECTORY/.git" add .
122 # place modified files in the worktree
123 for i in $(git ls-files)
125 sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
129 # check each individual file
130 for i
in $
(git ls-files
)
132 if grep broken
"$i" >/dev
/null
2>&1
138 test_expect_
$result "hunk header: $i" "
139 test_when_finished 'cat actual' && # for debugging only
140 git diff -U1 $i >actual &&
141 grep '@@ .* @@.*RIGHT' actual