]> git.draconx.ca Git - gob-dx.git/blob - tests/options.at
Add test cases for various command-line options.
[gob-dx.git] / tests / options.at
1 dnl Copyright © 2020 Nick Bowler
2 dnl License GPLv2+: GNU General Public License version 2 or any later version.
3 dnl This is free software: you are free to change and redistribute it.
4 dnl There is NO WARRANTY, to the extent permitted by law.
5
6 dnl Check that the --help option exits successfully and prints only to
7 dnl standard output.
8 AT_SETUP([--help option])
9 AT_KEYWORDS([option])dnl
10
11 # Currently prints to standard error :(
12 AT_XFAIL_IF([:])
13 AT_CHECK([gob2 invalid-file.gob --help --invalid-option], [0], [ignore-nolog])
14
15 AT_CLEANUP
16
17 dnl Check that the --version option exits successfully, prints only to
18 dnl standard output, and contains the correct version number.
19 AT_SETUP([--version option])
20 AT_KEYWORDS([option])dnl
21
22 # Currently prints to standard error :(
23 AT_XFAIL_IF([:])
24 AT_CHECK([gob2 invalid-file.gob --version --invalid-option], [0], [stdout])
25 AT_CHECK([awk 'NR == 1 { print $NF }' stdout], [0], [AT_PACKAGE_VERSION
26 ])
27
28 AT_CLEANUP
29
30 AT_SETUP([--exit-on-warn option])
31 AT_KEYWORDS([option])dnl
32
33 AT_DATA([test.gob], [[class :Test from G:Object
34 {
35   private int x;
36   /* gob produces a warning due to override and nick combination */
37   property INT x ( override, nick = "hello", link );
38 }
39 ]])
40
41 AT_CHECK([gob2 test.gob], [0], [], [ignore])
42 AT_CHECK([gob2 test.gob --exit-on-warn], [1], [], [ignore])
43 AT_CHECK([gob2 test.gob --no-exit-on-warn -w], [1], [], [ignore])
44
45 AT_CLEANUP
46
47 AT_SETUP([--no-exit-on-warn option])
48 AT_KEYWORDS([option])dnl
49
50 AT_DATA([test.gob], [[class :Test from G:Object
51 {
52   private int x;
53   /* gob produces a warning due to override and nick combination */
54   property INT x ( override, nick = "hello", link );
55 }
56 ]])
57
58 AT_CHECK([gob2 test.gob], [0], [], [ignore])
59 AT_CHECK([gob2 test.gob --exit-on-warn], [1], [], [ignore])
60 AT_CHECK([gob2 test.gob -w --no-exit-on-warn], [0], [], [ignore])
61 AT_CHECK([gob2 test.gob --exit-on-warn --no-exit-on-warn], [0], [], [ignore])
62
63 AT_CLEANUP
64
65 AT_SETUP([--ondemand-private-header option])
66 AT_KEYWORDS([option])dnl
67
68 AT_DATA([priv.gob], [[class A:B:C from G:Object {
69   private int x;
70 }
71 %{
72 TEST_WITNESS_C
73 %}
74 %h{
75 TEST_WITNESS_H
76 %}
77 %privateheader{
78 TEST_WITNESS_PRIVATE
79 %}
80 ]])
81 sed '/private int/d' priv.gob >nopriv.gob
82
83 rm -f *.c *.h
84 AT_CHECK([gob2 nopriv.gob])
85 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
86 TEST_WITNESS_PRIVATE
87 ])
88 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
89 ])
90 AT_CHECK([test ! -f a-b-c-private.h])
91
92 rm -f *.c *.h
93 AT_CHECK([gob2 priv.gob])
94 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
95 ])
96 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
97 ])
98 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
99 ])
100
101 rm -f *.c *.h
102 AT_CHECK([gob2 nopriv.gob --always-private-header --ondemand-private-header])
103 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
104 TEST_WITNESS_PRIVATE
105 ])
106 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
107 ])
108 AT_CHECK([test ! -f a-b-c-private.h])
109
110 rm -f *.c *.h
111 AT_CHECK([gob2 priv.gob --no-private-header --ondemand-private-header])
112 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
113 ])
114 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
115 ])
116 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
117 ])
118
119 AT_CLEANUP
120
121 AT_SETUP([--always-private-header option])
122 AT_KEYWORDS([option])dnl
123
124 AT_DATA([priv.gob], [[class A:B:C from G:Object {
125   private int x;
126 }
127 %{
128 TEST_WITNESS_C
129 %}
130 %h{
131 TEST_WITNESS_H
132 %}
133 %privateheader{
134 TEST_WITNESS_PRIVATE
135 %}
136 ]])
137 sed '/private int/d' priv.gob >nopriv.gob
138
139 rm -f *.c *.h
140 AT_CHECK([gob2 nopriv.gob --always-private-header])
141 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
142 ])
143 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
144 ])
145 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
146 ])
147
148 rm -f *.c *.h
149 AT_CHECK([gob2 priv.gob --no-private-header --always-private-header])
150 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
151 ])
152 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
153 ])
154 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
155 ])
156
157 rm -f *.c *.h
158 AT_CHECK([gob2 nopriv.gob --ondemand-private-header --always-private-header])
159 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
160 ])
161 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
162 ])
163 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
164 ])
165
166 AT_CLEANUP
167
168 AT_SETUP([--no-private-header option])
169 AT_KEYWORDS([option])dnl
170
171 AT_DATA([priv.gob], [[class A:B:C from G:Object {
172   private int x;
173 }
174 %{
175 TEST_WITNESS_C
176 %}
177 %h{
178 TEST_WITNESS_H
179 %}
180 %privateheader{
181 TEST_WITNESS_PRIVATE
182 %}
183 ]])
184 sed '/private int/d' priv.gob >nopriv.gob
185
186 rm -f *.c *.h
187 AT_CHECK([gob2 priv.gob --no-private-header])
188 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
189 TEST_WITNESS_PRIVATE
190 ])
191 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
192 ])
193 AT_CHECK([test ! -f a-b-c-private.h])
194
195 rm -f *.c *.h
196 AT_CHECK([gob2 nopriv.gob --always-private-header --no-private-header])
197 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
198 TEST_WITNESS_PRIVATE
199 ])
200 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
201 ])
202 AT_CHECK([test ! -f a-b-c-private.h])
203
204 rm -f *.c *.h
205 AT_CHECK([gob2 priv.gob --ondemand-private-header --no-private-header])
206 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
207 TEST_WITNESS_PRIVATE
208 ])
209 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
210 ])
211 AT_CHECK([test ! -f a-b-c-private.h])
212
213 AT_CLEANUP
214
215 AT_SETUP([--file-sep option])
216 AT_KEYWORDS([option])dnl
217
218 AT_DATA([test.gob], [[class A:B:C from G:Object {
219 }
220 %{
221 TEST_WITNESS_C
222 %}
223 %h{
224 TEST_WITNESS_H
225 %}
226 %privateheader{
227 TEST_WITNESS_PRIVATE
228 %}
229 ]])
230
231 mkdir a; mkdir a/b
232 AT_CHECK([gob2 test.gob --file-sep=/])
233 AT_CHECK([grep '^TEST_WITNESS' a/b/c.c], [0], [TEST_WITNESS_C
234 TEST_WITNESS_PRIVATE
235 ])
236 AT_CHECK([grep '^TEST_WITNESS' a/b/c.h], [0], [TEST_WITNESS_H
237 ])
238
239 AT_CHECK([gob2 test.gob --always-private-header --file-sep=])
240 AT_CHECK([grep '^TEST_WITNESS' abc.c], [0], [TEST_WITNESS_C
241 ])
242 AT_CHECK([grep '^TEST_WITNESS' abc.h], [0], [TEST_WITNESS_H
243 ])
244 AT_CHECK([grep '^TEST_WITNESS' abcprivate.h], [0], [TEST_WITNESS_PRIVATE
245 ])
246
247 rm -f abc*
248 AT_CHECK([gob2 test.gob --file-sep])
249 AT_CHECK([grep '^TEST_WITNESS' abc.c], [0], [TEST_WITNESS_C
250 TEST_WITNESS_PRIVATE
251 ])
252 AT_CHECK([grep '^TEST_WITNESS' abc.h], [0], [TEST_WITNESS_H
253 ])
254
255 AT_CLEANUP
256
257 AT_SETUP([--output-dir option])
258 AT_KEYWORDS([option])dnl
259
260 AT_DATA([test.gob], [[class A:B:C from G:Object {
261 }
262 %{
263 TEST_WITNESS_C
264 %}
265 %h{
266 TEST_WITNESS_H
267 %}
268 ]])
269
270 mkdir output-dir o
271 AT_CHECK([gob2 test.gob --output-dir=output-dir])
272 AT_CHECK([grep '^TEST_WITNESS' output-dir/a-b-c.c], [0], [TEST_WITNESS_C
273 ])
274 AT_CHECK([grep '^TEST_WITNESS' output-dir/a-b-c.h], [0], [TEST_WITNESS_H
275 ])
276
277 AT_CHECK([gob2 test.gob -o o])
278 AT_CHECK([grep '^TEST_WITNESS' o/a-b-c.c], [0], [TEST_WITNESS_C
279 ])
280 AT_CHECK([grep '^TEST_WITNESS' o/a-b-c.h], [0], [TEST_WITNESS_H
281 ])
282
283 AT_CLEANUP
284
285 dnl Check that the --no-touch option does not modify any files that would be
286 dnl unchanged by gob, and that the --no-touch-headers option does not modify
287 dnl any header files.
288 m4_foreach([OPTION], [[[--no-touch]], [[--no-touch-headers]]],
289 [AT_SETUP([OPTION option])
290 AT_KEYWORDS([option])dnl
291
292 # Sanity check for make implementation
293 touch test.h; touch test-h
294 AT_CHECK([mtime_uptodate test-h test.h || exit 77])
295 TEST_MTIME_DELAY; touch test.h
296 AT_CHECK([mtime_uptodate test-h test.h && exit 77], [1])
297 rm -f test.h
298
299 AT_DATA([test.gob], [[class :Test from G:Object
300 {
301   private int x;
302 }
303 ]])
304
305 m4_if(OPTION, [--no-touch-headers],
306 [#Currently, the private header is modified even with --no-touch-headers.
307 AT_XFAIL_IF([:])])dnl
308
309 AT_CHECK([gob2 test.gob])
310 touch test-c test-h test-private
311 TEST_MTIME_DELAY
312 AT_CHECK([gob2 test.gob])
313 AT_CHECK([mtime_uptodate test-c test.c], [1])
314 AT_CHECK([mtime_uptodate test-h test.h], [1])
315 AT_CHECK([mtime_uptodate test-private test-private.h], [1])
316
317 touch test-c test-h test-private
318 TEST_MTIME_DELAY
319 AT_CHECK([gob2 test.gob OPTION])
320 AT_CHECK([mtime_uptodate test-c test.c],
321   m4_if(OPTION, [--no-touch], [0], [1]))
322 AT_CHECK([mtime_uptodate test-h test.h], [0])
323 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
324
325 cat >>test.gob <<'EOF'
326 %{
327 /* some code */
328 %}
329 EOF
330 touch test-c test-h test-private
331 TEST_MTIME_DELAY
332 AT_CHECK([gob2 test.gob OPTION])
333 AT_CHECK([mtime_uptodate test-c test.c], [1])
334 AT_CHECK([mtime_uptodate test-h test.h], [0])
335 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
336
337 cat >>test.gob <<'EOF'
338 %h{
339 /* yonder comment */
340 %}
341 EOF
342 touch test-c test-h test-private
343 TEST_MTIME_DELAY
344 AT_CHECK([gob2 test.gob OPTION])
345 AT_CHECK([mtime_uptodate test-c test.c],
346   m4_if(OPTION, [--no-touch], [0], [1]))
347 AT_CHECK([mtime_uptodate test-h test.h], [1])
348 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
349
350 cat >>test.gob <<'EOF'
351 %privateheader{
352 /* once more unto the breach */
353 %}
354 EOF
355 touch test-c test-h test-private
356 TEST_MTIME_DELAY
357 AT_CHECK([gob2 test.gob OPTION])
358 AT_CHECK([mtime_uptodate test-c test.c],
359   m4_if(OPTION, [--no-touch], [0], [1]))
360 AT_CHECK([mtime_uptodate test-h test.h], [0])
361 AT_CHECK([mtime_uptodate test-private test-private.h], [1])
362
363 AT_CLEANUP
364 ])
365
366 AT_SETUP([--no-write option])
367 AT_KEYWORDS([option])dnl
368
369 mkdir outdir
370 AT_DATA([outdir/test.gob], [[class :Test from G:Object
371 {
372   private int x;
373 }
374 ]])
375 AT_CHECK([cd outdir && ls -Al], [0], [stdout-nolog])
376 mv -f stdout expout
377
378 AT_CHECK([cd outdir && gob2 test.gob --no-write && ls -Al], [0], [expout])
379 AT_CHECK([cd outdir && gob2 test.gob -n && ls -Al], [0], [expout])
380
381 AT_CHECK([cd outdir && gob2 test.gob && ls -Al], [0], [stdout-nolog])
382 mv -f stdout expout
383
384 AT_CHECK([cd outdir && gob2 test.gob --no-write && ls -Al], [0], [expout])
385 AT_CHECK([cd outdir && gob2 test.gob -n && ls -Al], [0], [expout])
386
387 AT_CLEANUP
388
389 AT_SETUP([--no-extern-c option])
390 AT_KEYWORDS([option])dnl
391
392 AT_DATA([test.gob], [[class :Test from G:Object
393 {
394   private int x;
395 }
396 ]])
397
398 AT_CHECK([gob2 test.gob])
399 AT_CHECK([cat *.h | grep 'extern "C"'], [0], [extern "C" {
400 extern "C" {
401 ])
402
403 AT_CHECK([gob2 --no-extern-c test.gob])
404 AT_CHECK([cat *.h | grep 'extern "C"'], [1])
405
406 AT_CLEANUP
407
408 AT_SETUP([--no-gnu option])
409 AT_KEYWORDS([option])dnl
410
411 AT_DATA([test.gob], [[enum TEST_ENUM {
412   TEST_ENUM_A
413 } Test:Enum;
414
415 flags TEST_FLAGS {
416   TEST_FLAG_A
417 } Test:Flags;
418
419 error TEST_ERROR {
420   TEST_ERROR_A
421 } Test:Error;
422
423 class :Test from G:Object
424 {
425   private int x;
426 }
427 ]])
428
429 # --no-gnu is currently busted for the get_type function declaration.
430 AT_XFAIL_IF([:])
431
432 AT_CHECK([gob2 test.gob])
433 AT_CHECK([cat test*.h test.c | grep '_GNUC_' >/dev/null], [0])
434
435 AT_CHECK([gob2 --no-gnu test.gob])
436 AT_CHECK([cat test*.h test.c | grep '_GNUC_'], [1])
437
438 AT_CLEANUP
439
440 dnl Check that --no-self-alias works as documented.  The self_xxx method
441 dnl aliases are not documented to be affected by this option, so check that
442 dnl they are unaffected.
443 AT_SETUP([--no-self-alias option])
444 AT_KEYWORDS([option])dnl
445
446 AT_DATA([test.gob], [[class :Test from G:Object
447 {
448   public void myfunction(self) { };
449 }
450 ]])
451
452 AT_CHECK([gob2 test.gob])
453 AT_CHECK([:; { grep '#define.*SELF' test.c &&
454 grep 'typedef.*Self' test.c &&
455 grep '#define.*self_myfunction' test.c; } >/dev/null], [0])
456
457 AT_CHECK([gob2 --no-self-alias test.gob])
458 AT_CHECK([grep '#.*define.*SELF' test.c], [1])
459 AT_CHECK([grep 'typedef.*Self' test.c], [1])
460 AT_CHECK([grep '#define.*self_myfunction' test.c >/dev/null], [0])
461
462 AT_CLEANUP
463
464 AT_SETUP([--no-lines option])
465 AT_KEYWORDS([option])dnl
466
467 AT_DATA([test.gob], [[class :Test from G:Object
468 {
469   public int foo(void) { return 42; }
470   private int x;
471 }
472 ]])
473
474 AT_CHECK([gob2 test.gob])
475 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line' >/dev/null])
476
477 AT_CHECK([gob2 --no-lines test.gob])
478 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line'], [1])
479
480 AT_CLEANUP
481
482 dnl Check that the --no-kill-underscores option is ignored for compatibility.
483 AT_SETUP([--no-kill-underscores option])
484 AT_KEYWORDS([option])dnl
485
486 AT_DATA([test.gob], [[class :Test from G:Object
487 {
488 }
489 ]])
490
491 mkdir orig
492 AT_CHECK([gob2 --output-dir orig test.gob])
493 AT_CHECK([gob2 --no-kill-underscores test.gob])
494
495 cp -f orig/test.c expout
496 AT_CHECK([cat test.c], [0], [expout])
497
498 cp -f orig/test.h expout
499 AT_CHECK([cat test.h], [0], [expout])
500
501 AT_CLEANUP
502
503 AT_SETUP([--always-private-struct option])
504 AT_KEYWORDS([option])dnl
505
506 AT_DATA([test.gob], [[class :Test from G:Object
507 {
508   public int my_public_member;
509 }
510 ]])
511
512 AT_CHECK([gob2 test.gob])
513 AT_CHECK([sed -n '/my_public_member/,/^}/s/_priv/&/p' test.h])
514
515 AT_CHECK([gob2 --always-private-struct test.gob])
516 AT_CHECK([sed -n '/my_public_member/,/^}/s/[[   ]]*\(.*_priv;\)/\1/p' test.h],
517   [0], [TestPrivate *_priv;
518 ])
519
520 AT_CLEANUP
521
522 dnl Check the --gtk3 option.  The only effect of this option seems to be to
523 dnl change the normal "Iface" suffix on interface types to "Interface".  So
524 dnl let's make sure that behaviour is tested.
525 AT_SETUP([--gtk3 option])
526 AT_KEYWORDS([option])dnl
527
528 AT_DATA([test.gob], [[class :Test from G:Object
529   (interface Gtk:Actionable)
530 {
531 }
532 ]])
533
534 AT_CHECK([gob2 test.gob])
535 AT_CHECK([sed -n \
536   's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
537   [GtkActionableIface
538 ])
539
540 AT_CHECK([gob2 --gtk3 test.gob])
541 AT_CHECK([sed -n \
542   's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
543   [GtkActionableInterface
544 ])
545
546 AT_CLEANUP
547
548 AT_SETUP([--m4-dir option])
549 AT_KEYWORDS([option])dnl
550 AT_CHECK_UNQUOTED([gob2 --m4-dir], [0], [$pkgdatadir/m4
551 ])
552 AT_CLEANUP
553
554 dnl Check that the --m4 option shells out to m4 and passes through
555 dnl all remaining arguments.
556 AT_SETUP([--m4 option])
557 AT_KEYWORDS([option])dnl
558
559 mkdir bin
560 AT_DATA([bin/m4], [[#!/bin/sh
561 test $][# != 0 && printf '%s\n' "$][*" >&2
562 cat <<'EOF'
563 class M4:Test from G:Object
564 {
565 }
566 EOF
567 ]])
568 chmod +x bin/m4
569
570 PATH=$PWD/bin${PATH:+":$PATH"}
571 AT_CHECK([gob2 --m4 filename], [0], [], [stderr])
572 read gob_m4_args <stderr
573 AT_CHECK([test -f m4-test.c])
574
575 rm -f m4-test.c m4-test.h
576 cat >experr <<EOF
577 $gob_m4_args --help I am trapped in a test case factory --
578 EOF
579 AT_CHECK([gob2 --m4 filename --help I am trapped in a test case factory --],
580   [0], [], [experr])
581 AT_CHECK([test -f m4-test.c])
582
583 AT_CLEANUP
584
585 dnl Check that the --m4 option shells out to m4 and passes through
586 dnl all remaining arguments without adding any additional arguments.
587 AT_SETUP([--m4-clean option])
588 AT_KEYWORDS([option])dnl
589
590 mkdir bin
591 AT_DATA([bin/m4], [[#!/bin/sh
592 test $][# != 0 && printf '%s\n' "$][*" >&2
593 cat <<'EOF'
594 class M4:Test from G:Object
595 {
596 }
597 EOF
598 ]])
599 chmod +x bin/m4
600
601 PATH=$PWD/bin${PATH:+":$PATH"}
602 AT_CHECK([gob2 --m4-clean filename], [0], [], [filename
603 ])
604 AT_CHECK([test -f m4-test.c])
605
606 rm -f m4-test.c m4-test.h
607 AT_CHECK(
608   [gob2 --m4-clean filename --help I am trapped in a test case factory --],
609   [0], [], [filename --help I am trapped in a test case factory --
610 ])
611 AT_CHECK([test -f m4-test.c])
612
613 AT_CLEANUP