t4018: an infrastructure to test hunk headers
Add an infrastructure that simplifies adding new tests of the hunk header regular expressions. To add new tests, a file with the syntax to test can be dropped in the directory t4018. The README file explains how a test file must contain; the README itself tests the default behavior. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Mar 21, 2014 at 22:07 UTC
bfa7d01413bd02b5b3675ef0e96f764064a13ce8
2 files changed
+72
-6
t/t4018-diff-funcname.sh
+54
-6
@@ -100,7 +100,25 @@ test_expect_funcname () {
100
grep "^@@.*@@ $1" diff
101
}
102
103
-for p in ada bibtex cpp csharp fortran html java matlab objc pascal perl php python ruby tex
103
+diffpatterns="
104
+ ada
105
+ bibtex
106
+ cpp
107
+ csharp
108
+ fortran
109
+ html
110
+ java
111
+ matlab
112
+ objc
113
+ pascal
114
+ perl
115
+ php
116
+ python
117
+ ruby
118
+ tex
119
+"
120
+
121
+for p in $diffpatterns
122
do
123
test_expect_success "builtin $p pattern compiles" '
124
echo "*.java diff=$p" >.gitattributes &&
@@ -118,11 +136,6 @@ do
136
'
137
done
138
121
-test_expect_success 'default behaviour' '
122
- rm -f .gitattributes &&
123
- test_expect_funcname "public class Beer\$"
124
-'
125
-
139
test_expect_success 'set up .gitattributes declaring drivers to test' '
140
cat >.gitattributes <<-\EOF
141
*.java diff=java
@@ -182,4 +195,39 @@ test_expect_success 'alternation in pattern' '
195
test_expect_funcname "public static void main("
196
'
197
198
+test_expect_success 'setup hunk header tests' '
199
+ for i in $diffpatterns
200
+ do
201
+ echo "$i-* diff=$i"
202
+ done > .gitattributes &&
203
+
204
+ # add all test files to the index
205
+ (
206
+ cd "$TEST_DIRECTORY"/t4018 &&
207
+ git --git-dir="$TRASH_DIRECTORY/.git" add .
208
+ ) &&
209
+
210
+ # place modified files in the worktree
211
+ for i in $(git ls-files)
212
+ do
213
+ sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
214
+ done
215
+'
216
+
217
+# check each individual file
218
+for i in $(git ls-files)
219
+do
220
+ if grep broken "$i" >/dev/null 2>&1
221
+ then
222
+ result=failure
223
+ else
224
+ result=success
225
+ fi
226
+ test_expect_$result "hunk header: $i" "
227
+ test_when_finished 'cat actual' && # for debugging only
228
+ git diff -U1 $i >actual &&
229
+ grep '@@ .* @@.*RIGHT' actual
230
+ "
231
+done
232
+
233
test_done
t/t4018/README
new
+18
@@ -0,0 +1,18 @@
1
+How to write RIGHT test cases
2
+=============================
3
+
4
+Insert the word "ChangeMe" (exactly this form) at a distance of
5
+at least two lines from the line that must appear in the hunk header.
6
+
7
+The text that must appear in the hunk header must contain the word
8
+"right", but in all upper-case, like in the title above.
9
+
10
+To mark a test case that highlights a malfunction, insert the word
11
+BROKEN in all lower-case somewhere in the file.
12
+
13
+This text is a bit twisted and out of order, but it is itself a
14
+test case for the default hunk header pattern. Know what you are doing
15
+if you change it.
16
+
17
+BTW, this tests that the head line goes to the hunk header, not the line
18
+of equal signs.