fuzz: link fuzz programs with `make all` on Linux
[alt-git.git] / t / t3321-notes-stripspace.sh
blobbeca34605672d407244b26ebcffb1f70527f5915
1 #!/bin/sh
3 # Copyright (c) 2023 Teng Long
6 test_description='Test commit notes with stripspace behavior'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 MULTI_LF="$LF$LF$LF"
12 write_script fake_editor <<\EOF
13 echo "$MSG" >"$1"
14 echo "$MSG" >&2
15 EOF
16 GIT_EDITOR=./fake_editor
17 export GIT_EDITOR
19 test_expect_success 'setup the commit' '
20 test_commit 1st
23 test_expect_success 'add note by editor' '
24 test_when_finished "git notes remove" &&
25 cat >expect <<-EOF &&
26 first-line
28 second-line
29 EOF
31 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add &&
32 git notes show >actual &&
33 test_cmp expect actual
36 test_expect_success 'add note by specifying single "-m", "--stripspace" is the default behavior' '
37 test_when_finished "git notes remove" &&
38 cat >expect <<-EOF &&
39 first-line
41 second-line
42 EOF
44 git notes add -m "${LF}first-line${MULTI_LF}second-line${LF}" &&
45 git notes show >actual &&
46 test_cmp expect actual &&
47 git notes remove &&
48 git notes add --stripspace -m "${LF}first-line${MULTI_LF}second-line${LF}" &&
49 git notes show >actual &&
50 test_cmp expect actual
53 test_expect_success 'add note by specifying single "-m" and "--no-stripspace" ' '
54 test_when_finished "git notes remove" &&
55 cat >expect <<-EOF &&
56 ${LF}first-line${MULTI_LF}second-line
57 EOF
59 git notes add --no-stripspace \
60 -m "${LF}first-line${MULTI_LF}second-line${LF}" &&
61 git notes show >actual &&
62 test_cmp expect actual
65 test_expect_success 'add note by specifying multiple "-m", "--stripspace" is the default behavior' '
66 test_when_finished "git notes remove" &&
67 cat >expect <<-EOF &&
68 first-line
70 second-line
71 EOF
73 git notes add -m "${LF}" \
74 -m "first-line" \
75 -m "${MULTI_LF}" \
76 -m "second-line" \
77 -m "${LF}" &&
78 git notes show >actual &&
79 test_cmp expect actual &&
80 git notes remove &&
81 git notes add --stripspace -m "${LF}" \
82 -m "first-line" \
83 -m "${MULTI_LF}" \
84 -m "second-line" \
85 -m "${LF}" &&
86 git notes show >actual &&
87 test_cmp expect actual
90 test_expect_success 'add notes by specifying multiple "-m" and "--no-stripspace"' '
91 test_when_finished "git notes remove" &&
92 cat >expect <<-EOF &&
93 ${LF}
94 first-line
95 ${MULTI_LF}
96 second-line${LF}
97 EOF
99 git notes add --no-stripspace \
100 -m "${LF}" \
101 -m "first-line" \
102 -m "${MULTI_LF}" \
103 -m "second-line" \
104 -m "${LF}" &&
105 git notes show >actual &&
106 test_cmp expect actual
109 test_expect_success 'add note by specifying single "-F", "--stripspace" is the default behavior' '
110 test_when_finished "git notes remove" &&
111 cat >expect <<-EOF &&
112 first-line
114 second-line
117 cat >note-file <<-EOF &&
118 ${LF}
119 first-line
120 ${MULTI_LF}
121 second-line
122 ${LF}
125 git notes add -F note-file &&
126 git notes show >actual &&
127 test_cmp expect actual &&
128 git notes remove &&
129 git notes add --stripspace -F note-file &&
130 git notes show >actual
133 test_expect_success 'add note by specifying single "-F" and "--no-stripspace"' '
134 test_when_finished "git notes remove" &&
135 cat >expect <<-EOF &&
136 ${LF}
137 first-line
138 ${MULTI_LF}
139 second-line
140 ${LF}
143 cat >note-file <<-EOF &&
144 ${LF}
145 first-line
146 ${MULTI_LF}
147 second-line
148 ${LF}
151 git notes add --no-stripspace -F note-file &&
152 git notes show >actual &&
153 test_cmp expect actual
156 test_expect_success 'add note by specifying multiple "-F", "--stripspace" is the default behavior' '
157 test_when_finished "git notes remove" &&
158 cat >expect <<-EOF &&
159 file-1-first-line
161 file-1-second-line
163 file-2-first-line
165 file-2-second-line
168 cat >note-file-1 <<-EOF &&
169 ${LF}
170 file-1-first-line
171 ${MULTI_LF}
172 file-1-second-line
173 ${LF}
176 cat >note-file-2 <<-EOF &&
177 ${LF}
178 file-2-first-line
179 ${MULTI_LF}
180 file-2-second-line
181 ${LF}
184 git notes add -F note-file-1 -F note-file-2 &&
185 git notes show >actual &&
186 test_cmp expect actual &&
187 git notes remove &&
188 git notes add --stripspace -F note-file-1 -F note-file-2 &&
189 git notes show >actual &&
190 test_cmp expect actual
193 test_expect_success 'add note by specifying multiple "-F" with "--no-stripspace"' '
194 test_when_finished "git notes remove" &&
195 cat >expect <<-EOF &&
196 ${LF}
197 file-1-first-line
198 ${MULTI_LF}
199 file-1-second-line
200 ${LF}
202 ${LF}
203 file-2-first-line
204 ${MULTI_LF}
205 file-2-second-line
206 ${LF}
209 cat >note-file-1 <<-EOF &&
210 ${LF}
211 file-1-first-line
212 ${MULTI_LF}
213 file-1-second-line
214 ${LF}
217 cat >note-file-2 <<-EOF &&
218 ${LF}
219 file-2-first-line
220 ${MULTI_LF}
221 file-2-second-line
222 ${LF}
225 git notes add --no-stripspace -F note-file-1 -F note-file-2 &&
226 git notes show >actual &&
227 test_cmp expect actual
230 test_expect_success 'append note by editor' '
231 test_when_finished "git notes remove" &&
232 cat >expect <<-EOF &&
233 first-line
235 second-line
238 git notes add -m "first-line" &&
239 MSG="${MULTI_LF}second-line${LF}" git notes append &&
240 git notes show >actual &&
241 test_cmp expect actual
244 test_expect_success 'append note by specifying single "-m"' '
245 test_when_finished "git notes remove" &&
246 cat >expect <<-EOF &&
247 first-line
249 second-line
252 git notes add -m "${LF}first-line" &&
253 git notes append -m "${MULTI_LF}second-line${LF}" &&
254 git notes show >actual &&
255 test_cmp expect actual
258 test_expect_success 'append note by specifying multiple "-m"' '
259 test_when_finished "git notes remove" &&
260 cat >expect <<-EOF &&
261 first-line
263 second-line
266 git notes add -m "${LF}first-line" &&
267 git notes append -m "${MULTI_LF}" \
268 -m "second-line" \
269 -m "${LF}" &&
270 git notes show >actual &&
271 test_cmp expect actual
274 test_expect_success 'add note by specifying single "-F"' '
275 test_when_finished "git notes remove" &&
276 cat >expect <<-EOF &&
277 first-line
279 second-line
282 cat >note-file <<-EOF &&
283 ${LF}
284 first-line
285 ${MULTI_LF}
286 second-line
287 ${LF}
290 git notes add -F note-file &&
291 git notes show >actual &&
292 test_cmp expect actual
295 test_expect_success 'add notes by specifying multiple "-F"' '
296 test_when_finished "git notes remove" &&
297 cat >expect <<-EOF &&
298 file-1-first-line
300 file-1-second-line
302 file-2-first-line
304 file-2-second-line
307 cat >note-file-1 <<-EOF &&
308 ${LF}
309 file-1-first-line
310 ${MULTI_LF}
311 file-1-second-line
312 ${LF}
315 cat >note-file-2 <<-EOF &&
316 ${LF}
317 file-2-first-line
318 ${MULTI_LF}
319 file-2-second-line
320 ${LF}
323 git notes add -F note-file-1 -F note-file-2 &&
324 git notes show >actual &&
325 test_cmp expect actual
328 test_expect_success 'append note by specifying single "-F"' '
329 test_when_finished "git notes remove" &&
330 cat >expect <<-EOF &&
331 initial-line
333 first-line
335 second-line
338 cat >note-file <<-EOF &&
339 ${LF}
340 first-line
341 ${MULTI_LF}
342 second-line
343 ${LF}
346 git notes add -m "initial-line" &&
347 git notes append -F note-file &&
348 git notes show >actual &&
349 test_cmp expect actual
352 test_expect_success 'append notes by specifying multiple "-F"' '
353 test_when_finished "git notes remove" &&
354 cat >expect <<-EOF &&
355 initial-line
357 file-1-first-line
359 file-1-second-line
361 file-2-first-line
363 file-2-second-line
366 cat >note-file-1 <<-EOF &&
367 ${LF}
368 file-1-first-line
369 ${MULTI_LF}
370 file-1-second-line
371 ${LF}
374 cat >note-file-2 <<-EOF &&
375 ${LF}
376 file-2-first-line
377 ${MULTI_LF}
378 file-2-second-line
379 ${LF}
382 git notes add -m "initial-line" &&
383 git notes append -F note-file-1 -F note-file-2 &&
384 git notes show >actual &&
385 test_cmp expect actual
388 test_expect_success 'append note by specifying multiple "-F" with "--no-stripspace"' '
389 test_when_finished "git notes remove" &&
390 cat >expect <<-EOF &&
391 initial-line
392 ${LF}${LF}
393 file-1-first-line
394 ${MULTI_LF}
395 file-1-second-line
396 ${LF}
398 ${LF}
399 file-2-first-line
400 ${MULTI_LF}
401 file-2-second-line
402 ${LF}
405 cat >note-file-1 <<-EOF &&
406 ${LF}
407 file-1-first-line
408 ${MULTI_LF}
409 file-1-second-line
410 ${LF}
413 cat >note-file-2 <<-EOF &&
414 ${LF}
415 file-2-first-line
416 ${MULTI_LF}
417 file-2-second-line
418 ${LF}
421 git notes add -m "initial-line" &&
422 git notes append --no-stripspace -F note-file-1 -F note-file-2 &&
423 git notes show >actual &&
424 test_cmp expect actual
427 test_expect_success 'add notes with empty messages' '
428 rev=$(git rev-parse HEAD) &&
429 git notes add -m "${LF}" \
430 -m "${MULTI_LF}" \
431 -m "${LF}" >actual 2>&1 &&
432 test_grep "Removing note for object" actual
435 test_expect_success 'add note by specifying "-C", "--no-stripspace" is the default behavior' '
436 test_when_finished "git notes remove" &&
437 cat >expect <<-EOF &&
438 ${LF}
439 first-line
440 ${MULTI_LF}
441 second-line
442 ${LF}
445 git hash-object -w --stdin <expect >blob &&
446 git notes add -C $(cat blob) &&
447 git notes show >actual &&
448 test_cmp expect actual &&
449 git notes remove &&
450 git notes add --no-stripspace -C $(cat blob) &&
451 git notes show >actual &&
452 test_cmp expect actual
455 test_expect_success 'reuse note by specifying "-C" and "--stripspace"' '
456 test_when_finished "git notes remove" &&
457 cat >data <<-EOF &&
458 ${LF}
459 first-line
460 ${MULTI_LF}
461 second-line
462 ${LF}
465 cat >expect <<-EOF &&
466 first-line
468 second-line
471 git hash-object -w --stdin <data >blob &&
472 git notes add --stripspace -C $(cat blob) &&
473 git notes show >actual &&
474 test_cmp expect actual
477 test_expect_success 'reuse with "-C" and add note with "-m", "-m" will stripspace all together' '
478 test_when_finished "git notes remove" &&
479 cat >data <<-EOF &&
480 ${LF}
481 first-line
482 ${MULTI_LF}
483 second-line
484 ${LF}
487 cat >expect <<-EOF &&
488 first-line
490 second-line
492 third-line
495 git hash-object -w --stdin <data >blob &&
496 git notes add -C $(cat blob) -m "third-line" &&
497 git notes show >actual &&
498 test_cmp expect actual
501 test_expect_success 'add note with "-m" and reuse note with "-C", "-C" will not stripspace all together' '
502 test_when_finished "git notes remove" &&
503 cat >data <<-EOF &&
505 second-line
508 cat >expect <<-EOF &&
509 first-line
510 ${LF}
511 second-line
514 git hash-object -w --stdin <data >blob &&
515 git notes add -m "first-line" -C $(cat blob) &&
516 git notes show >actual &&
517 test_cmp expect actual
520 test_expect_success 'add note by specifying "-c", "--stripspace" is the default behavior' '
521 test_when_finished "git notes remove" &&
522 cat >expect <<-EOF &&
523 first-line
525 second-line
528 echo "initial-line" | git hash-object -w --stdin >blob &&
529 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add -c $(cat blob) &&
530 git notes show >actual &&
531 test_cmp expect actual &&
532 git notes remove &&
533 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add --stripspace -c $(cat blob) &&
534 git notes show >actual &&
535 test_cmp expect actual
538 test_expect_success 'add note by specifying "-c" with "--no-stripspace"' '
539 test_when_finished "git notes remove" &&
540 cat >expect <<-EOF &&
541 ${LF}first-line${MULTI_LF}second-line${LF}
544 echo "initial-line" | git hash-object -w --stdin >blob &&
545 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add --no-stripspace -c $(cat blob) &&
546 git notes show >actual &&
547 test_cmp expect actual
550 test_expect_success 'edit note by specifying "-c", "--stripspace" is the default behavior' '
551 test_when_finished "git notes remove" &&
552 cat >expect <<-EOF &&
553 first-line
555 second-line
558 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes edit &&
559 git notes show >actual &&
560 test_cmp expect actual &&
561 git notes remove &&
562 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes edit --stripspace &&
563 git notes show >actual &&
564 test_cmp expect actual
567 test_expect_success 'edit note by specifying "-c" with "--no-stripspace"' '
568 test_when_finished "git notes remove" &&
569 cat >expect <<-EOF &&
570 ${LF}first-line${MULTI_LF}second-line${LF}
573 MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add --no-stripspace &&
574 git notes show >actual &&
575 test_cmp expect actual
578 test_done