3 # Copyright (c) 2006 Johannes E. Schindelin
6 test_description='Test special whitespace in diff engine.
12 # Ray Lehtiniemi's example
20 git update-index --add x
32 index adf3937..6edc172 100644
46 test_expect_success "Ray's example without options" 'git diff expect out'
49 test_expect_success "Ray's example with -w" 'git diff expect out'
52 test_expect_success "Ray's example with -b" 'git diff expect out'
54 tr 'Q' '\015' << EOF > x
55 whitespace at beginning
57 whitespace in the middle
66 whitespace at beginning
68 white space in the middle
74 tr 'Q' '\015' << EOF > expect
76 index d99af23..8b32fb5 100644
80 -whitespace at beginning
82 -whitespace in the middle
84 + whitespace at beginning
86 +white space in the middle
93 test_expect_success 'another test, without options' 'git diff expect out'
97 index d99af23..8b32fb5 100644
100 test_expect_success 'another test, with -w' 'git diff expect out'
102 tr 'Q' '\015' << EOF > expect
104 index d99af23..8b32fb5 100644
108 -whitespace at beginning
109 + whitespace at beginning
111 -whitespace in the middle
112 +white space in the middle
118 test_expect_success 'another test, with -b' 'git diff expect out'
120 test_expect_success 'check mixed spaces and tabs in indent' '
122 # This is indented with SP HT SP.
123 echo " foo();" > x &&
124 git diff --check | grep "space before tab in indent"
128 test_expect_success 'check mixed tabs and spaces in indent' '
130 # This is indented with HT SP HT.
131 echo " foo();" > x &&
132 git diff --check | grep "space before tab in indent"
136 test_expect_success 'check with no whitespace errors' '
138 git commit -m "snapshot" &&
144 test_expect_success 'check with trailing whitespace' '
146 echo "foo(); " > x &&
151 test_expect_success 'check with space before tab in indent' '
153 # indent has space followed by hard tab
154 echo " foo();" > x &&
159 test_expect_success '--check and --exit-code are not exclusive' '
162 git diff --check --exit-code
166 test_expect_success '--check and --quiet are not exclusive' '
168 git diff --check --quiet
172 test_expect_success 'check staged with no whitespace errors' '
176 git diff --cached --check
180 test_expect_success 'check staged with trailing whitespace' '
182 echo "foo(); " > x &&
184 ! git diff --cached --check
188 test_expect_success 'check staged with space before tab in indent' '
190 # indent has space followed by hard tab
191 echo " foo();" > x &&
193 ! git diff --cached --check
197 test_expect_success 'check with no whitespace errors (diff-index)' '
201 git diff-index --check HEAD
205 test_expect_success 'check with trailing whitespace (diff-index)' '
207 echo "foo(); " > x &&
209 ! git diff-index --check HEAD
213 test_expect_success 'check with space before tab in indent (diff-index)' '
215 # indent has space followed by hard tab
216 echo " foo();" > x &&
218 ! git diff-index --check HEAD
222 test_expect_success 'check staged with no whitespace errors (diff-index)' '
226 git diff-index --cached --check HEAD
230 test_expect_success 'check staged with trailing whitespace (diff-index)' '
232 echo "foo(); " > x &&
234 ! git diff-index --cached --check HEAD
238 test_expect_success 'check staged with space before tab in indent (diff-index)' '
240 # indent has space followed by hard tab
241 echo " foo();" > x &&
243 ! git diff-index --cached --check HEAD
247 test_expect_success 'check with no whitespace errors (diff-tree)' '
250 git commit -m "new commit" x &&
251 git diff-tree --check HEAD^ HEAD
255 test_expect_success 'check with trailing whitespace (diff-tree)' '
257 echo "foo(); " > x &&
258 git commit -m "another commit" x &&
259 ! git diff-tree --check HEAD^ HEAD
263 test_expect_success 'check with space before tab in indent (diff-tree)' '
265 # indent has space followed by hard tab
266 echo " foo();" > x &&
267 git commit -m "yet another" x &&
268 ! git diff-tree --check HEAD^ HEAD
272 test_expect_success 'check trailing whitespace (trailing-space: off)' '
274 git config core.whitespace "-trailing-space" &&
275 echo "foo (); " > x &&
280 test_expect_success 'check trailing whitespace (trailing-space: on)' '
282 git config core.whitespace "trailing-space" &&
283 echo "foo (); " > x &&
288 test_expect_success 'check space before tab in indent (space-before-tab: off)' '
290 # indent contains space followed by HT
291 git config core.whitespace "-space-before-tab" &&
292 echo " foo ();" > x &&
297 test_expect_success 'check space before tab in indent (space-before-tab: on)' '
299 # indent contains space followed by HT
300 git config core.whitespace "space-before-tab" &&
301 echo " foo (); " > x &&
306 test_expect_success 'check spaces as indentation (indent-with-non-tab: off)' '
308 git config core.whitespace "-indent-with-non-tab"
309 echo " foo ();" > x &&
314 test_expect_success 'check spaces as indentation (indent-with-non-tab: on)' '
316 git config core.whitespace "indent-with-non-tab" &&
317 echo " foo ();" > x &&
322 test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab: on)' '
324 git config core.whitespace "indent-with-non-tab" &&
325 echo " foo ();" > x &&
330 test_expect_success 'line numbers in --check output are correct' '
333 echo "foo(); " >> x &&
334 git diff --check | grep "x:2:"