]> git.draconx.ca Git - gob-dx.git/blob - tests/options.at
Expand --no-touch-headers to include the private header.
[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 # --no-gnu is currently busted for the get_type function declaration.
422 AT_XFAIL_IF([:])
423
424 AT_CHECK([gob2 test.gob])
425 AT_CHECK([cat test*.h test.c | grep '_GNUC_' >/dev/null], [0])
426
427 AT_CHECK([gob2 --no-gnu test.gob])
428 AT_CHECK([cat test*.h test.c | grep '_GNUC_'], [1])
429
430 AT_CLEANUP
431
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
437
438 AT_DATA([test.gob], [[class :Test from G:Object
439 {
440   public void myfunction(self) { };
441 }
442 ]])
443
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])
448
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])
453
454 AT_CLEANUP
455
456 AT_SETUP([--no-lines option])
457 AT_KEYWORDS([option])dnl
458
459 AT_DATA([test.gob], [[class :Test from G:Object
460 {
461   public int foo(void) { return 42; }
462   private int x;
463 }
464 ]])
465
466 AT_CHECK([gob2 test.gob])
467 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line' >/dev/null])
468
469 AT_CHECK([gob2 --no-lines test.gob])
470 AT_CHECK([cat test.h test-private.h test.c | grep '#.*line'], [1])
471
472 AT_CLEANUP
473
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
477
478 AT_DATA([test.gob], [[class :Test from G:Object
479 {
480 }
481 ]])
482
483 mkdir orig
484 AT_CHECK([gob2 --output-dir orig test.gob])
485 AT_CHECK([gob2 --no-kill-underscores test.gob])
486
487 cp -f orig/test.c expout
488 AT_CHECK([cat test.c], [0], [expout])
489
490 cp -f orig/test.h expout
491 AT_CHECK([cat test.h], [0], [expout])
492
493 AT_CLEANUP
494
495 AT_SETUP([--always-private-struct option])
496 AT_KEYWORDS([option])dnl
497
498 AT_DATA([test.gob], [[class :Test from G:Object
499 {
500   public int my_public_member;
501 }
502 ]])
503
504 AT_CHECK([gob2 test.gob])
505 AT_CHECK([sed -n '/my_public_member/,/^}/s/_priv/&/p' test.h])
506
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;
510 ])
511
512 AT_CLEANUP
513
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
519
520 AT_DATA([test.gob], [[class :Test from G:Object
521   (interface Gtk:Actionable)
522 {
523 }
524 ]])
525
526 AT_CHECK([gob2 test.gob])
527 AT_CHECK([sed -n \
528   's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
529   [GtkActionableIface
530 ])
531
532 AT_CHECK([gob2 --gtk3 test.gob])
533 AT_CHECK([sed -n \
534   's/.*Gtk_Actionable_init.*\(GtkActionable[[^ *]]*\).*/\1/p' test.c], [0],
535   [GtkActionableInterface
536 ])
537
538 AT_CLEANUP
539
540 AT_SETUP([--m4-dir option])
541 AT_KEYWORDS([option])dnl
542 AT_CHECK_UNQUOTED([gob2 --m4-dir], [0], [$pkgdatadir/m4
543 ])
544 AT_CLEANUP
545
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
550
551 mkdir bin
552 AT_DATA([bin/m4], [[#!/bin/sh
553 test $][# != 0 && printf '%s\n' "$][*" >&2
554 cat <<'EOF'
555 class M4:Test from G:Object
556 {
557 }
558 EOF
559 ]])
560 chmod +x bin/m4
561
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])
566
567 rm -f m4-test.c m4-test.h
568 cat >experr <<EOF
569 $gob_m4_args --help I am trapped in a test case factory --
570 EOF
571 AT_CHECK([gob2 --m4 filename --help I am trapped in a test case factory --],
572   [0], [], [experr])
573 AT_CHECK([test -f m4-test.c])
574
575 AT_CLEANUP
576
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
581
582 mkdir bin
583 AT_DATA([bin/m4], [[#!/bin/sh
584 test $][# != 0 && printf '%s\n' "$][*" >&2
585 cat <<'EOF'
586 class M4:Test from G:Object
587 {
588 }
589 EOF
590 ]])
591 chmod +x bin/m4
592
593 PATH=$PWD/bin${PATH:+":$PATH"}
594 AT_CHECK([gob2 --m4-clean filename], [0], [], [filename
595 ])
596 AT_CHECK([test -f m4-test.c])
597
598 rm -f m4-test.c m4-test.h
599 AT_CHECK(
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 --
602 ])
603 AT_CHECK([test -f m4-test.c])
604
605 AT_CLEANUP