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 # Currently prints to standard error :(
13 AT_CHECK([gob2 invalid-file.gob --help --invalid-option], [0], [ignore-nolog])
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
22 # Currently prints to standard error :(
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
30 AT_SETUP([--exit-on-warn option])
31 AT_KEYWORDS([option])dnl
33 AT_DATA([test.gob], [[class :Test from G:Object
36 /* gob produces a warning due to override and nick combination */
37 property INT x ( override, nick = "hello", link );
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])
47 AT_SETUP([--no-exit-on-warn option])
48 AT_KEYWORDS([option])dnl
50 AT_DATA([test.gob], [[class :Test from G:Object
53 /* gob produces a warning due to override and nick combination */
54 property INT x ( override, nick = "hello", link );
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])
65 AT_SETUP([--ondemand-private-header option])
66 AT_KEYWORDS([option])dnl
68 AT_DATA([priv.gob], [[class A:B:C from G:Object {
81 sed '/private int/d' priv.gob >nopriv.gob
84 AT_CHECK([gob2 nopriv.gob])
85 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
88 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
90 AT_CHECK([test ! -f a-b-c-private.h])
93 AT_CHECK([gob2 priv.gob])
94 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
96 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
98 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
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
106 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
108 AT_CHECK([test ! -f a-b-c-private.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
114 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
116 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
121 AT_SETUP([--always-private-header option])
122 AT_KEYWORDS([option])dnl
124 AT_DATA([priv.gob], [[class A:B:C from G:Object {
137 sed '/private int/d' priv.gob >nopriv.gob
140 AT_CHECK([gob2 nopriv.gob --always-private-header])
141 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
143 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
145 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
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
152 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
154 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
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
161 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
163 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
168 AT_SETUP([--no-private-header option])
169 AT_KEYWORDS([option])dnl
171 AT_DATA([priv.gob], [[class A:B:C from G:Object {
184 sed '/private int/d' priv.gob >nopriv.gob
187 AT_CHECK([gob2 priv.gob --no-private-header])
188 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
191 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
193 AT_CHECK([test ! -f a-b-c-private.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
200 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
202 AT_CHECK([test ! -f a-b-c-private.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
209 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
211 AT_CHECK([test ! -f a-b-c-private.h])
215 AT_SETUP([--file-sep option])
216 AT_KEYWORDS([option])dnl
218 AT_DATA([test.gob], [[class A:B:C from G:Object {
232 AT_CHECK([gob2 test.gob --file-sep=/])
233 AT_CHECK([grep '^TEST_WITNESS' a/b/c.c], [0], [TEST_WITNESS_C
236 AT_CHECK([grep '^TEST_WITNESS' a/b/c.h], [0], [TEST_WITNESS_H
239 AT_CHECK([gob2 test.gob --always-private-header --file-sep=])
240 AT_CHECK([grep '^TEST_WITNESS' abc.c], [0], [TEST_WITNESS_C
242 AT_CHECK([grep '^TEST_WITNESS' abc.h], [0], [TEST_WITNESS_H
244 AT_CHECK([grep '^TEST_WITNESS' abcprivate.h], [0], [TEST_WITNESS_PRIVATE
248 AT_CHECK([gob2 test.gob --file-sep])
249 AT_CHECK([grep '^TEST_WITNESS' abc.c], [0], [TEST_WITNESS_C
252 AT_CHECK([grep '^TEST_WITNESS' abc.h], [0], [TEST_WITNESS_H
257 AT_SETUP([--output-dir option])
258 AT_KEYWORDS([option])dnl
260 AT_DATA([test.gob], [[class A:B:C from G:Object {
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
274 AT_CHECK([grep '^TEST_WITNESS' output-dir/a-b-c.h], [0], [TEST_WITNESS_H
277 AT_CHECK([gob2 test.gob -o o])
278 AT_CHECK([grep '^TEST_WITNESS' o/a-b-c.c], [0], [TEST_WITNESS_C
280 AT_CHECK([grep '^TEST_WITNESS' o/a-b-c.h], [0], [TEST_WITNESS_H
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
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])
299 AT_DATA([test.gob], [[class :Test from G:Object
305 m4_if(OPTION, [--no-touch-headers],
306 [#Currently, the private header is modified even with --no-touch-headers.
307 AT_XFAIL_IF([:])])dnl
309 AT_CHECK([gob2 test.gob])
310 touch test-c test-h test-private
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])
317 touch test-c test-h test-private
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])
325 cat >>test.gob <<'EOF'
330 touch test-c test-h test-private
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])
337 cat >>test.gob <<'EOF'
342 touch test-c test-h test-private
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])
350 cat >>test.gob <<'EOF'
352 /* once more unto the breach */
355 touch test-c test-h test-private
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])
366 AT_SETUP([--no-write option])
367 AT_KEYWORDS([option])dnl
370 AT_DATA([outdir/test.gob], [[class :Test from G:Object
375 AT_CHECK([cd outdir && ls -Al], [0], [stdout-nolog])
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])
381 AT_CHECK([cd outdir && gob2 test.gob && ls -Al], [0], [stdout-nolog])
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])
389 AT_SETUP([--no-extern-c option])
390 AT_KEYWORDS([option])dnl
392 AT_DATA([test.gob], [[class :Test from G:Object
398 AT_CHECK([gob2 test.gob])
399 AT_CHECK([cat *.h | grep 'extern "C"'], [0], [extern "C" {
403 AT_CHECK([gob2 --no-extern-c test.gob])
404 AT_CHECK([cat *.h | grep 'extern "C"'], [1])
408 AT_SETUP([--no-gnu option])
409 AT_KEYWORDS([option])dnl
411 AT_DATA([test.gob], [[enum TEST_ENUM {
423 class :Test from G:Object
429 # --no-gnu is currently busted for the get_type function declaration.
432 AT_CHECK([gob2 test.gob])
433 AT_CHECK([cat test*.h test.c | grep '_GNUC_' >/dev/null], [0])
435 AT_CHECK([gob2 --no-gnu test.gob])
436 AT_CHECK([cat test*.h test.c | grep '_GNUC_'], [1])
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
446 AT_DATA([test.gob], [[class :Test from G:Object
448 public void myfunction(self) { };
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])
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])
464 AT_SETUP([--no-lines option])
465 AT_KEYWORDS([option])dnl
467 AT_DATA([test.gob], [[class :Test from G:Object
469 public int foo(void) { return 42; }
474 AT_CHECK([gob2 test.gob])
475 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line' >/dev/null])
477 AT_CHECK([gob2 --no-lines test.gob])
478 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line'], [1])
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
486 AT_DATA([test.gob], [[class :Test from G:Object
492 AT_CHECK([gob2 --output-dir orig test.gob])
493 AT_CHECK([gob2 --no-kill-underscores test.gob])
495 cp -f orig/test.c expout
496 AT_CHECK([cat test.c], [0], [expout])
498 cp -f orig/test.h expout
499 AT_CHECK([cat test.h], [0], [expout])
503 AT_SETUP([--always-private-struct option])
504 AT_KEYWORDS([option])dnl
506 AT_DATA([test.gob], [[class :Test from G:Object
508 public int my_public_member;
512 AT_CHECK([gob2 test.gob])
513 AT_CHECK([sed -n '/my_public_member/,/^}/s/_priv/&/p' test.h])
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;
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
528 AT_DATA([test.gob], [[class :Test from G:Object
529 (interface Gtk:Actionable)
534 AT_CHECK([gob2 test.gob])
536 's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
540 AT_CHECK([gob2 --gtk3 test.gob])
542 's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
543 [GtkActionableInterface
548 AT_SETUP([--m4-dir option])
549 AT_KEYWORDS([option])dnl
550 AT_CHECK_UNQUOTED([gob2 --m4-dir], [0], [$pkgdatadir/m4
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
560 AT_DATA([bin/m4], [[#!/bin/sh
561 test $][# != 0 && printf '%s\n' "$][*" >&2
563 class M4:Test from G:Object
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])
575 rm -f m4-test.c m4-test.h
577 $gob_m4_args --help I am trapped in a test case factory --
579 AT_CHECK([gob2 --m4 filename --help I am trapped in a test case factory --],
581 AT_CHECK([test -f m4-test.c])
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
591 AT_DATA([bin/m4], [[#!/bin/sh
592 test $][# != 0 && printf '%s\n' "$][*" >&2
594 class M4:Test from G:Object
601 PATH=$PWD/bin${PATH:+":$PATH"}
602 AT_CHECK([gob2 --m4-clean filename], [0], [], [filename
604 AT_CHECK([test -f m4-test.c])
606 rm -f m4-test.c m4-test.h
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 --
611 AT_CHECK([test -f m4-test.c])