3 test_description
='topgit_branches.awk functionality'
9 ap
="$(tg --awk-path)" && test -n "$ap" && test -d "$ap" || die
10 aptb
="$ap/topgit_branches"
11 test -f "$aptb" && test -r "$aptb" && test -x "$aptb" || die
15 input
="fake_input.txt"
16 cat <<-EOT >"$input" || die
19 even more garbage here
21 20000001 whatever branch1 :
26 30000001 something ebranch1 :
31 40000001 tag abranch1 :
38 cp "$input" "$input2" || die
39 cat <<-EOT >>"$input2" || die
40 50000001 blob branch2 :
45 60000001 tree branch3 :
50 70000001 commit branch4 :
55 10000001 object check ?
56 80000001 object branch5 :
63 test_expect_success
'topgit_branches runs' '
64 # some stupid awks might not even compile it
65 awk -f "$aptb" </dev/null
68 test_expect_success
'files are truncated' '
69 echo one >one && test -s one &&
70 awk -v brfile="one" -f "$aptb" </dev/null &&
72 echo two >two && test -s two &&
73 awk -v anfile="two" -f "$aptb" </dev/null &&
75 echo one >one && test -s one &&
76 echo two >two && test -s two &&
77 awk -v brfile="one" -v anfile="two" -f "$aptb" </dev/null &&
82 test_expect_success
'bad/good input' '
83 # the attempt to read four extra lines fails
84 echo "bad input here :" >badinput.txt &&
85 test_must_fail awk -f "$aptb" <badinput.txt &&
86 cat <<-EOT >badinput.txt &&
92 test_must_fail awk -f "$aptb" <badinput.txt &&
93 echo "2222 tree" >>badinput.txt &&
95 result="$(awk -f "$aptb" <badinput.txt)" &&
96 test z"$result" = z"here"
99 test_expect_success
'no opts output okay' '
100 printf "%s\n" branch1 ebranch1 abranch1 >expected &&
101 awk -f "$aptb" <"$input" >output.txt &&
102 test_cmp expected output.txt &&
103 awk -v noann=0 -f "$aptb" <"$input" >output.txt &&
104 test_cmp expected output.txt
107 test_expect_success
'noann output okay' '
108 printf "%s\n" branch1 >expected &&
109 awk -v noann=1 -f "$aptb" <"$input" >output.txt &&
110 test_cmp expected output.txt
113 test_expect_success
'brfile/anfile output okay' '
114 printf "%s\n" branch1 ebranch1 abranch1 >expected &&
116 awk -v brfile=brfile -f "$aptb" <"$input" >output.txt &&
117 test_cmp expected output.txt &&
118 test_cmp expected brfile &&
119 awk -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
120 test_cmp expected output.txt &&
121 test_cmp expected brfile &&
122 printf "%s\n" branch1 >expected &&
123 printf "%s\n" ebranch1 abranch1 >expected2 &&
124 rm -f brfile anfile &&
125 awk -v noann=1 -v brfile=brfile -f "$aptb" <"$input" >output.txt &&
126 test_cmp expected output.txt &&
127 test_cmp expected brfile &&
128 rm -f brfile anfile &&
129 awk -v noann=1 -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
130 test_cmp expected output.txt &&
131 test_cmp expected brfile &&
132 test_cmp expected2 anfile &&
134 printf "%s\n" branch1 ebranch1 abranch1 >expected &&
135 awk -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
136 test_cmp expected output.txt &&
137 test_cmp expected2 anfile &&
139 printf "%s\n" branch1 >expected &&
140 awk -v noann=1 -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
141 test_cmp expected output.txt &&
142 test_cmp expected2 anfile
145 test_expect_success
'exclude branches' '
147 awk -v exclbr="ebranch1 other abranch1 branch1" -f "$aptb" <"$input" >output.txt &&
148 test ! -s output.txt &&
149 printf "%s\n" branch1 abranch1 >expected &&
150 awk -v exclbr="ebranch1 other xabranch1 xbranch1" -f "$aptb" <"$input" >output.txt &&
151 test_cmp expected output.txt &&
152 printf "%s\n" ebranch1 abranch1 >expected &&
153 awk -v exclbr="xebranch1 other xabranch1 branch1" -f "$aptb" <"$input" >output.txt &&
154 test_cmp expected output.txt &&
155 printf "%s\n" branch1 abranch1 >expected &&
156 awk -v exclbr="ebranch1" -f "$aptb" <"$input" >output.txt &&
157 test_cmp expected output.txt
160 test_expect_success
'noann=1 exclude branches' '
162 rm -f brfile anfile &&
163 awk -v noann=1 -v exclbr="ebranch1 other abranch1 branch1" -f "$aptb" <"$input" >output.txt &&
164 test ! -s output.txt &&
165 printf "%s\n" branch1 >expected &&
166 awk -v noann=1 -v exclbr="ebranch1 other xabranch1 xbranch1" -f "$aptb" <"$input" >output.txt &&
167 test_cmp expected output.txt &&
169 awk -v noann=1 -v exclbr="xebranch1 other xabranch1 branch1" -f "$aptb" <"$input" >output.txt &&
170 test_cmp expected output.txt &&
171 printf "%s\n" branch1 >expected &&
172 awk -v noann=1 -v exclbr="ebranch1" -f "$aptb" <"$input" >output.txt &&
173 test_cmp expected output.txt
176 test_expect_success
'exclude branches brfile/anfile' '
177 printf "%s\n" branch1 ebranch1 abranch1 >expectedbr &&
178 printf "%s\n" ebranch1 abranch1 >expectedan &&
180 rm -f brfile anfile &&
181 awk -v exclbr="ebranch1 other abranch1 branch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
182 test ! -s output.txt &&
183 test_cmp expectedbr brfile &&
184 test_cmp expectedan anfile &&
185 printf "%s\n" branch1 abranch1 >expected &&
186 rm -f brfile anfile &&
187 awk -v exclbr="ebranch1 other xabranch1 xbranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
188 test_cmp expected output.txt &&
189 test_cmp expectedbr brfile &&
190 test_cmp expectedan anfile &&
191 printf "%s\n" ebranch1 abranch1 >expected &&
192 rm -f brfile anfile &&
193 awk -v exclbr="xebranch1 other xabranch1 branch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
194 test_cmp expected output.txt &&
195 test_cmp expectedbr brfile &&
196 test_cmp expectedan anfile &&
197 printf "%s\n" branch1 abranch1 >expected &&
198 rm -f brfile anfile &&
199 awk -v exclbr="ebranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
200 test_cmp expected output.txt &&
201 test_cmp expectedbr brfile &&
202 test_cmp expectedan anfile
205 test_expect_success
'noann=1 exclude branches brfile/anfile' '
206 printf "%s\n" branch1 >expectedbr &&
207 printf "%s\n" ebranch1 abranch1 >expectedan &&
209 rm -f brfile anfile &&
210 awk -v noann=1 -v exclbr="ebranch1 other abranch1 branch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
211 test ! -s output.txt &&
212 test_cmp expectedbr brfile &&
213 test_cmp expectedan anfile &&
214 printf "%s\n" branch1 >expected &&
215 rm -f brfile anfile &&
216 awk -v noann=1 -v exclbr="ebranch1 other xabranch1 xbranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
217 test_cmp expected output.txt &&
218 test_cmp expectedbr brfile &&
219 test_cmp expectedan anfile &&
221 rm -f brfile anfile &&
222 awk -v noann=1 -v exclbr="xebranch1 other xabranch1 branch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
223 test_cmp expected output.txt &&
224 test_cmp expectedbr brfile &&
225 test_cmp expectedan anfile &&
226 printf "%s\n" branch1 >expected &&
227 rm -f brfile anfile &&
228 awk -v noann=1 -v exclbr="ebranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
229 test_cmp expected output.txt &&
230 test_cmp expectedbr brfile &&
231 test_cmp expectedan anfile
234 test_expect_success
'include branches' '
235 printf "%s\n" branch1 >expected &&
236 awk -v inclbr="xebranch1 other xabranch1 branch1" -f "$aptb" <"$input" >output.txt &&
237 test_cmp expected output.txt &&
238 printf "%s\n" abranch1 >expected &&
239 awk -v inclbr="xebranch1 other abranch1 xbranch1" -f "$aptb" <"$input" >output.txt &&
240 test_cmp expected output.txt &&
241 printf "%s\n" ebranch1 >expected &&
242 awk -v inclbr="ebranch1" -f "$aptb" <"$input" >output.txt &&
243 test_cmp expected output.txt &&
244 printf "%s\n" branch1 ebranch1 >expected &&
245 awk -v inclbr="ebranch1 branch1" -f "$aptb" <"$input" >output.txt &&
246 test_cmp expected output.txt &&
247 printf "%s\n" branch1 abranch1 >expected &&
248 awk -v inclbr="branch1 abranch1" -f "$aptb" <"$input" >output.txt &&
249 test_cmp expected output.txt &&
250 printf "%s\n" ebranch1 abranch1 >expected &&
251 awk -v inclbr="abranch1 ebranch1" -f "$aptb" <"$input" >output.txt &&
252 test_cmp expected output.txt &&
253 printf "%s\n" branch1 ebranch1 abranch1 >expected &&
254 awk -v inclbr="abranch1 branch1 ebranch1" -f "$aptb" <"$input" >output.txt &&
255 test_cmp expected output.txt
258 test_expect_success
'noann=1 include branches' '
259 printf "%s\n" branch1 >expected &&
260 awk -v noann=1 -v inclbr="xebranch1 other xabranch1 branch1" -f "$aptb" <"$input" >output.txt &&
261 test_cmp expected output.txt &&
263 awk -v noann=1 -v inclbr="xebranch1 other abranch1 xbranch1" -f "$aptb" <"$input" >output.txt &&
264 test_cmp expected output.txt &&
266 awk -v noann=1 -v inclbr="ebranch1" -f "$aptb" <"$input" >output.txt &&
267 test_cmp expected output.txt &&
268 printf "%s\n" branch1 >expected &&
269 awk -v noann=1 -v inclbr="ebranch1 branch1" -f "$aptb" <"$input" >output.txt &&
270 test_cmp expected output.txt &&
271 printf "%s\n" branch1 >expected &&
272 awk -v noann=1 -v inclbr="branch1 abranch1" -f "$aptb" <"$input" >output.txt &&
273 test_cmp expected output.txt &&
275 awk -v noann=1 -v inclbr="abranch1 ebranch1" -f "$aptb" <"$input" >output.txt &&
276 test_cmp expected output.txt &&
277 printf "%s\n" branch1 >expected &&
278 awk -v noann=1 -v inclbr="abranch1 branch1 ebranch1" -f "$aptb" <"$input" >output.txt &&
279 test_cmp expected output.txt
282 test_expect_success
'include branches brfile/anfile' '
283 printf "%s\n" branch1 ebranch1 abranch1 >expectedbr &&
284 printf "%s\n" ebranch1 abranch1 >expectedan &&
285 printf "%s\n" branch1 >expected &&
286 rm -f brfile anfile &&
287 awk -v inclbr="xebranch1 other xabranch1 branch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
288 test_cmp expected output.txt &&
289 test_cmp expectedbr brfile &&
290 test_cmp expectedan anfile &&
291 printf "%s\n" abranch1 >expected &&
292 rm -f brfile anfile &&
293 awk -v inclbr="xebranch1 other abranch1 xbranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
294 test_cmp expected output.txt &&
295 test_cmp expectedbr brfile &&
296 test_cmp expectedan anfile &&
297 printf "%s\n" ebranch1 >expected &&
298 rm -f brfile anfile &&
299 awk -v inclbr="ebranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
300 test_cmp expected output.txt &&
301 test_cmp expectedbr brfile &&
302 test_cmp expectedan anfile &&
303 printf "%s\n" branch1 ebranch1 >expected &&
304 rm -f brfile anfile &&
305 awk -v inclbr="ebranch1 branch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
306 test_cmp expected output.txt &&
307 test_cmp expectedbr brfile &&
308 test_cmp expectedan anfile &&
309 printf "%s\n" branch1 abranch1 >expected &&
310 rm -f brfile anfile &&
311 awk -v inclbr="branch1 abranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
312 test_cmp expected output.txt &&
313 test_cmp expectedbr brfile &&
314 test_cmp expectedan anfile &&
315 printf "%s\n" ebranch1 abranch1 >expected &&
316 rm -f brfile anfile &&
317 awk -v inclbr="abranch1 ebranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
318 test_cmp expected output.txt &&
319 test_cmp expectedbr brfile &&
320 test_cmp expectedan anfile &&
321 printf "%s\n" branch1 ebranch1 abranch1 >expected &&
322 rm -f brfile anfile &&
323 awk -v inclbr="abranch1 branch1 ebranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
324 test_cmp expected output.txt &&
325 test_cmp expectedbr brfile &&
326 test_cmp expectedan anfile
329 test_expect_success
'noann=1 include branches brfile/anfile' '
330 printf "%s\n" branch1 >expectedbr &&
331 printf "%s\n" ebranch1 abranch1 >expectedan &&
332 printf "%s\n" branch1 >expected &&
333 rm -f brfile anfile &&
334 awk -v noann=1 -v inclbr="xebranch1 other xabranch1 branch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
335 test_cmp expected output.txt &&
336 test_cmp expectedbr brfile &&
337 test_cmp expectedan anfile &&
339 rm -f brfile anfile &&
340 awk -v noann=1 -v inclbr="xebranch1 other abranch1 xbranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
341 test_cmp expected output.txt &&
342 test_cmp expectedbr brfile &&
343 test_cmp expectedan anfile &&
345 rm -f brfile anfile &&
346 awk -v noann=1 -v inclbr="ebranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
347 test_cmp expected output.txt &&
348 test_cmp expectedbr brfile &&
349 test_cmp expectedan anfile &&
350 printf "%s\n" branch1 >expected &&
351 rm -f brfile anfile &&
352 awk -v noann=1 -v inclbr="ebranch1 branch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
353 test_cmp expected output.txt &&
354 test_cmp expectedbr brfile &&
355 test_cmp expectedan anfile &&
356 printf "%s\n" branch1 >expected &&
357 rm -f brfile anfile &&
358 awk -v noann=1 -v inclbr="branch1 abranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
359 test_cmp expected output.txt &&
360 test_cmp expectedbr brfile &&
361 test_cmp expectedan anfile &&
363 rm -f brfile anfile &&
364 awk -v noann=1 -v inclbr="abranch1 ebranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
365 test_cmp expected output.txt &&
366 test_cmp expectedbr brfile &&
367 test_cmp expectedan anfile &&
368 printf "%s\n" branch1 >expected &&
369 rm -f brfile anfile &&
370 awk -v noann=1 -v inclbr="abranch1 branch1 ebranch1" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input" >output.txt &&
371 test_cmp expected output.txt &&
372 test_cmp expectedbr brfile &&
373 test_cmp expectedan anfile
376 test_expect_success
'noann=0/1 include/exclude branches' '
377 printf "%s\n" branch1 ebranch1 abranch1 branch3 branch5 >expected &&
378 awk -v inclbr="branch1 branch2 branch3 branch4 branch5 ebranch1 abranch1" -v exclbr="branch2 branch4" -f "$aptb" <"$input2" >output.txt &&
379 test_cmp expected output.txt &&
380 printf "%s\n" branch1 branch3 branch5 >expected &&
381 awk -v noann=1 -v inclbr="branch1 branch2 branch3 branch4 branch5 ebranch1 abranch1" -v exclbr="branch2 branch4" -f "$aptb" <"$input2" >output.txt &&
382 test_cmp expected output.txt &&
383 printf "%s\n" branch1 ebranch1 abranch1 branch2 branch3 branch4 branch5 >expectedbr
386 test_expect_success
'noann=0/1 include/exclude branches brfile/anfile' '
387 printf "%s\n" branch1 ebranch1 abranch1 branch2 branch3 branch4 branch5 >expectedbr0 &&
388 printf "%s\n" branch1 branch2 branch3 branch4 branch5 >expectedbr1 &&
389 printf "%s\n" ebranch1 abranch1 >expectedan &&
390 printf "%s\n" branch1 ebranch1 abranch1 branch3 branch5 >expected &&
391 rm -f brfile anfile &&
392 awk -v inclbr="branch1 branch2 branch3 branch4 branch5 ebranch1 abranch1" -v exclbr="branch2 branch4" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input2" >output.txt &&
393 test_cmp expected output.txt &&
394 test_cmp expectedbr0 brfile &&
395 test_cmp expectedan anfile &&
396 printf "%s\n" branch1 branch3 branch5 >expected &&
397 rm -f brfile anfile &&
398 awk -v noann=1 -v inclbr="branch1 branch2 branch3 branch4 branch5 ebranch1 abranch1" -v exclbr="branch2 branch4" -v brfile=brfile -v anfile=anfile -f "$aptb" <"$input2" >output.txt &&
399 test_cmp expected output.txt &&
400 test_cmp expectedbr1 brfile &&
401 test_cmp expectedan anfile