t5583: fix shebang line
[alt-git.git] / t / t0030-stripspace.sh
blob0a5713c5248280d88a241b8027b5c98e4f321718
1 #!/bin/sh
3 # Copyright (c) 2007 Carlos Rica
6 test_description='git stripspace'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 t40='A quick brown fox jumps over the lazy do'
12 s40=' '
13 sss="$s40$s40$s40$s40$s40$s40$s40$s40$s40$s40" # 400
14 ttt="$t40$t40$t40$t40$t40$t40$t40$t40$t40$t40" # 400
16 printf_git_stripspace () {
17 printf "$1" | git stripspace
20 test_expect_success \
21 'long lines without spaces should be unchanged' '
22 echo "$ttt" >expect &&
23 git stripspace <expect >actual &&
24 test_cmp expect actual &&
26 echo "$ttt$ttt" >expect &&
27 git stripspace <expect >actual &&
28 test_cmp expect actual &&
30 echo "$ttt$ttt$ttt" >expect &&
31 git stripspace <expect >actual &&
32 test_cmp expect actual &&
34 echo "$ttt$ttt$ttt$ttt" >expect &&
35 git stripspace <expect >actual &&
36 test_cmp expect actual
39 test_expect_success \
40 'lines with spaces at the beginning should be unchanged' '
41 echo "$sss$ttt" >expect &&
42 git stripspace <expect >actual &&
43 test_cmp expect actual &&
45 echo "$sss$sss$ttt" >expect &&
46 git stripspace <expect >actual &&
47 test_cmp expect actual &&
49 echo "$sss$sss$sss$ttt" >expect &&
50 git stripspace <expect >actual &&
51 test_cmp expect actual
54 test_expect_success \
55 'lines with intermediate spaces should be unchanged' '
56 echo "$ttt$sss$ttt" >expect &&
57 git stripspace <expect >actual &&
58 test_cmp expect actual &&
60 echo "$ttt$sss$sss$ttt" >expect &&
61 git stripspace <expect >actual &&
62 test_cmp expect actual
65 test_expect_success \
66 'consecutive blank lines should be unified' '
67 printf "$ttt\n\n$ttt\n" > expect &&
68 printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
69 test_cmp expect actual &&
71 printf "$ttt$ttt\n\n$ttt\n" > expect &&
72 printf "$ttt$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
73 test_cmp expect actual &&
75 printf "$ttt$ttt$ttt\n\n$ttt\n" > expect &&
76 printf "$ttt$ttt$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
77 test_cmp expect actual &&
79 printf "$ttt\n\n$ttt\n" > expect &&
80 printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
81 test_cmp expect actual &&
83 printf "$ttt\n\n$ttt$ttt\n" > expect &&
84 printf "$ttt\n\n\n\n\n$ttt$ttt\n" | git stripspace >actual &&
85 test_cmp expect actual &&
87 printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
88 printf "$ttt\n\n\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
89 test_cmp expect actual &&
91 printf "$ttt\n\n$ttt\n" > expect &&
92 printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
93 test_cmp expect actual &&
95 printf "$ttt$ttt\n\n$ttt\n" > expect &&
96 printf "$ttt$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
97 test_cmp expect actual &&
99 printf "$ttt$ttt$ttt\n\n$ttt\n" > expect &&
100 printf "$ttt$ttt$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
101 test_cmp expect actual &&
103 printf "$ttt\n\n$ttt\n" > expect &&
104 printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
105 test_cmp expect actual &&
107 printf "$ttt\n\n$ttt$ttt\n" > expect &&
108 printf "$ttt\n\t\n \n\n \t\t\n$ttt$ttt\n" | git stripspace >actual &&
109 test_cmp expect actual &&
111 printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
112 printf "$ttt\n\t\n \n\n \t\t\n$ttt$ttt$ttt\n" | git stripspace >actual &&
113 test_cmp expect actual
116 test_expect_success \
117 'only consecutive blank lines should be completely removed' '
119 printf "\n" | git stripspace >actual &&
120 test_must_be_empty actual &&
122 printf "\n\n\n" | git stripspace >actual &&
123 test_must_be_empty actual &&
125 printf "$sss\n$sss\n$sss\n" | git stripspace >actual &&
126 test_must_be_empty actual &&
128 printf "$sss$sss\n$sss\n\n" | git stripspace >actual &&
129 test_must_be_empty actual &&
131 printf "\n$sss\n$sss$sss\n" | git stripspace >actual &&
132 test_must_be_empty actual &&
134 printf "$sss$sss$sss$sss\n\n\n" | git stripspace >actual &&
135 test_must_be_empty actual &&
137 printf "\n$sss$sss$sss$sss\n\n" | git stripspace >actual &&
138 test_must_be_empty actual &&
140 printf "\n\n$sss$sss$sss$sss\n" | git stripspace >actual &&
141 test_must_be_empty actual
144 test_expect_success \
145 'consecutive blank lines at the beginning should be removed' '
146 printf "$ttt\n" > expect &&
147 printf "\n$ttt\n" | git stripspace >actual &&
148 test_cmp expect actual &&
150 printf "$ttt\n" > expect &&
151 printf "\n\n\n$ttt\n" | git stripspace >actual &&
152 test_cmp expect actual &&
154 printf "$ttt$ttt\n" > expect &&
155 printf "\n\n\n$ttt$ttt\n" | git stripspace >actual &&
156 test_cmp expect actual &&
158 printf "$ttt$ttt$ttt\n" > expect &&
159 printf "\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
160 test_cmp expect actual &&
162 printf "$ttt$ttt$ttt$ttt\n" > expect &&
163 printf "\n\n\n$ttt$ttt$ttt$ttt\n" | git stripspace >actual &&
164 test_cmp expect actual &&
166 printf "$ttt\n" > expect &&
168 printf "$sss\n$sss\n$sss\n$ttt\n" | git stripspace >actual &&
169 test_cmp expect actual &&
171 printf "\n$sss\n$sss$sss\n$ttt\n" | git stripspace >actual &&
172 test_cmp expect actual &&
174 printf "$sss$sss\n$sss\n\n$ttt\n" | git stripspace >actual &&
175 test_cmp expect actual &&
177 printf "$sss$sss$sss\n\n\n$ttt\n" | git stripspace >actual &&
178 test_cmp expect actual &&
180 printf "\n$sss$sss$sss\n\n$ttt\n" | git stripspace >actual &&
181 test_cmp expect actual &&
183 printf "\n\n$sss$sss$sss\n$ttt\n" | git stripspace >actual &&
184 test_cmp expect actual
187 test_expect_success \
188 'consecutive blank lines at the end should be removed' '
189 printf "$ttt\n" > expect &&
190 printf "$ttt\n\n" | git stripspace >actual &&
191 test_cmp expect actual &&
193 printf "$ttt\n" > expect &&
194 printf "$ttt\n\n\n\n" | git stripspace >actual &&
195 test_cmp expect actual &&
197 printf "$ttt$ttt\n" > expect &&
198 printf "$ttt$ttt\n\n\n\n" | git stripspace >actual &&
199 test_cmp expect actual &&
201 printf "$ttt$ttt$ttt\n" > expect &&
202 printf "$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
203 test_cmp expect actual &&
205 printf "$ttt$ttt$ttt$ttt\n" > expect &&
206 printf "$ttt$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
207 test_cmp expect actual &&
209 printf "$ttt\n" > expect &&
211 printf "$ttt\n$sss\n$sss\n$sss\n" | git stripspace >actual &&
212 test_cmp expect actual &&
214 printf "$ttt\n\n$sss\n$sss$sss\n" | git stripspace >actual &&
215 test_cmp expect actual &&
217 printf "$ttt\n$sss$sss\n$sss\n\n" | git stripspace >actual &&
218 test_cmp expect actual &&
220 printf "$ttt\n$sss$sss$sss\n\n\n" | git stripspace >actual &&
221 test_cmp expect actual &&
223 printf "$ttt\n\n$sss$sss$sss\n\n" | git stripspace >actual &&
224 test_cmp expect actual &&
226 printf "$ttt\n\n\n$sss$sss$sss\n" | git stripspace >actual &&
227 test_cmp expect actual
230 test_expect_success \
231 'text without newline at end should end with newline' '
232 test_stdout_line_count -gt 0 printf_git_stripspace "$ttt" &&
233 test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt" &&
234 test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt" &&
235 test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$ttt"
238 # text plus spaces at the end:
240 test_expect_success \
241 'text plus spaces without newline at end should end with newline' '
242 test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss" &&
243 test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss" &&
244 test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$sss" &&
245 test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss" &&
246 test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss$sss" &&
247 test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss$sss"
250 test_expect_success \
251 'text plus spaces without newline at end should not show spaces' '
252 printf "$ttt$sss" | git stripspace >tmp &&
253 ! grep " " tmp >/dev/null &&
254 printf "$ttt$ttt$sss" | git stripspace >tmp &&
255 ! grep " " tmp >/dev/null &&
256 printf "$ttt$ttt$ttt$sss" | git stripspace >tmp &&
257 ! grep " " tmp >/dev/null &&
258 printf "$ttt$sss$sss" | git stripspace >tmp &&
259 ! grep " " tmp >/dev/null &&
260 printf "$ttt$ttt$sss$sss" | git stripspace >tmp &&
261 ! grep " " tmp >/dev/null &&
262 printf "$ttt$sss$sss$sss" | git stripspace >tmp &&
263 ! grep " " tmp >/dev/null
266 test_expect_success \
267 'text plus spaces without newline should show the correct lines' '
268 printf "$ttt\n" >expect &&
269 printf "$ttt$sss" | git stripspace >actual &&
270 test_cmp expect actual &&
272 printf "$ttt\n" >expect &&
273 printf "$ttt$sss$sss" | git stripspace >actual &&
274 test_cmp expect actual &&
276 printf "$ttt\n" >expect &&
277 printf "$ttt$sss$sss$sss" | git stripspace >actual &&
278 test_cmp expect actual &&
280 printf "$ttt$ttt\n" >expect &&
281 printf "$ttt$ttt$sss" | git stripspace >actual &&
282 test_cmp expect actual &&
284 printf "$ttt$ttt\n" >expect &&
285 printf "$ttt$ttt$sss$sss" | git stripspace >actual &&
286 test_cmp expect actual &&
288 printf "$ttt$ttt$ttt\n" >expect &&
289 printf "$ttt$ttt$ttt$sss" | git stripspace >actual &&
290 test_cmp expect actual
293 test_expect_success \
294 'text plus spaces at end should not show spaces' '
295 echo "$ttt$sss" | git stripspace >tmp &&
296 ! grep " " tmp >/dev/null &&
297 echo "$ttt$ttt$sss" | git stripspace >tmp &&
298 ! grep " " tmp >/dev/null &&
299 echo "$ttt$ttt$ttt$sss" | git stripspace >tmp &&
300 ! grep " " tmp >/dev/null &&
301 echo "$ttt$sss$sss" | git stripspace >tmp &&
302 ! grep " " tmp >/dev/null &&
303 echo "$ttt$ttt$sss$sss" | git stripspace >tmp &&
304 ! grep " " tmp >/dev/null &&
305 echo "$ttt$sss$sss$sss" | git stripspace >tmp &&
306 ! grep " " tmp >/dev/null
309 test_expect_success \
310 'text plus spaces at end should be cleaned and newline must remain' '
311 echo "$ttt" >expect &&
312 echo "$ttt$sss" | git stripspace >actual &&
313 test_cmp expect actual &&
315 echo "$ttt" >expect &&
316 echo "$ttt$sss$sss" | git stripspace >actual &&
317 test_cmp expect actual &&
319 echo "$ttt" >expect &&
320 echo "$ttt$sss$sss$sss" | git stripspace >actual &&
321 test_cmp expect actual &&
323 echo "$ttt$ttt" >expect &&
324 echo "$ttt$ttt$sss" | git stripspace >actual &&
325 test_cmp expect actual &&
327 echo "$ttt$ttt" >expect &&
328 echo "$ttt$ttt$sss$sss" | git stripspace >actual &&
329 test_cmp expect actual &&
331 echo "$ttt$ttt$ttt" >expect &&
332 echo "$ttt$ttt$ttt$sss" | git stripspace >actual &&
333 test_cmp expect actual
336 # spaces only:
338 test_expect_success \
339 'spaces with newline at end should be replaced with empty string' '
340 echo | git stripspace >actual &&
341 test_must_be_empty actual &&
343 echo "$sss" | git stripspace >actual &&
344 test_must_be_empty actual &&
346 echo "$sss$sss" | git stripspace >actual &&
347 test_must_be_empty actual &&
349 echo "$sss$sss$sss" | git stripspace >actual &&
350 test_must_be_empty actual &&
352 echo "$sss$sss$sss$sss" | git stripspace >actual &&
353 test_must_be_empty actual
356 test_expect_success \
357 'spaces without newline at end should not show spaces' '
358 printf "" | git stripspace >tmp &&
359 ! grep " " tmp >/dev/null &&
360 printf "$sss" | git stripspace >tmp &&
361 ! grep " " tmp >/dev/null &&
362 printf "$sss$sss" | git stripspace >tmp &&
363 ! grep " " tmp >/dev/null &&
364 printf "$sss$sss$sss" | git stripspace >tmp &&
365 ! grep " " tmp >/dev/null &&
366 printf "$sss$sss$sss$sss" | git stripspace >tmp &&
367 ! grep " " tmp >/dev/null
370 test_expect_success \
371 'spaces without newline at end should be replaced with empty string' '
372 printf "" | git stripspace >actual &&
373 test_must_be_empty actual &&
375 printf "$sss$sss" | git stripspace >actual &&
376 test_must_be_empty actual &&
378 printf "$sss$sss$sss" | git stripspace >actual &&
379 test_must_be_empty actual &&
381 printf "$sss$sss$sss$sss" | git stripspace >actual &&
382 test_must_be_empty actual
385 test_expect_success \
386 'consecutive text lines should be unchanged' '
387 printf "$ttt$ttt\n$ttt\n" >expect &&
388 printf "$ttt$ttt\n$ttt\n" | git stripspace >actual &&
389 test_cmp expect actual &&
391 printf "$ttt\n$ttt$ttt\n$ttt\n" >expect &&
392 printf "$ttt\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
393 test_cmp expect actual &&
395 printf "$ttt\n$ttt\n$ttt\n$ttt$ttt\n" >expect &&
396 printf "$ttt\n$ttt\n$ttt\n$ttt$ttt\n" | git stripspace >actual &&
397 test_cmp expect actual &&
399 printf "$ttt\n$ttt\n\n$ttt$ttt\n$ttt\n" >expect &&
400 printf "$ttt\n$ttt\n\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
401 test_cmp expect actual &&
403 printf "$ttt$ttt\n\n$ttt\n$ttt$ttt\n" >expect &&
404 printf "$ttt$ttt\n\n$ttt\n$ttt$ttt\n" | git stripspace >actual &&
405 test_cmp expect actual &&
407 printf "$ttt\n$ttt$ttt\n\n$ttt\n" >expect &&
408 printf "$ttt\n$ttt$ttt\n\n$ttt\n" | git stripspace >actual &&
409 test_cmp expect actual
412 test_expect_success 'strip comments, too' '
413 test ! -z "$(echo "# comment" | git stripspace)" &&
414 test -z "$(echo "# comment" | git stripspace -s)"
417 test_expect_success 'strip comments with changed comment char' '
418 test ! -z "$(echo "; comment" | git -c core.commentchar=";" stripspace)" &&
419 test -z "$(echo "; comment" | git -c core.commentchar=";" stripspace -s)"
422 test_expect_success '-c with single line' '
423 printf "# foo\n" >expect &&
424 printf "foo" | git stripspace -c >actual &&
425 test_cmp expect actual
428 test_expect_success '-c with single line followed by empty line' '
429 printf "# foo\n#\n" >expect &&
430 printf "foo\n\n" | git stripspace -c >actual &&
431 test_cmp expect actual
434 test_expect_success '-c with newline only' '
435 printf "#\n" >expect &&
436 printf "\n" | git stripspace -c >actual &&
437 test_cmp expect actual
440 test_expect_success '--comment-lines with single line' '
441 printf "# foo\n" >expect &&
442 printf "foo" | git stripspace -c >actual &&
443 test_cmp expect actual
446 test_expect_success '-c with changed comment char' '
447 printf "; foo\n" >expect &&
448 printf "foo" | git -c core.commentchar=";" stripspace -c >actual &&
449 test_cmp expect actual
452 test_expect_success '-c with comment char defined in .git/config' '
453 test_config core.commentchar = &&
454 printf "= foo\n" >expect &&
455 rm -fr sub &&
456 mkdir sub &&
457 printf "foo" | git -C sub stripspace -c >actual &&
458 test_cmp expect actual
461 test_expect_success '-c outside git repository' '
462 printf "# foo\n" >expect &&
463 printf "foo" | nongit git stripspace -c >actual &&
464 test_cmp expect actual
467 test_expect_success 'avoid SP-HT sequence in commented line' '
468 printf "#\tone\n#\n# two\n" >expect &&
469 printf "\tone\n\ntwo\n" | git stripspace -c >actual &&
470 test_cmp expect actual
473 test_done