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 # Currently prints to standard error :(
22 AT_CHECK([gob2 invalid-file.gob --version --invalid-option], [0], [stdout])
23 AT_CHECK([awk 'NR == 1 { print $NF }' stdout], [0], [AT_PACKAGE_VERSION
28 AT_SETUP([--exit-on-warn option])
29 AT_KEYWORDS([option])dnl
31 AT_DATA([test.gob], [[class :Test from G:Object
34 /* gob produces a warning due to override and nick combination */
35 property INT x ( override, nick = "hello", link );
39 AT_CHECK([gob2 test.gob], [0], [], [ignore])
40 AT_CHECK([gob2 test.gob --exit-on-warn], [1], [], [ignore])
41 AT_CHECK([gob2 test.gob --no-exit-on-warn -w], [1], [], [ignore])
45 AT_SETUP([--no-exit-on-warn option])
46 AT_KEYWORDS([option])dnl
48 AT_DATA([test.gob], [[class :Test from G:Object
51 /* gob produces a warning due to override and nick combination */
52 property INT x ( override, nick = "hello", link );
56 AT_CHECK([gob2 test.gob], [0], [], [ignore])
57 AT_CHECK([gob2 test.gob --exit-on-warn], [1], [], [ignore])
58 AT_CHECK([gob2 test.gob -w --no-exit-on-warn], [0], [], [ignore])
59 AT_CHECK([gob2 test.gob --exit-on-warn --no-exit-on-warn], [0], [], [ignore])
63 AT_SETUP([--ondemand-private-header option])
64 AT_KEYWORDS([option])dnl
66 AT_DATA([priv.gob], [[class A:B:C from G:Object {
79 sed '/private int/d' priv.gob >nopriv.gob
82 AT_CHECK([gob2 nopriv.gob])
83 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
86 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
88 AT_CHECK([test ! -f a-b-c-private.h])
91 AT_CHECK([gob2 priv.gob])
92 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
94 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
96 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
100 AT_CHECK([gob2 nopriv.gob --always-private-header --ondemand-private-header])
101 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
104 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
106 AT_CHECK([test ! -f a-b-c-private.h])
109 AT_CHECK([gob2 priv.gob --no-private-header --ondemand-private-header])
110 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
112 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
114 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
119 AT_SETUP([--always-private-header option])
120 AT_KEYWORDS([option])dnl
122 AT_DATA([priv.gob], [[class A:B:C from G:Object {
135 sed '/private int/d' priv.gob >nopriv.gob
138 AT_CHECK([gob2 nopriv.gob --always-private-header])
139 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
141 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
143 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
147 AT_CHECK([gob2 priv.gob --no-private-header --always-private-header])
148 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
150 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
152 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
156 AT_CHECK([gob2 nopriv.gob --ondemand-private-header --always-private-header])
157 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
159 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
161 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
166 AT_SETUP([--no-private-header option])
167 AT_KEYWORDS([option])dnl
169 AT_DATA([priv.gob], [[class A:B:C from G:Object {
182 sed '/private int/d' priv.gob >nopriv.gob
185 AT_CHECK([gob2 priv.gob --no-private-header])
186 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
189 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
191 AT_CHECK([test ! -f a-b-c-private.h])
194 AT_CHECK([gob2 nopriv.gob --always-private-header --no-private-header])
195 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
198 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
200 AT_CHECK([test ! -f a-b-c-private.h])
203 AT_CHECK([gob2 priv.gob --ondemand-private-header --no-private-header])
204 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
207 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
209 AT_CHECK([test ! -f a-b-c-private.h])
213 AT_SETUP([--file-sep option])
214 AT_KEYWORDS([option])dnl
216 AT_DATA([test.gob], [[class A:B:C from G:Object {
230 AT_CHECK([gob2 test.gob --file-sep=/])
231 AT_CHECK([grep '^TEST_WITNESS' a/b/c.c], [0], [TEST_WITNESS_C
234 AT_CHECK([grep '^TEST_WITNESS' a/b/c.h], [0], [TEST_WITNESS_H
237 AT_CHECK([gob2 test.gob --always-private-header --file-sep=])
238 AT_CHECK([grep '^TEST_WITNESS' abc.c], [0], [TEST_WITNESS_C
240 AT_CHECK([grep '^TEST_WITNESS' abc.h], [0], [TEST_WITNESS_H
242 AT_CHECK([grep '^TEST_WITNESS' abcprivate.h], [0], [TEST_WITNESS_PRIVATE
246 AT_CHECK([gob2 test.gob --file-sep])
247 AT_CHECK([grep '^TEST_WITNESS' abc.c], [0], [TEST_WITNESS_C
250 AT_CHECK([grep '^TEST_WITNESS' abc.h], [0], [TEST_WITNESS_H
255 AT_SETUP([--output-dir option])
256 AT_KEYWORDS([option])dnl
258 AT_DATA([test.gob], [[class A:B:C from G:Object {
269 AT_CHECK([gob2 test.gob --output-dir=output-dir])
270 AT_CHECK([grep '^TEST_WITNESS' output-dir/a-b-c.c], [0], [TEST_WITNESS_C
272 AT_CHECK([grep '^TEST_WITNESS' output-dir/a-b-c.h], [0], [TEST_WITNESS_H
275 AT_CHECK([gob2 test.gob -o o])
276 AT_CHECK([grep '^TEST_WITNESS' o/a-b-c.c], [0], [TEST_WITNESS_C
278 AT_CHECK([grep '^TEST_WITNESS' o/a-b-c.h], [0], [TEST_WITNESS_H
283 dnl Check that the --no-touch option does not modify any files that would be
284 dnl unchanged by gob, and that the --no-touch-headers option does not modify
285 dnl any header files.
286 m4_foreach([OPTION], [[[--no-touch]], [[--no-touch-headers]]],
287 [AT_SETUP([OPTION option])
288 AT_KEYWORDS([option])dnl
290 # Sanity check for make implementation
291 touch test.h; touch test-h
292 AT_CHECK([mtime_uptodate test-h test.h || exit 77])
293 TEST_MTIME_DELAY; touch test.h
294 AT_CHECK([mtime_uptodate test-h test.h && exit 77], [1])
297 AT_DATA([test.gob], [[class :Test from G:Object
303 m4_if(OPTION, [--no-touch-headers],
304 [#Currently, the private header is modified even with --no-touch-headers.
305 AT_XFAIL_IF([:])])dnl
307 AT_CHECK([gob2 test.gob])
308 touch test-c test-h test-private
310 AT_CHECK([gob2 test.gob])
311 AT_CHECK([mtime_uptodate test-c test.c], [1])
312 AT_CHECK([mtime_uptodate test-h test.h], [1])
313 AT_CHECK([mtime_uptodate test-private test-private.h], [1])
315 touch test-c test-h test-private
317 AT_CHECK([gob2 test.gob OPTION])
318 AT_CHECK([mtime_uptodate test-c test.c],
319 m4_if(OPTION, [--no-touch], [0], [1]))
320 AT_CHECK([mtime_uptodate test-h test.h], [0])
321 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
323 cat >>test.gob <<'EOF'
328 touch test-c test-h test-private
330 AT_CHECK([gob2 test.gob OPTION])
331 AT_CHECK([mtime_uptodate test-c test.c], [1])
332 AT_CHECK([mtime_uptodate test-h test.h], [0])
333 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
335 cat >>test.gob <<'EOF'
340 touch test-c test-h test-private
342 AT_CHECK([gob2 test.gob OPTION])
343 AT_CHECK([mtime_uptodate test-c test.c],
344 m4_if(OPTION, [--no-touch], [0], [1]))
345 AT_CHECK([mtime_uptodate test-h test.h], [1])
346 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
348 cat >>test.gob <<'EOF'
350 /* once more unto the breach */
353 touch test-c test-h test-private
355 AT_CHECK([gob2 test.gob OPTION])
356 AT_CHECK([mtime_uptodate test-c test.c],
357 m4_if(OPTION, [--no-touch], [0], [1]))
358 AT_CHECK([mtime_uptodate test-h test.h], [0])
359 AT_CHECK([mtime_uptodate test-private test-private.h], [1])
364 AT_SETUP([--no-write option])
365 AT_KEYWORDS([option])dnl
368 AT_DATA([outdir/test.gob], [[class :Test from G:Object
373 AT_CHECK([cd outdir && 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])
379 AT_CHECK([cd outdir && gob2 test.gob && ls -Al], [0], [stdout-nolog])
382 AT_CHECK([cd outdir && gob2 test.gob --no-write && ls -Al], [0], [expout])
383 AT_CHECK([cd outdir && gob2 test.gob -n && ls -Al], [0], [expout])
387 AT_SETUP([--no-extern-c option])
388 AT_KEYWORDS([option])dnl
390 AT_DATA([test.gob], [[class :Test from G:Object
396 AT_CHECK([gob2 test.gob])
397 AT_CHECK([cat *.h | grep 'extern "C"'], [0], [extern "C" {
401 AT_CHECK([gob2 --no-extern-c test.gob])
402 AT_CHECK([cat *.h | grep 'extern "C"'], [1])
406 AT_SETUP([--no-gnu option])
407 AT_KEYWORDS([option])dnl
409 AT_DATA([test.gob], [[enum TEST_ENUM {
421 class :Test from G:Object
427 # --no-gnu is currently busted for the get_type function declaration.
430 AT_CHECK([gob2 test.gob])
431 AT_CHECK([cat test*.h test.c | grep '_GNUC_' >/dev/null], [0])
433 AT_CHECK([gob2 --no-gnu test.gob])
434 AT_CHECK([cat test*.h test.c | grep '_GNUC_'], [1])
438 dnl Check that --no-self-alias works as documented. The self_xxx method
439 dnl aliases are not documented to be affected by this option, so check that
440 dnl they are unaffected.
441 AT_SETUP([--no-self-alias option])
442 AT_KEYWORDS([option])dnl
444 AT_DATA([test.gob], [[class :Test from G:Object
446 public void myfunction(self) { };
450 AT_CHECK([gob2 test.gob])
451 AT_CHECK([:; { grep '#define.*SELF' test.c &&
452 grep 'typedef.*Self' test.c &&
453 grep '#define.*self_myfunction' test.c; } >/dev/null], [0])
455 AT_CHECK([gob2 --no-self-alias test.gob])
456 AT_CHECK([grep '#.*define.*SELF' test.c], [1])
457 AT_CHECK([grep 'typedef.*Self' test.c], [1])
458 AT_CHECK([grep '#define.*self_myfunction' test.c >/dev/null], [0])
462 AT_SETUP([--no-lines option])
463 AT_KEYWORDS([option])dnl
465 AT_DATA([test.gob], [[class :Test from G:Object
467 public int foo(void) { return 42; }
472 AT_CHECK([gob2 test.gob])
473 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line' >/dev/null])
475 AT_CHECK([gob2 --no-lines test.gob])
476 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line'], [1])
480 dnl Check that the --no-kill-underscores option is ignored for compatibility.
481 AT_SETUP([--no-kill-underscores option])
482 AT_KEYWORDS([option])dnl
484 AT_DATA([test.gob], [[class :Test from G:Object
490 AT_CHECK([gob2 --output-dir orig test.gob])
491 AT_CHECK([gob2 --no-kill-underscores test.gob])
493 cp -f orig/test.c expout
494 AT_CHECK([cat test.c], [0], [expout])
496 cp -f orig/test.h expout
497 AT_CHECK([cat test.h], [0], [expout])
501 AT_SETUP([--always-private-struct option])
502 AT_KEYWORDS([option])dnl
504 AT_DATA([test.gob], [[class :Test from G:Object
506 public int my_public_member;
510 AT_CHECK([gob2 test.gob])
511 AT_CHECK([sed -n '/my_public_member/,/^}/s/_priv/&/p' test.h])
513 AT_CHECK([gob2 --always-private-struct test.gob])
514 AT_CHECK([sed -n '/my_public_member/,/^}/s/[[ ]]*\(.*_priv;\)/\1/p' test.h],
515 [0], [TestPrivate *_priv;
520 dnl Check the --gtk3 option. The only effect of this option seems to be to
521 dnl change the normal "Iface" suffix on interface types to "Interface". So
522 dnl let's make sure that behaviour is tested.
523 AT_SETUP([--gtk3 option])
524 AT_KEYWORDS([option])dnl
526 AT_DATA([test.gob], [[class :Test from G:Object
527 (interface Gtk:Actionable)
532 AT_CHECK([gob2 test.gob])
534 's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
538 AT_CHECK([gob2 --gtk3 test.gob])
540 's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
541 [GtkActionableInterface
546 AT_SETUP([--m4-dir option])
547 AT_KEYWORDS([option])dnl
548 AT_CHECK_UNQUOTED([gob2 --m4-dir], [0], [$pkgdatadir/m4
552 dnl Check that the --m4 option shells out to m4 and passes through
553 dnl all remaining arguments.
554 AT_SETUP([--m4 option])
555 AT_KEYWORDS([option])dnl
558 AT_DATA([bin/m4], [[#!/bin/sh
559 test $][# != 0 && printf '%s\n' "$][*" >&2
561 class M4:Test from G:Object
568 PATH=$PWD/bin${PATH:+":$PATH"}
569 AT_CHECK([gob2 --m4 filename], [0], [], [stderr])
570 read gob_m4_args <stderr
571 AT_CHECK([test -f m4-test.c])
573 rm -f m4-test.c m4-test.h
575 $gob_m4_args --help I am trapped in a test case factory --
577 AT_CHECK([gob2 --m4 filename --help I am trapped in a test case factory --],
579 AT_CHECK([test -f m4-test.c])
583 dnl Check that the --m4 option shells out to m4 and passes through
584 dnl all remaining arguments without adding any additional arguments.
585 AT_SETUP([--m4-clean option])
586 AT_KEYWORDS([option])dnl
589 AT_DATA([bin/m4], [[#!/bin/sh
590 test $][# != 0 && printf '%s\n' "$][*" >&2
592 class M4:Test from G:Object
599 PATH=$PWD/bin${PATH:+":$PATH"}
600 AT_CHECK([gob2 --m4-clean filename], [0], [], [filename
602 AT_CHECK([test -f m4-test.c])
604 rm -f m4-test.c m4-test.h
606 [gob2 --m4-clean filename --help I am trapped in a test case factory --],
607 [0], [], [filename --help I am trapped in a test case factory --
609 AT_CHECK([test -f m4-test.c])