t1360: test topgit_msg.awk functionality
[topgit/pro.git] / t / t1360-awk-topgit_msg.sh
blob5345a58d33b774e435dfd758447ccc79cb9d98f9
1 #!/bin/sh
3 test_description='topgit_msg.awk functionality'
5 . ./test-lib.sh
7 ap="$(tg --awk-path)" && test -n "$ap" && test -d "$ap" || die
8 aptm="$ap/topgit_msg"
9 test -f "$aptm" && test -r "$aptm" && test -x "$aptm" || die
11 # Final output of topgit_msg_prepare looks like:
13 # 5e6bd1db23329803939ffa1e1f9052e678ea4a06 0 t/sample
15 # where the "0" can actually be in the range 0-4 inclusive.
16 # That output then gets piped through this:
18 # git cat-file --batch='%(objecttype) %(objectsize) %(rest)' | tr '\0' '\27'
20 # and fed to the topgit_msg script. awk is not guaranteed to handle the
21 # NUL character so by running through tr (which is POSIXly supposed to) if
22 # some unfortunate blob is involved this topgit_msg script still has a
23 # chance of doing something correct with the result
25 # note that despite the format provided, "missing" will always be the second
26 # field output for missing objects
28 test_plan 42
30 v_blobify() { eval "$1="'"$(git hash-object -t blob -w --stdin)"'; }
31 v_blobify mtblob </dev/null || die
33 doprep() {
34 git cat-file --batch='%(objecttype) %(objectsize) %(rest)' |
35 tr '\0' '\27'
37 dotgmsg() {
38 doprep |
39 awk -f "$aptm" "$@"
42 v_blobify mtsubj <<-EOT || die
43 Subject:
44 EOT
45 v_blobify wrapabc <<-EOT || die
46 Subject:
50 EOT
51 v_blobify first <<-EOT || die
52 Subject: first
53 EOT
54 v_blobify wonky <<-EOT || die
55 subJeCT: first
56 EOT
57 v_blobify second <<-EOT || die
58 Subject: second
59 EOT
60 v_blobify third <<-EOT || die
61 Subject: third
62 EOT
63 v_blobify doubleup <<-EOT || die
64 This:
65 Double-up: line
66 one
67 X-other:
68 double-UP:
69 line two
70 EOT
72 printf "%s\n" \
73 "$first 0 t/first" \
74 "$second 0 t/second" \
75 "$third 0 t/third" |
76 doprep >cat123 || die
78 test_expect_success 'topgit_msg runs' '
79 # some stupid awks might not even compile it
80 awk -f "$aptm" </dev/null &&
81 # and make sure the helper works too
82 dotgmsg </dev/null
85 test_expect_success 'first subject' '
86 echo "t/first 0 first" >expected &&
87 echo "$first 0 t/first" | dotgmsg >actual &&
88 test_cmp actual expected
91 test_expect_success 'second subject' '
92 echo "t/second 0 second" >expected &&
93 echo "$second 0 t/second" | dotgmsg >actual &&
94 test_cmp actual expected
97 test_expect_success 'third subject' '
98 echo "t/third 0 third" >expected &&
99 echo "$third 0 t/third" | dotgmsg >actual &&
100 test_cmp actual expected
103 test_expect_success 'third subject colfmt' '
104 printf "%-39s\t%s\n" "t/third 0" "third" >expected &&
105 echo "$third 0 t/third" |
106 dotgmsg -v colfmt=1 >actual &&
107 test_cmp actual expected
110 test_expect_success 'third subject colfmt nokind' '
111 printf "%-39s\t%s\n" "t/third" "third" >expected &&
112 echo "$third 0 t/third" |
113 dotgmsg -v colfmt=1 -v nokind=1 >actual &&
114 test_cmp actual expected
117 test_expect_success 'third subject colfmt noname' '
118 printf "%-39s\t%s\n" "0" "third" >expected &&
119 echo "$third 0 t/third" |
120 dotgmsg -v colfmt=1 -v noname=1 >actual &&
121 test_cmp actual expected
124 test_expect_success 'third subject colfmt nokind noname' '
125 echo "third" >expected &&
126 echo "$third 0 t/third" |
127 dotgmsg -v colfmt=1 -v nokind=1 -v noname=1 >actual &&
128 test_cmp actual expected
131 test_expect_success 'two subjects' '
132 echo "t/first 0 first" >expected &&
133 echo "t/second 0 second" >>expected &&
134 printf "%s\n" "$first 0 t/first" "$second 0 t/second" |
135 dotgmsg >actual &&
136 test_cmp actual expected
139 test_expect_success 'three subjects' '
140 echo "t/first 0 first" >expected &&
141 echo "t/second 0 second" >>expected &&
142 echo "t/third 0 third" >>expected &&
143 printf "%s\n" \
144 "$first 0 t/first" \
145 "$second 0 t/second" \
146 "$third 0 t/third" |
147 dotgmsg >actual &&
148 test_cmp actual expected
151 test_expect_success 'five subjects all kinds' '
152 echo "t/first 0 first" >expected &&
153 echo "t/firstx 1 branch t/firstx (missing .topmsg)" >>expected &&
154 echo "t/second 2 branch t/second (annihilated)" >>expected &&
155 echo "t/third 3 branch t/third (no commits)" >>expected &&
156 echo "t/firsty 4 branch t/firsty (bare branch)" >>expected &&
157 printf "%s\n" \
158 "$first 0 t/first" \
159 "$first 1 t/firstx" \
160 "$second 2 t/second" \
161 "$third 3 t/third" \
162 "$first 4 t/firsty" |
163 dotgmsg -v withan=1 >actual &&
164 test_cmp actual expected
167 test_expect_success 'three subjects exclbr second' '
168 echo "t/first 0 first" >expected &&
169 echo "t/third 0 third" >>expected &&
170 <cat123 awk -f "$aptm" -v "exclbr=t/second" >actual &&
171 test_cmp actual expected
174 test_expect_success 'three subjects inclbr second' '
175 echo "t/second 0 second" >expected &&
176 <cat123 awk -f "$aptm" -v "inclbr=t/second" >actual &&
177 test_cmp actual expected
180 test_expect_success 'three subjects inclbr first and second' '
181 echo "t/first 0 first" >expected &&
182 echo "t/second 0 second" >>expected &&
183 <cat123 awk -f "$aptm" -v "inclbr=t/second t/first" >actual &&
184 test_cmp actual expected
187 test_expect_success 'three subjects exclbr second and third' '
188 echo "t/first 0 first" >expected &&
189 <cat123 awk -f "$aptm" -v "exclbr=t/third t/second" >actual &&
190 test_cmp actual expected
193 test_expect_success 'three subjects inclbr second and third exclbr second' '
194 echo "t/third 0 third" >expected &&
195 <cat123 awk -f "$aptm" -v "inclbr=t/second t/third" -v "exclbr=t/second" >actual &&
196 test_cmp actual expected
199 test_expect_success 'three subjects only1' '
200 echo "t/first 0 first" >expected &&
201 <cat123 awk -f "$aptm" -v only1=1 >actual &&
202 test_cmp actual expected
205 test_expect_success 'three subjects only1 inclbr' '
206 echo "t/first 0 first" >expected &&
207 <cat123 awk -f "$aptm" -v only1=1 -v "inclbr=t/first" >actual &&
208 test_cmp actual expected &&
209 echo "t/second 0 second" >expected &&
210 <cat123 awk -f "$aptm" -v only1=1 -v "inclbr=t/second" >actual &&
211 test_cmp actual expected &&
212 echo "t/third 0 third" >expected &&
213 <cat123 awk -f "$aptm" -v only1=1 -v "inclbr=t/third" >actual &&
214 test_cmp actual expected
217 test_expect_success 'three subjects only1 exclbr' '
218 echo "t/first 0 first" >expected &&
219 <cat123 awk -f "$aptm" -v only1=1 -v "exclbr=t/second" >actual &&
220 test_cmp actual expected &&
221 echo "t/second 0 second" >expected &&
222 <cat123 awk -f "$aptm" -v only1=1 -v "exclbr=t/third t/first" >actual &&
223 test_cmp actual expected &&
224 echo "t/third 0 third" >expected &&
225 <cat123 awk -f "$aptm" -v only1=1 -v "exclbr=t/second t/first" >actual &&
226 test_cmp actual expected &&
227 echo "t/third 0 third" >expected &&
228 <cat123 awk -f "$aptm" -v only1=1 -v "exclbr=t/first t/second" >actual &&
229 test_cmp actual expected
232 test_expect_success 'three subjects no kind' '
233 echo "t/first first" >expected &&
234 echo "t/second second" >>expected &&
235 echo "t/third third" >>expected &&
236 printf "%s\n" \
237 "$first 0 t/first" \
238 "$second 0 t/second" \
239 "$third 0 t/third" |
240 dotgmsg -v nokind=1 >actual &&
241 test_cmp actual expected
244 test_expect_success 'three subjects no name' '
245 echo "0 first" >expected &&
246 echo "0 second" >>expected &&
247 echo "0 third" >>expected &&
248 printf "%s\n" \
249 "$first 0 t/first" \
250 "$second 0 t/second" \
251 "$third 0 t/third" |
252 dotgmsg -v noname=1 >actual &&
253 test_cmp actual expected
256 test_expect_success 'three subjects no kind and no name' '
257 echo "first" >expected &&
258 echo "second" >>expected &&
259 echo "third" >>expected &&
260 printf "%s\n" \
261 "$first 0 t/first" \
262 "$second 0 t/second" \
263 "$third 0 t/third" |
264 dotgmsg -v nokind=1 -v noname=1 >actual &&
265 test_cmp actual expected
268 test_expect_success 'three subjects middle missing' '
269 echo "t/first 0 first" >expected &&
270 echo "t/third 0 third" >>expected &&
271 printf "%s\n" \
272 "$first 0 t/first" \
273 "555${second#???} 0 t/second" \
274 "$third 0 t/third" |
275 dotgmsg >actual &&
276 test_cmp actual expected
279 test_expect_success 'three subjects middle no keyword' '
280 echo "t/first 0 first" >expected &&
281 echo "t/second 0 branch t/second (missing \"Subject:\" in .topmsg)" >>expected &&
282 echo "t/third 0 third" >>expected &&
283 printf "%s\n" \
284 "$first 0 t/first" \
285 "$mtblob 0 t/second" \
286 "$third 0 t/third" |
287 dotgmsg >actual &&
288 test_cmp actual expected
291 test_expect_success 'three subjects middle empty keyword' '
292 echo "t/first 0 first" >expected &&
293 echo "t/second 0 branch t/second (empty \"Subject:\" in .topmsg)" >>expected &&
294 echo "t/third 0 third" >>expected &&
295 printf "%s\n" \
296 "$first 0 t/first" \
297 "$mtsubj 0 t/second" \
298 "$third 0 t/third" |
299 dotgmsg >actual &&
300 test_cmp actual expected
303 test_expect_success 'three subjects middle K==1' '
304 echo "t/first 0 first" >expected &&
305 echo "t/second 1 branch t/second (missing .topmsg)" >>expected &&
306 echo "t/third 0 third" >>expected &&
307 printf "%s\n" \
308 "$first 0 t/first" \
309 "$second 1 t/second" \
310 "$third 0 t/third" |
311 dotgmsg >actual &&
312 test_cmp actual expected
315 test_expect_success 'three subjects middle K==2' '
316 echo "t/first 0 first" >expected &&
317 echo "t/second 2 branch t/second (annihilated)" >>expected &&
318 echo "t/third 0 third" >>expected &&
319 printf "%s\n" \
320 "$first 0 t/first" \
321 "$second 2 t/second" \
322 "$third 0 t/third" |
323 dotgmsg -v withan=1 -v withmt=0 >actual &&
324 test_cmp actual expected &&
325 printf "%s\n" \
326 "$first 0 t/first" \
327 "$second 2 t/second" \
328 "$second 3 t/bogus" \
329 "$third 0 t/third" |
330 dotgmsg -v withan=1 -v withmt=0 >actual &&
331 test_cmp actual expected
334 test_expect_success 'three subjects middle K==3' '
335 echo "t/first 0 first" >expected &&
336 echo "t/second 3 branch t/second (no commits)" >>expected &&
337 echo "t/third 0 third" >>expected &&
338 printf "%s\n" \
339 "$first 0 t/first" \
340 "$second 3 t/second" \
341 "$third 0 t/third" |
342 dotgmsg -v withmt=1 >actual &&
343 test_cmp actual expected &&
344 printf "%s\n" \
345 "$first 0 t/first" \
346 "$second 2 t/bogus" \
347 "$second 3 t/second" \
348 "$third 0 t/third" |
349 dotgmsg -v withmt=1 >actual &&
350 test_cmp actual expected
353 test_expect_success 'three subjects middle K==4' '
354 echo "t/first 0 first" >expected &&
355 echo "t/second 4 branch t/second (bare branch)" >>expected &&
356 echo "t/third 0 third" >>expected &&
357 printf "%s\n" \
358 "$first 0 t/first" \
359 "$second 4 t/second" \
360 "$third 0 t/third" |
361 dotgmsg >actual &&
362 test_cmp actual expected
365 test_expect_success 'three subjects middle wrapped' '
366 echo "t/first 0 first" >expected &&
367 echo "t/second 0 a b c" >>expected &&
368 echo "t/third 0 third" >>expected &&
369 printf "%s\n" \
370 "$first 0 t/first" \
371 "$wrapabc 0 t/second" \
372 "$third 0 t/third" |
373 dotgmsg >actual &&
374 test_cmp actual expected
377 test_expect_success 'five subjects all kinds kwregex=subject' '
378 echo "t/first 0 first" >expected &&
379 echo "t/firstx 1 branch t/firstx (missing .topmsg)" >>expected &&
380 echo "t/second 2 branch t/second (annihilated)" >>expected &&
381 echo "t/third 3 branch t/third (no commits)" >>expected &&
382 echo "t/firsty 4 branch t/firsty (bare branch)" >>expected &&
383 printf "%s\n" \
384 "$first 0 t/first" \
385 "$mtblob 1 t/firstx" \
386 "$mtblob 2 t/second" \
387 "$mtblob 3 t/third" \
388 "$mtblob 4 t/firsty" |
389 doprep >five &&
390 <five awk -f "$aptm" -v withan=1 -v kwregex="Subject" >actual &&
391 test_cmp actual expected &&
392 <five awk -f "$aptm" -v withan=1 -v kwregex="subject" >actual &&
393 test_cmp actual expected &&
394 <five awk -f "$aptm" -v withan=1 -v kwregex="sUbJeCt" >actual &&
395 test_cmp actual expected
398 test_expect_success 'five subjects all kinds kwregex=(subject)' '
399 echo "t/first 0 first" >expected &&
400 echo "t/firstx 1 " >>expected &&
401 echo "t/second 2 " >>expected &&
402 echo "t/third 3 " >>expected &&
403 echo "t/firsty 4 " >>expected &&
404 printf "%s\n" \
405 "$first 0 t/first" \
406 "$mtblob 1 t/firstx" \
407 "$mtblob 2 t/second" \
408 "$mtblob 3 t/third" \
409 "$mtblob 4 t/firsty" |
410 doprep >five &&
411 <five awk -f "$aptm" -v withan=1 -v kwregex="(sUbJeCt)" >actual &&
412 test_cmp actual expected
415 test_expect_success 'five subjects all kinds kwregex=(subject) nokind noname' '
416 echo "first" >expected &&
417 echo "" >>expected &&
418 echo "" >>expected &&
419 echo "" >>expected &&
420 echo "" >>expected &&
421 printf "%s\n" \
422 "$first 0 t/first" \
423 "$mtblob 1 t/firstx" \
424 "$mtblob 2 t/second" \
425 "$mtblob 3 t/third" \
426 "$mtblob 4 t/firsty" |
427 doprep >five &&
428 <five awk -f "$aptm" -v withan=1 -v nokind=1 -v noname=1 -v kwregex="(sUbJeCt)" >actual &&
429 test_cmp actual expected
432 test_expect_success 'five subjects all kinds kwregex=+subject nokind noname' '
433 echo "Subject: first" >expected &&
434 printf "%s\n" \
435 "$wonky 0 t/first" \
436 "$mtblob 1 t/firstx" \
437 "$mtblob 2 t/second" \
438 "$mtblob 3 t/third" \
439 "$mtblob 4 t/firsty" |
440 doprep >five &&
441 <five awk -f "$aptm" -v withan=1 -v nokind=1 -v noname=1 -v kwregex="+sUbJeCt" >actual &&
442 test_cmp actual expected &&
443 <five awk -f "$aptm" -v withan=1 -v nokind=1 -v noname=1 -v kwregex="+(sUbJeCt)" >actual &&
444 test_cmp actual expected
447 test_expect_success 'double-up kwregex' '
448 echo "line one" >expected &&
449 printf "%s\n" "$doubleup 0 whatever" |
450 dotgmsg -v nokind=1 -v noname=1 -v kwregex="DOUBle-uP" >actual &&
451 test_cmp actual expected
454 test_expect_success 'double-up kwregex empty' '
455 echo "" >expected &&
456 printf "%s\n" "$doubleup 0 whatever" |
457 dotgmsg -v nokind=1 -v noname=1 -v kwregex="this" >actual &&
458 test_cmp actual expected &&
459 printf "%s\n" "$doubleup 0 whatever" |
460 dotgmsg -v nokind=1 -v noname=1 -v kwregex="no-such-keyword" >actual &&
461 test_cmp actual expected
464 test_expect_success 'double-up kwregex only1 empty' '
465 >expected &&
466 printf "%s\n" "$doubleup 0 whatever" |
467 dotgmsg -v nokind=1 -v noname=1 -v only1=1 -v kwregex="this" >actual &&
468 test_cmp actual expected &&
469 printf "%s\n" "$doubleup 0 whatever" |
470 dotgmsg -v nokind=1 -v noname=1 -v only1=1 -v kwregex="no-such-keyword" >actual &&
471 test_cmp actual expected
474 test_expect_success 'double-up kwregex+ empty' '
475 echo "This:" >expected &&
476 printf "%s\n" "$doubleup 0 whatever" |
477 dotgmsg -v nokind=1 -v noname=1 -v kwregex="+this" >actual &&
478 test_cmp actual expected &&
479 >expected &&
480 printf "%s\n" "$doubleup 0 whatever" |
481 dotgmsg -v nokind=1 -v noname=1 -v kwregex="+no-such-keyword" >actual &&
482 test_cmp actual expected &&
483 printf "%s\n" "$doubleup 0 whatever" |
484 dotgmsg -v nokind=1 -v noname=1 -v kwregex="+Double" >actual &&
485 test_cmp actual expected
488 test_expect_success 'double-up kwregex+' '
489 echo "Double-Up: line one" >expected &&
490 echo "Double-Up: line two" >>expected &&
491 printf "%s\n" "$doubleup 0 whatever" |
492 dotgmsg -v nokind=1 -v noname=1 -v kwregex="+DOUBle-uP" >actual &&
493 test_cmp actual expected
496 test_expect_success 'double-up kwregex+ wildcard' '
497 echo "Double-Up: line one" >expected &&
498 echo "X-Other:" >>expected &&
499 echo "Double-Up: line two" >>expected &&
500 printf "%s\n" "$doubleup 0 whatever" |
501 dotgmsg -v nokind=1 -v noname=1 -v kwregex="+[dx].*" >actual &&
502 test_cmp actual expected
505 test_expect_success 'double-up kwregex match all' '
506 echo "" >expected &&
507 printf "%s\n" "$doubleup 0 whatever" |
508 dotgmsg -v nokind=1 -v noname=1 -v kwregex=".*" >actual &&
509 test_cmp actual expected
512 test_expect_success 'double-up kwregex+ match all' '
513 echo "This:" >expected &&
514 echo "Double-Up: line one" >>expected &&
515 echo "X-Other:" >>expected &&
516 echo "Double-Up: line two" >>expected &&
517 printf "%s\n" "$doubleup 0 whatever" |
518 dotgmsg -v nokind=1 -v noname=1 -v kwregex="+.*" >actual &&
519 test_cmp actual expected
522 test_done