Git fork

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>

authored by

Johannes Sixt and committed by
Junio C Hamano
bfa7d014 abf8f986

+72 -6
+54 -6
t/t4018-diff-funcname.sh
··· 100 100 grep "^@@.*@@ $1" diff 101 101 } 102 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 104 122 do 105 123 test_expect_success "builtin $p pattern compiles" ' 106 124 echo "*.java diff=$p" >.gitattributes && ··· 117 135 ! grep error msg 118 136 ' 119 137 done 120 - 121 - test_expect_success 'default behaviour' ' 122 - rm -f .gitattributes && 123 - test_expect_funcname "public class Beer\$" 124 - ' 125 138 126 139 test_expect_success 'set up .gitattributes declaring drivers to test' ' 127 140 cat >.gitattributes <<-\EOF ··· 181 194 test_config diff.java.xfuncname "^[ ]*((public|static).*)$" && 182 195 test_expect_funcname "public static void main(" 183 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 184 232 185 233 test_done
+18
t/t4018/README
··· 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.