]> git.draconx.ca Git - gob-dx.git/blob - tests/options.at
53eda4695d45898f6184c092bc5aa08d9079e152
[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 AT_CHECK([gob2 invalid-file.gob --version --invalid-option], [0], [stdout])
21 AT_CHECK([awk 'NR == 1 { print $NF }' stdout], [0], [AT_PACKAGE_VERSION
22 ])
23
24 AT_CLEANUP
25
26 AT_SETUP([--exit-on-warn option])
27 AT_KEYWORDS([option])dnl
28
29 AT_DATA([test.gob], [[class :Test from G:Object
30 {
31   private int x;
32   /* gob produces a warning due to override and nick combination */
33   property INT x ( override, nick = "hello", link );
34 }
35 ]])
36
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])
40
41 AT_CLEANUP
42
43 AT_SETUP([--no-exit-on-warn option])
44 AT_KEYWORDS([option])dnl
45
46 AT_DATA([test.gob], [[class :Test from G:Object
47 {
48   private int x;
49   /* gob produces a warning due to override and nick combination */
50   property INT x ( override, nick = "hello", link );
51 }
52 ]])
53
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])
58
59 AT_CLEANUP
60
61 AT_SETUP([--ondemand-private-header option])
62 AT_KEYWORDS([option])dnl
63
64 AT_DATA([priv.gob], [[class A:B:C from G:Object {
65   private int x;
66 }
67 %{
68 TEST_WITNESS_C
69 %}
70 %h{
71 TEST_WITNESS_H
72 %}
73 %privateheader{
74 TEST_WITNESS_PRIVATE
75 %}
76 ]])
77 sed '/private int/d' priv.gob >nopriv.gob
78
79 rm -f *.c *.h
80 AT_CHECK([gob2 nopriv.gob])
81 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
82 TEST_WITNESS_PRIVATE
83 ])
84 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
85 ])
86 AT_CHECK([test ! -f a-b-c-private.h])
87
88 rm -f *.c *.h
89 AT_CHECK([gob2 priv.gob])
90 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
91 ])
92 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
93 ])
94 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
95 ])
96
97 rm -f *.c *.h
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
100 TEST_WITNESS_PRIVATE
101 ])
102 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
103 ])
104 AT_CHECK([test ! -f a-b-c-private.h])
105
106 rm -f *.c *.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
109 ])
110 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
111 ])
112 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
113 ])
114
115 AT_CLEANUP
116
117 AT_SETUP([--always-private-header option])
118 AT_KEYWORDS([option])dnl
119
120 AT_DATA([priv.gob], [[class A:B:C from G:Object {
121   private int x;
122 }
123 %{
124 TEST_WITNESS_C
125 %}
126 %h{
127 TEST_WITNESS_H
128 %}
129 %privateheader{
130 TEST_WITNESS_PRIVATE
131 %}
132 ]])
133 sed '/private int/d' priv.gob >nopriv.gob
134
135 rm -f *.c *.h
136 AT_CHECK([gob2 nopriv.gob --always-private-header])
137 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
138 ])
139 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
140 ])
141 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
142 ])
143
144 rm -f *.c *.h
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
147 ])
148 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
149 ])
150 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
151 ])
152
153 rm -f *.c *.h
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
156 ])
157 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
158 ])
159 AT_CHECK([grep '^TEST_WITNESS' a-b-c-private.h], [0], [TEST_WITNESS_PRIVATE
160 ])
161
162 AT_CLEANUP
163
164 AT_SETUP([--no-private-header option])
165 AT_KEYWORDS([option])dnl
166
167 AT_DATA([priv.gob], [[class A:B:C from G:Object {
168   private int x;
169 }
170 %{
171 TEST_WITNESS_C
172 %}
173 %h{
174 TEST_WITNESS_H
175 %}
176 %privateheader{
177 TEST_WITNESS_PRIVATE
178 %}
179 ]])
180 sed '/private int/d' priv.gob >nopriv.gob
181
182 rm -f *.c *.h
183 AT_CHECK([gob2 priv.gob --no-private-header])
184 AT_CHECK([grep '^TEST_WITNESS' a-b-c.c], [0], [TEST_WITNESS_C
185 TEST_WITNESS_PRIVATE
186 ])
187 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
188 ])
189 AT_CHECK([test ! -f a-b-c-private.h])
190
191 rm -f *.c *.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
194 TEST_WITNESS_PRIVATE
195 ])
196 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
197 ])
198 AT_CHECK([test ! -f a-b-c-private.h])
199
200 rm -f *.c *.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
203 TEST_WITNESS_PRIVATE
204 ])
205 AT_CHECK([grep '^TEST_WITNESS' a-b-c.h], [0], [TEST_WITNESS_H
206 ])
207 AT_CHECK([test ! -f a-b-c-private.h])
208
209 AT_CLEANUP
210
211 AT_SETUP([--file-sep option])
212 AT_KEYWORDS([option])dnl
213
214 AT_DATA([test.gob], [[class A:B:C from G:Object {
215 }
216 %{
217 TEST_WITNESS_C
218 %}
219 %h{
220 TEST_WITNESS_H
221 %}
222 %privateheader{
223 TEST_WITNESS_PRIVATE
224 %}
225 ]])
226
227 mkdir a; mkdir a/b
228 AT_CHECK([gob2 test.gob --file-sep=/])
229 AT_CHECK([grep '^TEST_WITNESS' a/b/c.c], [0], [TEST_WITNESS_C
230 TEST_WITNESS_PRIVATE
231 ])
232 AT_CHECK([grep '^TEST_WITNESS' a/b/c.h], [0], [TEST_WITNESS_H
233 ])
234
235 AT_CHECK([gob2 test.gob --always-private-header --file-sep=])
236 AT_CHECK([grep '^TEST_WITNESS' abc.c], [0], [TEST_WITNESS_C
237 ])
238 AT_CHECK([grep '^TEST_WITNESS' abc.h], [0], [TEST_WITNESS_H
239 ])
240 AT_CHECK([grep '^TEST_WITNESS' abcprivate.h], [0], [TEST_WITNESS_PRIVATE
241 ])
242
243 rm -f abc*
244 AT_CHECK([gob2 test.gob --file-sep])
245 AT_CHECK([grep '^TEST_WITNESS' abc.c], [0], [TEST_WITNESS_C
246 TEST_WITNESS_PRIVATE
247 ])
248 AT_CHECK([grep '^TEST_WITNESS' abc.h], [0], [TEST_WITNESS_H
249 ])
250
251 AT_CLEANUP
252
253 AT_SETUP([--output-dir option])
254 AT_KEYWORDS([option])dnl
255
256 AT_DATA([test.gob], [[class A:B:C from G:Object {
257 }
258 %{
259 TEST_WITNESS_C
260 %}
261 %h{
262 TEST_WITNESS_H
263 %}
264 ]])
265
266 mkdir output-dir o
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
269 ])
270 AT_CHECK([grep '^TEST_WITNESS' output-dir/a-b-c.h], [0], [TEST_WITNESS_H
271 ])
272
273 AT_CHECK([gob2 test.gob -o o])
274 AT_CHECK([grep '^TEST_WITNESS' o/a-b-c.c], [0], [TEST_WITNESS_C
275 ])
276 AT_CHECK([grep '^TEST_WITNESS' o/a-b-c.h], [0], [TEST_WITNESS_H
277 ])
278
279 AT_CLEANUP
280
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
287
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])
293 rm -f test.h
294
295 AT_DATA([test.gob], [[class :Test from G:Object
296 {
297   private int x;
298 }
299 ]])
300
301 AT_CHECK([gob2 test.gob])
302 touch test-c test-h test-private
303 TEST_MTIME_DELAY
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])
308
309 touch test-c test-h test-private
310 TEST_MTIME_DELAY
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])
316
317 cat >>test.gob <<'EOF'
318 %{
319 /* some code */
320 %}
321 EOF
322 touch test-c test-h test-private
323 TEST_MTIME_DELAY
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])
328
329 cat >>test.gob <<'EOF'
330 %h{
331 /* yonder comment */
332 %}
333 EOF
334 touch test-c test-h test-private
335 TEST_MTIME_DELAY
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])
341
342 cat >>test.gob <<'EOF'
343 %privateheader{
344 /* once more unto the breach */
345 %}
346 EOF
347 touch test-c test-h test-private
348 TEST_MTIME_DELAY
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])
354
355 AT_CLEANUP
356 ])
357
358 AT_SETUP([--no-write option])
359 AT_KEYWORDS([option])dnl
360
361 mkdir outdir
362 AT_DATA([outdir/test.gob], [[class :Test from G:Object
363 {
364   private int x;
365 }
366 ]])
367 AT_CHECK([cd outdir && ls -Al], [0], [stdout-nolog])
368 mv -f stdout expout
369
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])
372
373 AT_CHECK([cd outdir && gob2 test.gob && 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_CLEANUP
380
381 AT_SETUP([--no-extern-c option])
382 AT_KEYWORDS([option])dnl
383
384 AT_DATA([test.gob], [[class :Test from G:Object
385 {
386   private int x;
387 }
388 ]])
389
390 AT_CHECK([gob2 test.gob])
391 AT_CHECK([cat *.h | grep 'extern "C"'], [0], [extern "C" {
392 extern "C" {
393 ])
394
395 AT_CHECK([gob2 --no-extern-c test.gob])
396 AT_CHECK([cat *.h | grep 'extern "C"'], [1])
397
398 AT_CLEANUP
399
400 AT_SETUP([--no-gnu option])
401 AT_KEYWORDS([option])dnl
402
403 AT_DATA([test.gob], [[enum TEST_ENUM {
404   TEST_ENUM_A
405 } Test:Enum;
406
407 flags TEST_FLAGS {
408   TEST_FLAG_A
409 } Test:Flags;
410
411 error TEST_ERROR {
412   TEST_ERROR_A
413 } Test:Error;
414
415 class :Test from G:Object
416 {
417   private int x;
418 }
419 ]])
420
421 AT_CHECK([gob2 test.gob])
422 AT_CHECK([cat test*.h test.c | grep '_GNUC_' >/dev/null], [0])
423
424 AT_CHECK([gob2 --no-gnu test.gob])
425 AT_CHECK([cat test*.h test.c | grep '_GNUC_'], [1])
426
427 AT_CLEANUP
428
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
434
435 AT_DATA([test.gob], [[class :Test from G:Object
436 {
437   public void myfunction(self) { };
438 }
439 ]])
440
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])
445
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])
450
451 AT_CLEANUP
452
453 AT_SETUP([--no-lines option])
454 AT_KEYWORDS([option])dnl
455
456 AT_DATA([test.gob], [[class :Test from G:Object
457 {
458   public int foo(void) { return 42; }
459   private int x;
460 }
461 ]])
462
463 AT_CHECK([gob2 test.gob])
464 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line' >/dev/null])
465
466 AT_CHECK([gob2 --no-lines test.gob])
467 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line'], [1])
468
469 AT_CLEANUP
470
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
474
475 AT_DATA([test.gob], [[class :Test from G:Object
476 {
477 }
478 ]])
479
480 mkdir orig
481 AT_CHECK([gob2 --output-dir orig test.gob])
482 AT_CHECK([gob2 --no-kill-underscores test.gob])
483
484 cp -f orig/test.c expout
485 AT_CHECK([cat test.c], [0], [expout])
486
487 cp -f orig/test.h expout
488 AT_CHECK([cat test.h], [0], [expout])
489
490 AT_CLEANUP
491
492 AT_SETUP([--always-private-struct option])
493 AT_KEYWORDS([option])dnl
494
495 AT_DATA([test.gob], [[class :Test from G:Object
496 {
497   public int my_public_member;
498 }
499 ]])
500
501 AT_CHECK([gob2 test.gob])
502 AT_CHECK([sed -n '/my_public_member/,/^}/s/_priv/&/p' test.h])
503
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;
507 ])
508
509 AT_CLEANUP
510
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
516
517 AT_DATA([test.gob], [[class :Test from G:Object
518   (interface Gtk:Actionable)
519 {
520 }
521 ]])
522
523 AT_CHECK([gob2 test.gob])
524 AT_CHECK([sed -n \
525   's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
526   [GtkActionableIface
527 ])
528
529 AT_CHECK([gob2 --gtk3 test.gob])
530 AT_CHECK([sed -n \
531   's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
532   [GtkActionableInterface
533 ])
534
535 AT_CLEANUP
536
537 AT_SETUP([--m4-dir option])
538 AT_KEYWORDS([option])dnl
539 AT_CHECK_UNQUOTED([gob2 --m4-dir], [0], [$pkgdatadir/m4
540 ])
541 AT_CLEANUP
542
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
547
548 mkdir bin
549 AT_DATA([bin/m4], [[#!/bin/sh
550 test $][# != 0 && printf '%s\n' "$][*" >&2
551 cat <<'EOF'
552 class M4:Test from G:Object
553 {
554 }
555 EOF
556 ]])
557 chmod +x bin/m4
558
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])
563
564 rm -f m4-test.c m4-test.h
565 cat >experr <<EOF
566 $gob_m4_args --help I am trapped in a test case factory --
567 EOF
568 AT_CHECK([gob2 --m4 filename --help I am trapped in a test case factory --],
569   [0], [], [experr])
570 AT_CHECK([test -f m4-test.c])
571
572 AT_CLEANUP
573
574 dnl Check that the --m4 option shells out to m4 and passes through
575 dnl all remaining arguments without adding any additional arguments.
576 AT_SETUP([--m4-clean option])
577 AT_KEYWORDS([option])dnl
578
579 mkdir bin
580 AT_DATA([bin/m4], [[#!/bin/sh
581 test $][# != 0 && printf '%s\n' "$][*" >&2
582 cat <<'EOF'
583 class M4:Test from G:Object
584 {
585 }
586 EOF
587 ]])
588 chmod +x bin/m4
589
590 PATH=$PWD/bin${PATH:+":$PATH"}
591 AT_CHECK([gob2 --m4-clean filename], [0], [], [filename
592 ])
593 AT_CHECK([test -f m4-test.c])
594
595 rm -f m4-test.c m4-test.h
596 AT_CHECK(
597   [gob2 --m4-clean filename --help I am trapped in a test case factory --],
598   [0], [], [filename --help I am trapped in a test case factory --
599 ])
600 AT_CHECK([test -f m4-test.c])
601
602 AT_CLEANUP