]> git.draconx.ca Git - gob-dx.git/blob - tests/options.at
Improve --version output.
[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 m4_if(OPTION, [--no-touch-headers],
302 [#Currently, the private header is modified even with --no-touch-headers.
303 AT_XFAIL_IF([:])])dnl
304
305 AT_CHECK([gob2 test.gob])
306 touch test-c test-h test-private
307 TEST_MTIME_DELAY
308 AT_CHECK([gob2 test.gob])
309 AT_CHECK([mtime_uptodate test-c test.c], [1])
310 AT_CHECK([mtime_uptodate test-h test.h], [1])
311 AT_CHECK([mtime_uptodate test-private test-private.h], [1])
312
313 touch test-c test-h test-private
314 TEST_MTIME_DELAY
315 AT_CHECK([gob2 test.gob OPTION])
316 AT_CHECK([mtime_uptodate test-c test.c],
317   m4_if(OPTION, [--no-touch], [0], [1]))
318 AT_CHECK([mtime_uptodate test-h test.h], [0])
319 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
320
321 cat >>test.gob <<'EOF'
322 %{
323 /* some code */
324 %}
325 EOF
326 touch test-c test-h test-private
327 TEST_MTIME_DELAY
328 AT_CHECK([gob2 test.gob OPTION])
329 AT_CHECK([mtime_uptodate test-c test.c], [1])
330 AT_CHECK([mtime_uptodate test-h test.h], [0])
331 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
332
333 cat >>test.gob <<'EOF'
334 %h{
335 /* yonder comment */
336 %}
337 EOF
338 touch test-c test-h test-private
339 TEST_MTIME_DELAY
340 AT_CHECK([gob2 test.gob OPTION])
341 AT_CHECK([mtime_uptodate test-c test.c],
342   m4_if(OPTION, [--no-touch], [0], [1]))
343 AT_CHECK([mtime_uptodate test-h test.h], [1])
344 AT_CHECK([mtime_uptodate test-private test-private.h], [0])
345
346 cat >>test.gob <<'EOF'
347 %privateheader{
348 /* once more unto the breach */
349 %}
350 EOF
351 touch test-c test-h test-private
352 TEST_MTIME_DELAY
353 AT_CHECK([gob2 test.gob OPTION])
354 AT_CHECK([mtime_uptodate test-c test.c],
355   m4_if(OPTION, [--no-touch], [0], [1]))
356 AT_CHECK([mtime_uptodate test-h test.h], [0])
357 AT_CHECK([mtime_uptodate test-private test-private.h], [1])
358
359 AT_CLEANUP
360 ])
361
362 AT_SETUP([--no-write option])
363 AT_KEYWORDS([option])dnl
364
365 mkdir outdir
366 AT_DATA([outdir/test.gob], [[class :Test from G:Object
367 {
368   private int x;
369 }
370 ]])
371 AT_CHECK([cd outdir && ls -Al], [0], [stdout-nolog])
372 mv -f stdout expout
373
374 AT_CHECK([cd outdir && gob2 test.gob --no-write && ls -Al], [0], [expout])
375 AT_CHECK([cd outdir && gob2 test.gob -n && ls -Al], [0], [expout])
376
377 AT_CHECK([cd outdir && gob2 test.gob && ls -Al], [0], [stdout-nolog])
378 mv -f stdout expout
379
380 AT_CHECK([cd outdir && gob2 test.gob --no-write && ls -Al], [0], [expout])
381 AT_CHECK([cd outdir && gob2 test.gob -n && ls -Al], [0], [expout])
382
383 AT_CLEANUP
384
385 AT_SETUP([--no-extern-c option])
386 AT_KEYWORDS([option])dnl
387
388 AT_DATA([test.gob], [[class :Test from G:Object
389 {
390   private int x;
391 }
392 ]])
393
394 AT_CHECK([gob2 test.gob])
395 AT_CHECK([cat *.h | grep 'extern "C"'], [0], [extern "C" {
396 extern "C" {
397 ])
398
399 AT_CHECK([gob2 --no-extern-c test.gob])
400 AT_CHECK([cat *.h | grep 'extern "C"'], [1])
401
402 AT_CLEANUP
403
404 AT_SETUP([--no-gnu option])
405 AT_KEYWORDS([option])dnl
406
407 AT_DATA([test.gob], [[enum TEST_ENUM {
408   TEST_ENUM_A
409 } Test:Enum;
410
411 flags TEST_FLAGS {
412   TEST_FLAG_A
413 } Test:Flags;
414
415 error TEST_ERROR {
416   TEST_ERROR_A
417 } Test:Error;
418
419 class :Test from G:Object
420 {
421   private int x;
422 }
423 ]])
424
425 # --no-gnu is currently busted for the get_type function declaration.
426 AT_XFAIL_IF([:])
427
428 AT_CHECK([gob2 test.gob])
429 AT_CHECK([cat test*.h test.c | grep '_GNUC_' >/dev/null], [0])
430
431 AT_CHECK([gob2 --no-gnu test.gob])
432 AT_CHECK([cat test*.h test.c | grep '_GNUC_'], [1])
433
434 AT_CLEANUP
435
436 dnl Check that --no-self-alias works as documented.  The self_xxx method
437 dnl aliases are not documented to be affected by this option, so check that
438 dnl they are unaffected.
439 AT_SETUP([--no-self-alias option])
440 AT_KEYWORDS([option])dnl
441
442 AT_DATA([test.gob], [[class :Test from G:Object
443 {
444   public void myfunction(self) { };
445 }
446 ]])
447
448 AT_CHECK([gob2 test.gob])
449 AT_CHECK([:; { grep '#define.*SELF' test.c &&
450 grep 'typedef.*Self' test.c &&
451 grep '#define.*self_myfunction' test.c; } >/dev/null], [0])
452
453 AT_CHECK([gob2 --no-self-alias test.gob])
454 AT_CHECK([grep '#.*define.*SELF' test.c], [1])
455 AT_CHECK([grep 'typedef.*Self' test.c], [1])
456 AT_CHECK([grep '#define.*self_myfunction' test.c >/dev/null], [0])
457
458 AT_CLEANUP
459
460 AT_SETUP([--no-lines option])
461 AT_KEYWORDS([option])dnl
462
463 AT_DATA([test.gob], [[class :Test from G:Object
464 {
465   public int foo(void) { return 42; }
466   private int x;
467 }
468 ]])
469
470 AT_CHECK([gob2 test.gob])
471 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line' >/dev/null])
472
473 AT_CHECK([gob2 --no-lines test.gob])
474 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line'], [1])
475
476 AT_CLEANUP
477
478 dnl Check that the --no-kill-underscores option is ignored for compatibility.
479 AT_SETUP([--no-kill-underscores option])
480 AT_KEYWORDS([option])dnl
481
482 AT_DATA([test.gob], [[class :Test from G:Object
483 {
484 }
485 ]])
486
487 mkdir orig
488 AT_CHECK([gob2 --output-dir orig test.gob])
489 AT_CHECK([gob2 --no-kill-underscores test.gob])
490
491 cp -f orig/test.c expout
492 AT_CHECK([cat test.c], [0], [expout])
493
494 cp -f orig/test.h expout
495 AT_CHECK([cat test.h], [0], [expout])
496
497 AT_CLEANUP
498
499 AT_SETUP([--always-private-struct option])
500 AT_KEYWORDS([option])dnl
501
502 AT_DATA([test.gob], [[class :Test from G:Object
503 {
504   public int my_public_member;
505 }
506 ]])
507
508 AT_CHECK([gob2 test.gob])
509 AT_CHECK([sed -n '/my_public_member/,/^}/s/_priv/&/p' test.h])
510
511 AT_CHECK([gob2 --always-private-struct test.gob])
512 AT_CHECK([sed -n '/my_public_member/,/^}/s/[[   ]]*\(.*_priv;\)/\1/p' test.h],
513   [0], [TestPrivate *_priv;
514 ])
515
516 AT_CLEANUP
517
518 dnl Check the --gtk3 option.  The only effect of this option seems to be to
519 dnl change the normal "Iface" suffix on interface types to "Interface".  So
520 dnl let's make sure that behaviour is tested.
521 AT_SETUP([--gtk3 option])
522 AT_KEYWORDS([option])dnl
523
524 AT_DATA([test.gob], [[class :Test from G:Object
525   (interface Gtk:Actionable)
526 {
527 }
528 ]])
529
530 AT_CHECK([gob2 test.gob])
531 AT_CHECK([sed -n \
532   's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
533   [GtkActionableIface
534 ])
535
536 AT_CHECK([gob2 --gtk3 test.gob])
537 AT_CHECK([sed -n \
538   's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
539   [GtkActionableInterface
540 ])
541
542 AT_CLEANUP
543
544 AT_SETUP([--m4-dir option])
545 AT_KEYWORDS([option])dnl
546 AT_CHECK_UNQUOTED([gob2 --m4-dir], [0], [$pkgdatadir/m4
547 ])
548 AT_CLEANUP
549
550 dnl Check that the --m4 option shells out to m4 and passes through
551 dnl all remaining arguments.
552 AT_SETUP([--m4 option])
553 AT_KEYWORDS([option])dnl
554
555 mkdir bin
556 AT_DATA([bin/m4], [[#!/bin/sh
557 test $][# != 0 && printf '%s\n' "$][*" >&2
558 cat <<'EOF'
559 class M4:Test from G:Object
560 {
561 }
562 EOF
563 ]])
564 chmod +x bin/m4
565
566 PATH=$PWD/bin${PATH:+":$PATH"}
567 AT_CHECK([gob2 --m4 filename], [0], [], [stderr])
568 read gob_m4_args <stderr
569 AT_CHECK([test -f m4-test.c])
570
571 rm -f m4-test.c m4-test.h
572 cat >experr <<EOF
573 $gob_m4_args --help I am trapped in a test case factory --
574 EOF
575 AT_CHECK([gob2 --m4 filename --help I am trapped in a test case factory --],
576   [0], [], [experr])
577 AT_CHECK([test -f m4-test.c])
578
579 AT_CLEANUP
580
581 dnl Check that the --m4 option shells out to m4 and passes through
582 dnl all remaining arguments without adding any additional arguments.
583 AT_SETUP([--m4-clean option])
584 AT_KEYWORDS([option])dnl
585
586 mkdir bin
587 AT_DATA([bin/m4], [[#!/bin/sh
588 test $][# != 0 && printf '%s\n' "$][*" >&2
589 cat <<'EOF'
590 class M4:Test from G:Object
591 {
592 }
593 EOF
594 ]])
595 chmod +x bin/m4
596
597 PATH=$PWD/bin${PATH:+":$PATH"}
598 AT_CHECK([gob2 --m4-clean filename], [0], [], [filename
599 ])
600 AT_CHECK([test -f m4-test.c])
601
602 rm -f m4-test.c m4-test.h
603 AT_CHECK(
604   [gob2 --m4-clean filename --help I am trapped in a test case factory --],
605   [0], [], [filename --help I am trapped in a test case factory --
606 ])
607 AT_CHECK([test -f m4-test.c])
608
609 AT_CLEANUP