1 dnl Copyright © 2020-2021 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 AT_CHECK([gob2 test.gob])
302 touch test-c test-h test-private
304 AT_CHECK([gob2 test.gob])
305 AT_CHECK([mtime_uptodate test-c test.c], [1])
306 AT_CHECK([mtime_uptodate test-h test.h], [1])
307 AT_CHECK([mtime_uptodate test-private test-private.h], [1])
309 touch test-c test-h test-private
311 AT_CHECK([gob2 test.gob OPTION])
312 AT_CHECK([mtime_uptodate test-c test.c],
313 m4_if(OPTION, [--no-touch], [0], [1]))
314 AT_CHECK([mtime_uptodate test-h test.h], [0])
315 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
317 cat >>test.gob <<'EOF'
322 touch test-c test-h test-private
324 AT_CHECK([gob2 test.gob OPTION])
325 AT_CHECK([mtime_uptodate test-c test.c], [1])
326 AT_CHECK([mtime_uptodate test-h test.h], [0])
327 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
329 cat >>test.gob <<'EOF'
334 touch test-c test-h test-private
336 AT_CHECK([gob2 test.gob OPTION])
337 AT_CHECK([mtime_uptodate test-c test.c],
338 m4_if(OPTION, [--no-touch], [0], [1]))
339 AT_CHECK([mtime_uptodate test-h test.h], [1])
340 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
342 cat >>test.gob <<'EOF'
344 /* once more unto the breach */
347 touch test-c test-h test-private
349 AT_CHECK([gob2 test.gob OPTION])
350 AT_CHECK([mtime_uptodate test-c test.c],
351 m4_if(OPTION, [--no-touch], [0], [1]))
352 AT_CHECK([mtime_uptodate test-h test.h], [0])
353 AT_CHECK([mtime_uptodate test-private test-private.h], [1])
358 AT_SETUP([--no-write option])
359 AT_KEYWORDS([option])dnl
362 AT_DATA([outdir/test.gob], [[class :Test from G:Object
367 AT_CHECK([cd outdir && ls -Al], [0], [stdout-nolog])
370 AT_CHECK([cd outdir && gob2 test.gob --no-write && ls -Al], [0], [expout])
371 AT_CHECK([cd outdir && gob2 test.gob -n && ls -Al], [0], [expout])
373 AT_CHECK([cd outdir && gob2 test.gob && ls -Al], [0], [stdout-nolog])
376 AT_CHECK([cd outdir && gob2 test.gob --no-write && ls -Al], [0], [expout])
377 AT_CHECK([cd outdir && gob2 test.gob -n && ls -Al], [0], [expout])
381 AT_SETUP([--no-extern-c option])
382 AT_KEYWORDS([option])dnl
384 AT_DATA([test.gob], [[class :Test from G:Object
390 AT_CHECK([gob2 test.gob])
391 AT_CHECK([cat *.h | grep 'extern "C"'], [0], [extern "C" {
395 AT_CHECK([gob2 --no-extern-c test.gob])
396 AT_CHECK([cat *.h | grep 'extern "C"'], [1])
400 AT_SETUP([--no-gnu option])
401 AT_KEYWORDS([option])dnl
403 AT_DATA([test.gob], [[enum TEST_ENUM {
415 class :Test from G:Object
421 AT_CHECK([gob2 test.gob])
422 AT_CHECK([cat test*.h test.c | grep '_GNUC_' >/dev/null], [0])
424 AT_CHECK([gob2 --no-gnu test.gob])
425 AT_CHECK([cat test*.h test.c | grep '_GNUC_'], [1])
429 dnl Check that --no-self-alias works as documented. The self_xxx method
430 dnl aliases are not documented to be affected by this option, so check that
431 dnl they are unaffected.
432 AT_SETUP([--no-self-alias option])
433 AT_KEYWORDS([option])dnl
435 AT_DATA([test.gob], [[class :Test from G:Object
437 public void myfunction(self) { };
441 AT_CHECK([gob2 test.gob])
442 AT_CHECK([:; { grep '#define.*SELF' test.c &&
443 grep 'typedef.*Self' test.c &&
444 grep '#define.*self_myfunction' test.c; } >/dev/null], [0])
446 AT_CHECK([gob2 --no-self-alias test.gob])
447 AT_CHECK([grep '#.*define.*SELF' test.c], [1])
448 AT_CHECK([grep 'typedef.*Self' test.c], [1])
449 AT_CHECK([grep '#define.*self_myfunction' test.c >/dev/null], [0])
453 AT_SETUP([--no-lines option])
454 AT_KEYWORDS([option])dnl
456 AT_DATA([test.gob], [[class :Test from G:Object
458 public int foo(void) { return 42; }
463 AT_CHECK([gob2 test.gob])
464 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line' >/dev/null])
466 AT_CHECK([gob2 --no-lines test.gob])
467 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line'], [1])
471 dnl Check that the --no-kill-underscores option is ignored for compatibility.
472 AT_SETUP([--no-kill-underscores option])
473 AT_KEYWORDS([option])dnl
475 AT_DATA([test.gob], [[class :Test from G:Object
481 AT_CHECK([gob2 --output-dir orig test.gob])
482 AT_CHECK([gob2 --no-kill-underscores test.gob])
484 cp -f orig/test.c expout
485 AT_CHECK([cat test.c], [0], [expout])
487 cp -f orig/test.h expout
488 AT_CHECK([cat test.h], [0], [expout])
492 AT_SETUP([--always-private-struct option])
493 AT_KEYWORDS([option])dnl
495 AT_DATA([test.gob], [[class :Test from G:Object
497 public int my_public_member;
501 AT_CHECK([gob2 test.gob])
502 AT_CHECK([sed -n '/my_public_member/,/^}/s/_priv/&/p' test.h])
504 AT_CHECK([gob2 --always-private-struct test.gob])
505 AT_CHECK([sed -n '/my_public_member/,/^}/s/[[ ]]*\(.*_priv;\)/\1/p' test.h],
506 [0], [TestPrivate *_priv;
511 dnl Check the --gtk3 option. The only effect of this option seems to be to
512 dnl change the normal "Iface" suffix on interface types to "Interface". So
513 dnl let's make sure that behaviour is tested.
514 AT_SETUP([--gtk3 option])
515 AT_KEYWORDS([option])dnl
517 AT_DATA([test.gob], [[class :Test from G:Object
518 (interface Gtk:Actionable)
523 AT_CHECK([gob2 test.gob])
525 's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
529 AT_CHECK([gob2 --gtk3 test.gob])
531 's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
532 [GtkActionableInterface
537 AT_SETUP([--m4-dir option])
538 AT_KEYWORDS([option])dnl
539 AT_CHECK_UNQUOTED([gob2 --m4-dir], [0], [$pkgdatadir/m4
543 dnl Check that the --m4 option shells out to m4 and passes through
544 dnl all remaining arguments.
545 AT_SETUP([--m4 option])
546 AT_KEYWORDS([option])dnl
549 AT_DATA([bin/m4], [[#!/bin/sh
550 test $][# != 0 && printf '%s\n' "$][*" >&2
552 class M4:Test from G:Object
559 PATH=$PWD/bin${PATH:+":$PATH"}
560 AT_CHECK([gob2 --m4 filename], [0], [], [stderr])
561 read gob_m4_args <stderr
562 AT_CHECK([test -f m4-test.c])
564 rm -f m4-test.c m4-test.h
566 $gob_m4_args --help I am trapped in a test case factory --
568 AT_CHECK([gob2 --m4 filename --help I am trapped in a test case factory --],
570 AT_CHECK([test -f m4-test.c])
572 set x $gob_m4_args; shift
576 AS_CASE([$arg], [filename], [], [*], [set x "$@" "$arg"; shift])
582 AT_CHECK([gob2 --m4 -- filename], [0], [], [experr])
586 dnl Check that the --m4 option shells out to m4 and passes through
587 dnl all remaining arguments without adding any additional arguments.
588 AT_SETUP([--m4-clean option])
589 AT_KEYWORDS([option])dnl
592 AT_DATA([bin/m4], [[#!/bin/sh
593 test $][# != 0 && printf '%s\n' "$][*" >&2
595 class M4:Test from G:Object
602 PATH=$PWD/bin${PATH:+":$PATH"}
603 AT_CHECK([gob2 --m4-clean filename], [0], [], [filename
605 AT_CHECK([test -f m4-test.c])
607 rm -f m4-test.c m4-test.h
609 [gob2 --m4-clean filename --help I am trapped in a test case factory --],
610 [0], [], [filename --help I am trapped in a test case factory --
612 AT_CHECK([test -f m4-test.c])