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 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 # --no-gnu is currently busted for the get_type function declaration.
424 AT_CHECK([gob2 test.gob])
425 AT_CHECK([cat test*.h test.c | grep '_GNUC_' >/dev/null], [0])
427 AT_CHECK([gob2 --no-gnu test.gob])
428 AT_CHECK([cat test*.h test.c | grep '_GNUC_'], [1])
432 dnl Check that --no-self-alias works as documented. The self_xxx method
433 dnl aliases are not documented to be affected by this option, so check that
434 dnl they are unaffected.
435 AT_SETUP([--no-self-alias option])
436 AT_KEYWORDS([option])dnl
438 AT_DATA([test.gob], [[class :Test from G:Object
440 public void myfunction(self) { };
444 AT_CHECK([gob2 test.gob])
445 AT_CHECK([:; { grep '#define.*SELF' test.c &&
446 grep 'typedef.*Self' test.c &&
447 grep '#define.*self_myfunction' test.c; } >/dev/null], [0])
449 AT_CHECK([gob2 --no-self-alias test.gob])
450 AT_CHECK([grep '#.*define.*SELF' test.c], [1])
451 AT_CHECK([grep 'typedef.*Self' test.c], [1])
452 AT_CHECK([grep '#define.*self_myfunction' test.c >/dev/null], [0])
456 AT_SETUP([--no-lines option])
457 AT_KEYWORDS([option])dnl
459 AT_DATA([test.gob], [[class :Test from G:Object
461 public int foo(void) { return 42; }
466 AT_CHECK([gob2 test.gob])
467 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line' >/dev/null])
469 AT_CHECK([gob2 --no-lines test.gob])
470 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line'], [1])
474 dnl Check that the --no-kill-underscores option is ignored for compatibility.
475 AT_SETUP([--no-kill-underscores option])
476 AT_KEYWORDS([option])dnl
478 AT_DATA([test.gob], [[class :Test from G:Object
484 AT_CHECK([gob2 --output-dir orig test.gob])
485 AT_CHECK([gob2 --no-kill-underscores test.gob])
487 cp -f orig/test.c expout
488 AT_CHECK([cat test.c], [0], [expout])
490 cp -f orig/test.h expout
491 AT_CHECK([cat test.h], [0], [expout])
495 AT_SETUP([--always-private-struct option])
496 AT_KEYWORDS([option])dnl
498 AT_DATA([test.gob], [[class :Test from G:Object
500 public int my_public_member;
504 AT_CHECK([gob2 test.gob])
505 AT_CHECK([sed -n '/my_public_member/,/^}/s/_priv/&/p' test.h])
507 AT_CHECK([gob2 --always-private-struct test.gob])
508 AT_CHECK([sed -n '/my_public_member/,/^}/s/[[ ]]*\(.*_priv;\)/\1/p' test.h],
509 [0], [TestPrivate *_priv;
514 dnl Check the --gtk3 option. The only effect of this option seems to be to
515 dnl change the normal "Iface" suffix on interface types to "Interface". So
516 dnl let's make sure that behaviour is tested.
517 AT_SETUP([--gtk3 option])
518 AT_KEYWORDS([option])dnl
520 AT_DATA([test.gob], [[class :Test from G:Object
521 (interface Gtk:Actionable)
526 AT_CHECK([gob2 test.gob])
528 's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
532 AT_CHECK([gob2 --gtk3 test.gob])
534 's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
535 [GtkActionableInterface
540 AT_SETUP([--m4-dir option])
541 AT_KEYWORDS([option])dnl
542 AT_CHECK_UNQUOTED([gob2 --m4-dir], [0], [$pkgdatadir/m4
546 dnl Check that the --m4 option shells out to m4 and passes through
547 dnl all remaining arguments.
548 AT_SETUP([--m4 option])
549 AT_KEYWORDS([option])dnl
552 AT_DATA([bin/m4], [[#!/bin/sh
553 test $][# != 0 && printf '%s\n' "$][*" >&2
555 class M4:Test from G:Object
562 PATH=$PWD/bin${PATH:+":$PATH"}
563 AT_CHECK([gob2 --m4 filename], [0], [], [stderr])
564 read gob_m4_args <stderr
565 AT_CHECK([test -f m4-test.c])
567 rm -f m4-test.c m4-test.h
569 $gob_m4_args --help I am trapped in a test case factory --
571 AT_CHECK([gob2 --m4 filename --help I am trapped in a test case factory --],
573 AT_CHECK([test -f m4-test.c])
577 dnl Check that the --m4 option shells out to m4 and passes through
578 dnl all remaining arguments without adding any additional arguments.
579 AT_SETUP([--m4-clean option])
580 AT_KEYWORDS([option])dnl
583 AT_DATA([bin/m4], [[#!/bin/sh
584 test $][# != 0 && printf '%s\n' "$][*" >&2
586 class M4:Test from G:Object
593 PATH=$PWD/bin${PATH:+":$PATH"}
594 AT_CHECK([gob2 --m4-clean filename], [0], [], [filename
596 AT_CHECK([test -f m4-test.c])
598 rm -f m4-test.c m4-test.h
600 [gob2 --m4-clean filename --help I am trapped in a test case factory --],
601 [0], [], [filename --help I am trapped in a test case factory --
603 AT_CHECK([test -f m4-test.c])