]> git.draconx.ca Git - gob-dx.git/blob - tests/options.at
22e96091b01cc048f5e9b9f3e0c0ca056a84438b
[gob-dx.git] / tests / options.at
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.
5
6 dnl Check that the --help option exits successfully and prints only to
7 dnl standard output.
8 AT_SETUP([--help option])
9 AT_KEYWORDS([option])dnl
10
11 AT_CHECK([gob2 invalid-file.gob --help --invalid-option], [0], [ignore-nolog])
12
13 AT_CLEANUP
14
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
19
20 # Currently prints to standard error :(
21 AT_XFAIL_IF([:])
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
24 ])
25
26 AT_CLEANUP
27
28 AT_SETUP([--exit-on-warn option])
29 AT_KEYWORDS([option])dnl
30
31 AT_DATA([test.gob], [[class :Test from G:Object
32 {
33   private int x;
34   /* gob produces a warning due to override and nick combination */
35   property INT x ( override, nick = "hello", link );
36 }
37 ]])
38
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])
42
43 AT_CLEANUP
44
45 AT_SETUP([--no-exit-on-warn option])
46 AT_KEYWORDS([option])dnl
47
48 AT_DATA([test.gob], [[class :Test from G:Object
49 {
50   private int x;
51   /* gob produces a warning due to override and nick combination */
52   property INT x ( override, nick = "hello", link );
53 }
54 ]])
55
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])
60
61 AT_CLEANUP
62
63 AT_SETUP([--ondemand-private-header option])
64 AT_KEYWORDS([option])dnl
65
66 AT_DATA([priv.gob], [[class A:B:C from G:Object {
67   private int x;
68 }
69 %{
70 TEST_WITNESS_C
71 %}
72 %h{
73 TEST_WITNESS_H
74 %}
75 %privateheader{
76 TEST_WITNESS_PRIVATE
77 %}
78 ]])
79 sed '/private int/d' priv.gob >nopriv.gob
80
81 rm -f *.c *.h
82 AT_CHECK([gob2 nopriv.gob])
83 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
84 TEST_WITNESS_PRIVATE
85 ])
86 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
87 ])
88 AT_CHECK([test ! -f a-b-c-private.h])
89
90 rm -f *.c *.h
91 AT_CHECK([gob2 priv.gob])
92 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
93 ])
94 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
95 ])
96 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
97 ])
98
99 rm -f *.c *.h
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
102 TEST_WITNESS_PRIVATE
103 ])
104 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
105 ])
106 AT_CHECK([test ! -f a-b-c-private.h])
107
108 rm -f *.c *.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
111 ])
112 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
113 ])
114 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
115 ])
116
117 AT_CLEANUP
118
119 AT_SETUP([--always-private-header option])
120 AT_KEYWORDS([option])dnl
121
122 AT_DATA([priv.gob], [[class A:B:C from G:Object {
123   private int x;
124 }
125 %{
126 TEST_WITNESS_C
127 %}
128 %h{
129 TEST_WITNESS_H
130 %}
131 %privateheader{
132 TEST_WITNESS_PRIVATE
133 %}
134 ]])
135 sed '/private int/d' priv.gob >nopriv.gob
136
137 rm -f *.c *.h
138 AT_CHECK([gob2 nopriv.gob --always-private-header])
139 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
140 ])
141 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
142 ])
143 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
144 ])
145
146 rm -f *.c *.h
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
149 ])
150 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
151 ])
152 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
153 ])
154
155 rm -f *.c *.h
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
158 ])
159 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
160 ])
161 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
162 ])
163
164 AT_CLEANUP
165
166 AT_SETUP([--no-private-header option])
167 AT_KEYWORDS([option])dnl
168
169 AT_DATA([priv.gob], [[class A:B:C from G:Object {
170   private int x;
171 }
172 %{
173 TEST_WITNESS_C
174 %}
175 %h{
176 TEST_WITNESS_H
177 %}
178 %privateheader{
179 TEST_WITNESS_PRIVATE
180 %}
181 ]])
182 sed '/private int/d' priv.gob >nopriv.gob
183
184 rm -f *.c *.h
185 AT_CHECK([gob2 priv.gob --no-private-header])
186 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
187 TEST_WITNESS_PRIVATE
188 ])
189 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
190 ])
191 AT_CHECK([test ! -f a-b-c-private.h])
192
193 rm -f *.c *.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
196 TEST_WITNESS_PRIVATE
197 ])
198 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
199 ])
200 AT_CHECK([test ! -f a-b-c-private.h])
201
202 rm -f *.c *.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
205 TEST_WITNESS_PRIVATE
206 ])
207 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
208 ])
209 AT_CHECK([test ! -f a-b-c-private.h])
210
211 AT_CLEANUP
212
213 AT_SETUP([--file-sep option])
214 AT_KEYWORDS([option])dnl
215
216 AT_DATA([test.gob], [[class A:B:C from G:Object {
217 }
218 %{
219 TEST_WITNESS_C
220 %}
221 %h{
222 TEST_WITNESS_H
223 %}
224 %privateheader{
225 TEST_WITNESS_PRIVATE
226 %}
227 ]])
228
229 mkdir a; mkdir a/b
230 AT_CHECK([gob2 test.gob --file-sep=/])
231 AT_CHECK([grep '^TEST_WITNESS' a/b/c.c], [0], [TEST_WITNESS_C
232 TEST_WITNESS_PRIVATE
233 ])
234 AT_CHECK([grep '^TEST_WITNESS' a/b/c.h], [0], [TEST_WITNESS_H
235 ])
236
237 AT_CHECK([gob2 test.gob --always-private-header --file-sep=])
238 AT_CHECK([grep '^TEST_WITNESS' abc.c], [0], [TEST_WITNESS_C
239 ])
240 AT_CHECK([grep '^TEST_WITNESS' abc.h], [0], [TEST_WITNESS_H
241 ])
242 AT_CHECK([grep '^TEST_WITNESS' abcprivate.h], [0], [TEST_WITNESS_PRIVATE
243 ])
244
245 rm -f abc*
246 AT_CHECK([gob2 test.gob --file-sep])
247 AT_CHECK([grep '^TEST_WITNESS' abc.c], [0], [TEST_WITNESS_C
248 TEST_WITNESS_PRIVATE
249 ])
250 AT_CHECK([grep '^TEST_WITNESS' abc.h], [0], [TEST_WITNESS_H
251 ])
252
253 AT_CLEANUP
254
255 AT_SETUP([--output-dir option])
256 AT_KEYWORDS([option])dnl
257
258 AT_DATA([test.gob], [[class A:B:C from G:Object {
259 }
260 %{
261 TEST_WITNESS_C
262 %}
263 %h{
264 TEST_WITNESS_H
265 %}
266 ]])
267
268 mkdir output-dir o
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
271 ])
272 AT_CHECK([grep '^TEST_WITNESS' output-dir/a-b-c.h], [0], [TEST_WITNESS_H
273 ])
274
275 AT_CHECK([gob2 test.gob -o o])
276 AT_CHECK([grep '^TEST_WITNESS' o/a-b-c.c], [0], [TEST_WITNESS_C
277 ])
278 AT_CHECK([grep '^TEST_WITNESS' o/a-b-c.h], [0], [TEST_WITNESS_H
279 ])
280
281 AT_CLEANUP
282
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
289
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])
295 rm -f test.h
296
297 AT_DATA([test.gob], [[class :Test from G:Object
298 {
299   private int x;
300 }
301 ]])
302
303 m4_if(OPTION, [--no-touch-headers],
304 [#Currently, the private header is modified even with --no-touch-headers.
305 AT_XFAIL_IF([:])])dnl
306
307 AT_CHECK([gob2 test.gob])
308 touch test-c test-h test-private
309 TEST_MTIME_DELAY
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])
314
315 touch test-c test-h test-private
316 TEST_MTIME_DELAY
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])
322
323 cat >>test.gob <<'EOF'
324 %{
325 /* some code */
326 %}
327 EOF
328 touch test-c test-h test-private
329 TEST_MTIME_DELAY
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])
334
335 cat >>test.gob <<'EOF'
336 %h{
337 /* yonder comment */
338 %}
339 EOF
340 touch test-c test-h test-private
341 TEST_MTIME_DELAY
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])
347
348 cat >>test.gob <<'EOF'
349 %privateheader{
350 /* once more unto the breach */
351 %}
352 EOF
353 touch test-c test-h test-private
354 TEST_MTIME_DELAY
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])
360
361 AT_CLEANUP
362 ])
363
364 AT_SETUP([--no-write option])
365 AT_KEYWORDS([option])dnl
366
367 mkdir outdir
368 AT_DATA([outdir/test.gob], [[class :Test from G:Object
369 {
370   private int x;
371 }
372 ]])
373 AT_CHECK([cd outdir && ls -Al], [0], [stdout-nolog])
374 mv -f stdout expout
375
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])
378
379 AT_CHECK([cd outdir && gob2 test.gob && ls -Al], [0], [stdout-nolog])
380 mv -f stdout expout
381
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])
384
385 AT_CLEANUP
386
387 AT_SETUP([--no-extern-c option])
388 AT_KEYWORDS([option])dnl
389
390 AT_DATA([test.gob], [[class :Test from G:Object
391 {
392   private int x;
393 }
394 ]])
395
396 AT_CHECK([gob2 test.gob])
397 AT_CHECK([cat *.h | grep 'extern "C"'], [0], [extern "C" {
398 extern "C" {
399 ])
400
401 AT_CHECK([gob2 --no-extern-c test.gob])
402 AT_CHECK([cat *.h | grep 'extern "C"'], [1])
403
404 AT_CLEANUP
405
406 AT_SETUP([--no-gnu option])
407 AT_KEYWORDS([option])dnl
408
409 AT_DATA([test.gob], [[enum TEST_ENUM {
410   TEST_ENUM_A
411 } Test:Enum;
412
413 flags TEST_FLAGS {
414   TEST_FLAG_A
415 } Test:Flags;
416
417 error TEST_ERROR {
418   TEST_ERROR_A
419 } Test:Error;
420
421 class :Test from G:Object
422 {
423   private int x;
424 }
425 ]])
426
427 # --no-gnu is currently busted for the get_type function declaration.
428 AT_XFAIL_IF([:])
429
430 AT_CHECK([gob2 test.gob])
431 AT_CHECK([cat test*.h test.c | grep '_GNUC_' >/dev/null], [0])
432
433 AT_CHECK([gob2 --no-gnu test.gob])
434 AT_CHECK([cat test*.h test.c | grep '_GNUC_'], [1])
435
436 AT_CLEANUP
437
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
443
444 AT_DATA([test.gob], [[class :Test from G:Object
445 {
446   public void myfunction(self) { };
447 }
448 ]])
449
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])
454
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])
459
460 AT_CLEANUP
461
462 AT_SETUP([--no-lines option])
463 AT_KEYWORDS([option])dnl
464
465 AT_DATA([test.gob], [[class :Test from G:Object
466 {
467   public int foo(void) { return 42; }
468   private int x;
469 }
470 ]])
471
472 AT_CHECK([gob2 test.gob])
473 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line' >/dev/null])
474
475 AT_CHECK([gob2 --no-lines test.gob])
476 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line'], [1])
477
478 AT_CLEANUP
479
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
483
484 AT_DATA([test.gob], [[class :Test from G:Object
485 {
486 }
487 ]])
488
489 mkdir orig
490 AT_CHECK([gob2 --output-dir orig test.gob])
491 AT_CHECK([gob2 --no-kill-underscores test.gob])
492
493 cp -f orig/test.c expout
494 AT_CHECK([cat test.c], [0], [expout])
495
496 cp -f orig/test.h expout
497 AT_CHECK([cat test.h], [0], [expout])
498
499 AT_CLEANUP
500
501 AT_SETUP([--always-private-struct option])
502 AT_KEYWORDS([option])dnl
503
504 AT_DATA([test.gob], [[class :Test from G:Object
505 {
506   public int my_public_member;
507 }
508 ]])
509
510 AT_CHECK([gob2 test.gob])
511 AT_CHECK([sed -n '/my_public_member/,/^}/s/_priv/&/p' test.h])
512
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;
516 ])
517
518 AT_CLEANUP
519
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
525
526 AT_DATA([test.gob], [[class :Test from G:Object
527   (interface Gtk:Actionable)
528 {
529 }
530 ]])
531
532 AT_CHECK([gob2 test.gob])
533 AT_CHECK([sed -n \
534   's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
535   [GtkActionableIface
536 ])
537
538 AT_CHECK([gob2 --gtk3 test.gob])
539 AT_CHECK([sed -n \
540   's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
541   [GtkActionableInterface
542 ])
543
544 AT_CLEANUP
545
546 AT_SETUP([--m4-dir option])
547 AT_KEYWORDS([option])dnl
548 AT_CHECK_UNQUOTED([gob2 --m4-dir], [0], [$pkgdatadir/m4
549 ])
550 AT_CLEANUP
551
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
556
557 mkdir bin
558 AT_DATA([bin/m4], [[#!/bin/sh
559 test $][# != 0 && printf '%s\n' "$][*" >&2
560 cat <<'EOF'
561 class M4:Test from G:Object
562 {
563 }
564 EOF
565 ]])
566 chmod +x bin/m4
567
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])
572
573 rm -f m4-test.c m4-test.h
574 cat >experr <<EOF
575 $gob_m4_args --help I am trapped in a test case factory --
576 EOF
577 AT_CHECK([gob2 --m4 filename --help I am trapped in a test case factory --],
578   [0], [], [experr])
579 AT_CHECK([test -f m4-test.c])
580
581 AT_CLEANUP
582
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
587
588 mkdir bin
589 AT_DATA([bin/m4], [[#!/bin/sh
590 test $][# != 0 && printf '%s\n' "$][*" >&2
591 cat <<'EOF'
592 class M4:Test from G:Object
593 {
594 }
595 EOF
596 ]])
597 chmod +x bin/m4
598
599 PATH=$PWD/bin${PATH:+":$PATH"}
600 AT_CHECK([gob2 --m4-clean filename], [0], [], [filename
601 ])
602 AT_CHECK([test -f m4-test.c])
603
604 rm -f m4-test.c m4-test.h
605 AT_CHECK(
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 --
608 ])
609 AT_CHECK([test -f m4-test.c])
610
611 AT_CLEANUP