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.
6 dnl Check that the --help option exits successfully and prints only to
8 AT_SETUP([--help option])
9 AT_KEYWORDS([option])dnl
11 AT_CHECK([gob2 invalid-file.gob --help --invalid-option], [0], [ignore-nolog])
15 dnl Check that the --version option exits successfully, prints only to
16 dnl standard output, and contains the correct version number.
17 AT_SETUP([--version option])
18 AT_KEYWORDS([option])dnl
20 AT_CHECK([gob2 invalid-file.gob --version --invalid-option], [0], [stdout])
21 AT_CHECK([awk 'NR == 1 { print $NF }' stdout], [0], [AT_PACKAGE_VERSION
26 AT_SETUP([--exit-on-warn option])
27 AT_KEYWORDS([option])dnl
29 AT_DATA([test.gob], [[class :Test from G:Object
32 /* gob produces a warning due to override and nick combination */
33 property INT x ( override, nick = "hello", link );
37 AT_CHECK([gob2 test.gob], [0], [], [ignore])
38 AT_CHECK([gob2 test.gob --exit-on-warn], [1], [], [ignore])
39 AT_CHECK([gob2 test.gob --no-exit-on-warn -w], [1], [], [ignore])
43 AT_SETUP([--no-exit-on-warn option])
44 AT_KEYWORDS([option])dnl
46 AT_DATA([test.gob], [[class :Test from G:Object
49 /* gob produces a warning due to override and nick combination */
50 property INT x ( override, nick = "hello", link );
54 AT_CHECK([gob2 test.gob], [0], [], [ignore])
55 AT_CHECK([gob2 test.gob --exit-on-warn], [1], [], [ignore])
56 AT_CHECK([gob2 test.gob -w --no-exit-on-warn], [0], [], [ignore])
57 AT_CHECK([gob2 test.gob --exit-on-warn --no-exit-on-warn], [0], [], [ignore])
61 AT_SETUP([--ondemand-private-header option])
62 AT_KEYWORDS([option])dnl
64 AT_DATA([priv.gob], [[class A:B:C from G:Object {
77 sed '/private int/d' priv.gob >nopriv.gob
80 AT_CHECK([gob2 nopriv.gob])
81 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
84 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
86 AT_CHECK([test ! -f a-b-c-private.h])
89 AT_CHECK([gob2 priv.gob])
90 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
92 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
94 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
98 AT_CHECK([gob2 nopriv.gob --always-private-header --ondemand-private-header])
99 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
102 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
104 AT_CHECK([test ! -f a-b-c-private.h])
107 AT_CHECK([gob2 priv.gob --no-private-header --ondemand-private-header])
108 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
110 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
112 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
117 AT_SETUP([--always-private-header option])
118 AT_KEYWORDS([option])dnl
120 AT_DATA([priv.gob], [[class A:B:C from G:Object {
133 sed '/private int/d' priv.gob >nopriv.gob
136 AT_CHECK([gob2 nopriv.gob --always-private-header])
137 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
139 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
141 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
145 AT_CHECK([gob2 priv.gob --no-private-header --always-private-header])
146 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
148 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
150 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
154 AT_CHECK([gob2 nopriv.gob --ondemand-private-header --always-private-header])
155 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
157 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
159 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
164 AT_SETUP([--no-private-header option])
165 AT_KEYWORDS([option])dnl
167 AT_DATA([priv.gob], [[class A:B:C from G:Object {
180 sed '/private int/d' priv.gob >nopriv.gob
183 AT_CHECK([gob2 priv.gob --no-private-header])
184 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
187 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
189 AT_CHECK([test ! -f a-b-c-private.h])
192 AT_CHECK([gob2 nopriv.gob --always-private-header --no-private-header])
193 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
196 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
198 AT_CHECK([test ! -f a-b-c-private.h])
201 AT_CHECK([gob2 priv.gob --ondemand-private-header --no-private-header])
202 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
205 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
207 AT_CHECK([test ! -f a-b-c-private.h])
211 AT_SETUP([--file-sep option])
212 AT_KEYWORDS([option])dnl
214 AT_DATA([test.gob], [[class A:B:C from G:Object {
228 AT_CHECK([gob2 test.gob --file-sep=/])
229 AT_CHECK([grep '^TEST_WITNESS' a/b/c.c], [0], [TEST_WITNESS_C
232 AT_CHECK([grep '^TEST_WITNESS' a/b/c.h], [0], [TEST_WITNESS_H
235 AT_CHECK([gob2 test.gob --always-private-header --file-sep=])
236 AT_CHECK([grep '^TEST_WITNESS' abc.c], [0], [TEST_WITNESS_C
238 AT_CHECK([grep '^TEST_WITNESS' abc.h], [0], [TEST_WITNESS_H
240 AT_CHECK([grep '^TEST_WITNESS' abcprivate.h], [0], [TEST_WITNESS_PRIVATE
244 AT_CHECK([gob2 test.gob --file-sep])
245 AT_CHECK([grep '^TEST_WITNESS' abc.c], [0], [TEST_WITNESS_C
248 AT_CHECK([grep '^TEST_WITNESS' abc.h], [0], [TEST_WITNESS_H
253 AT_SETUP([--output-dir option])
254 AT_KEYWORDS([option])dnl
256 AT_DATA([test.gob], [[class A:B:C from G:Object {
267 AT_CHECK([gob2 test.gob --output-dir=output-dir])
268 AT_CHECK([grep '^TEST_WITNESS' output-dir/a-b-c.c], [0], [TEST_WITNESS_C
270 AT_CHECK([grep '^TEST_WITNESS' output-dir/a-b-c.h], [0], [TEST_WITNESS_H
273 AT_CHECK([gob2 test.gob -o o])
274 AT_CHECK([grep '^TEST_WITNESS' o/a-b-c.c], [0], [TEST_WITNESS_C
276 AT_CHECK([grep '^TEST_WITNESS' o/a-b-c.h], [0], [TEST_WITNESS_H
281 dnl Check that the --no-touch option does not modify any files that would be
282 dnl unchanged by gob, and that the --no-touch-headers option does not modify
283 dnl any header files.
284 m4_foreach([OPTION], [[[--no-touch]], [[--no-touch-headers]]],
285 [AT_SETUP([OPTION option])
286 AT_KEYWORDS([option])dnl
288 # Sanity check for make implementation
289 touch test.h; touch test-h
290 AT_CHECK([mtime_uptodate test-h test.h || exit 77])
291 TEST_MTIME_DELAY; touch test.h
292 AT_CHECK([mtime_uptodate test-h test.h && exit 77], [1])
295 AT_DATA([test.gob], [[class :Test from G:Object
301 m4_if(OPTION, [--no-touch-headers],
302 [#Currently, the private header is modified even with --no-touch-headers.
303 AT_XFAIL_IF([:])])dnl
305 AT_CHECK([gob2 test.gob])
306 touch test-c test-h test-private
308 AT_CHECK([gob2 test.gob])
309 AT_CHECK([mtime_uptodate test-c test.c], [1])
310 AT_CHECK([mtime_uptodate test-h test.h], [1])
311 AT_CHECK([mtime_uptodate test-private test-private.h], [1])
313 touch test-c test-h test-private
315 AT_CHECK([gob2 test.gob OPTION])
316 AT_CHECK([mtime_uptodate test-c test.c],
317 m4_if(OPTION, [--no-touch], [0], [1]))
318 AT_CHECK([mtime_uptodate test-h test.h], [0])
319 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
321 cat >>test.gob <<'EOF'
326 touch test-c test-h test-private
328 AT_CHECK([gob2 test.gob OPTION])
329 AT_CHECK([mtime_uptodate test-c test.c], [1])
330 AT_CHECK([mtime_uptodate test-h test.h], [0])
331 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
333 cat >>test.gob <<'EOF'
338 touch test-c test-h test-private
340 AT_CHECK([gob2 test.gob OPTION])
341 AT_CHECK([mtime_uptodate test-c test.c],
342 m4_if(OPTION, [--no-touch], [0], [1]))
343 AT_CHECK([mtime_uptodate test-h test.h], [1])
344 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
346 cat >>test.gob <<'EOF'
348 /* once more unto the breach */
351 touch test-c test-h test-private
353 AT_CHECK([gob2 test.gob OPTION])
354 AT_CHECK([mtime_uptodate test-c test.c],
355 m4_if(OPTION, [--no-touch], [0], [1]))
356 AT_CHECK([mtime_uptodate test-h test.h], [0])
357 AT_CHECK([mtime_uptodate test-private test-private.h], [1])
362 AT_SETUP([--no-write option])
363 AT_KEYWORDS([option])dnl
366 AT_DATA([outdir/test.gob], [[class :Test from G:Object
371 AT_CHECK([cd outdir && ls -Al], [0], [stdout-nolog])
374 AT_CHECK([cd outdir && gob2 test.gob --no-write && ls -Al], [0], [expout])
375 AT_CHECK([cd outdir && gob2 test.gob -n && ls -Al], [0], [expout])
377 AT_CHECK([cd outdir && gob2 test.gob && ls -Al], [0], [stdout-nolog])
380 AT_CHECK([cd outdir && gob2 test.gob --no-write && ls -Al], [0], [expout])
381 AT_CHECK([cd outdir && gob2 test.gob -n && ls -Al], [0], [expout])
385 AT_SETUP([--no-extern-c option])
386 AT_KEYWORDS([option])dnl
388 AT_DATA([test.gob], [[class :Test from G:Object
394 AT_CHECK([gob2 test.gob])
395 AT_CHECK([cat *.h | grep 'extern "C"'], [0], [extern "C" {
399 AT_CHECK([gob2 --no-extern-c test.gob])
400 AT_CHECK([cat *.h | grep 'extern "C"'], [1])
404 AT_SETUP([--no-gnu option])
405 AT_KEYWORDS([option])dnl
407 AT_DATA([test.gob], [[enum TEST_ENUM {
419 class :Test from G:Object
425 # --no-gnu is currently busted for the get_type function declaration.
428 AT_CHECK([gob2 test.gob])
429 AT_CHECK([cat test*.h test.c | grep '_GNUC_' >/dev/null], [0])
431 AT_CHECK([gob2 --no-gnu test.gob])
432 AT_CHECK([cat test*.h test.c | grep '_GNUC_'], [1])
436 dnl Check that --no-self-alias works as documented. The self_xxx method
437 dnl aliases are not documented to be affected by this option, so check that
438 dnl they are unaffected.
439 AT_SETUP([--no-self-alias option])
440 AT_KEYWORDS([option])dnl
442 AT_DATA([test.gob], [[class :Test from G:Object
444 public void myfunction(self) { };
448 AT_CHECK([gob2 test.gob])
449 AT_CHECK([:; { grep '#define.*SELF' test.c &&
450 grep 'typedef.*Self' test.c &&
451 grep '#define.*self_myfunction' test.c; } >/dev/null], [0])
453 AT_CHECK([gob2 --no-self-alias test.gob])
454 AT_CHECK([grep '#.*define.*SELF' test.c], [1])
455 AT_CHECK([grep 'typedef.*Self' test.c], [1])
456 AT_CHECK([grep '#define.*self_myfunction' test.c >/dev/null], [0])
460 AT_SETUP([--no-lines option])
461 AT_KEYWORDS([option])dnl
463 AT_DATA([test.gob], [[class :Test from G:Object
465 public int foo(void) { return 42; }
470 AT_CHECK([gob2 test.gob])
471 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line' >/dev/null])
473 AT_CHECK([gob2 --no-lines test.gob])
474 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line'], [1])
478 dnl Check that the --no-kill-underscores option is ignored for compatibility.
479 AT_SETUP([--no-kill-underscores option])
480 AT_KEYWORDS([option])dnl
482 AT_DATA([test.gob], [[class :Test from G:Object
488 AT_CHECK([gob2 --output-dir orig test.gob])
489 AT_CHECK([gob2 --no-kill-underscores test.gob])
491 cp -f orig/test.c expout
492 AT_CHECK([cat test.c], [0], [expout])
494 cp -f orig/test.h expout
495 AT_CHECK([cat test.h], [0], [expout])
499 AT_SETUP([--always-private-struct option])
500 AT_KEYWORDS([option])dnl
502 AT_DATA([test.gob], [[class :Test from G:Object
504 public int my_public_member;
508 AT_CHECK([gob2 test.gob])
509 AT_CHECK([sed -n '/my_public_member/,/^}/s/_priv/&/p' test.h])
511 AT_CHECK([gob2 --always-private-struct test.gob])
512 AT_CHECK([sed -n '/my_public_member/,/^}/s/[[ ]]*\(.*_priv;\)/\1/p' test.h],
513 [0], [TestPrivate *_priv;
518 dnl Check the --gtk3 option. The only effect of this option seems to be to
519 dnl change the normal "Iface" suffix on interface types to "Interface". So
520 dnl let's make sure that behaviour is tested.
521 AT_SETUP([--gtk3 option])
522 AT_KEYWORDS([option])dnl
524 AT_DATA([test.gob], [[class :Test from G:Object
525 (interface Gtk:Actionable)
530 AT_CHECK([gob2 test.gob])
532 's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
536 AT_CHECK([gob2 --gtk3 test.gob])
538 's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
539 [GtkActionableInterface
544 AT_SETUP([--m4-dir option])
545 AT_KEYWORDS([option])dnl
546 AT_CHECK_UNQUOTED([gob2 --m4-dir], [0], [$pkgdatadir/m4
550 dnl Check that the --m4 option shells out to m4 and passes through
551 dnl all remaining arguments.
552 AT_SETUP([--m4 option])
553 AT_KEYWORDS([option])dnl
556 AT_DATA([bin/m4], [[#!/bin/sh
557 test $][# != 0 && printf '%s\n' "$][*" >&2
559 class M4:Test from G:Object
566 PATH=$PWD/bin${PATH:+":$PATH"}
567 AT_CHECK([gob2 --m4 filename], [0], [], [stderr])
568 read gob_m4_args <stderr
569 AT_CHECK([test -f m4-test.c])
571 rm -f m4-test.c m4-test.h
573 $gob_m4_args --help I am trapped in a test case factory --
575 AT_CHECK([gob2 --m4 filename --help I am trapped in a test case factory --],
577 AT_CHECK([test -f m4-test.c])
581 dnl Check that the --m4 option shells out to m4 and passes through
582 dnl all remaining arguments without adding any additional arguments.
583 AT_SETUP([--m4-clean option])
584 AT_KEYWORDS([option])dnl
587 AT_DATA([bin/m4], [[#!/bin/sh
588 test $][# != 0 && printf '%s\n' "$][*" >&2
590 class M4:Test from G:Object
597 PATH=$PWD/bin${PATH:+":$PATH"}
598 AT_CHECK([gob2 --m4-clean filename], [0], [], [filename
600 AT_CHECK([test -f m4-test.c])
602 rm -f m4-test.c m4-test.h
604 [gob2 --m4-clean filename --help I am trapped in a test case factory --],
605 [0], [], [filename --help I am trapped in a test case factory --
607 AT_CHECK([test -f m4-test.c])