]> git.draconx.ca Git - dxcommon.git/blob - tests/scripts.at
gen-options.awk: Add a more compact data representation.
[dxcommon.git] / tests / scripts.at
1 dnl Copyright © 2021-2023 Nick Bowler
2 dnl
3 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4 dnl This is free software: you are free to do what the fuck you want to.
5 dnl There is NO WARRANTY, to the extent permitted by law.
6
7 AT_BANNER([Script tests])
8
9 AT_SETUP([gen-options.awk])
10 AT_KEYWORDS([gen-options awk script scripts])
11
12 AT_DATA([options.def],
13 [[--option-only
14 --option-with-val (5)
15 --option-with-flagval (&x, 5)
16 --option-with-arg=ARG
17 some "text" goes here
18 --option-with-optional-arg[=OPTIONAL]
19
20 hello
21 -a, --option-with-sopt
22
23 -b, --option-with-sopt-and-arg=SOPTARG
24 -c, --option-with-sopt-and-optional-arg[=SOPTOPTIONAL]
25 --option-with-arg-and-val=ARGVAL (42)
26 --option-with-arg-and-flagval=ARGFLAGVAL (&a[1], 'x')
27 --option-with-optional-arg-and-val[=OPTIONALARGVAL] (54)
28 --option-with-optional-arg-and-flagval[=OPTIONALFLAGVAL] (0, 0)
29 --with-sopt
30 Here is a help string
31     that has a line randomly indented
32 # with a comment
33     @&t@
34 and a blank line
35 --with-arg=ARG
36 do stuff with ARG
37 --flagval
38 ]])
39
40 AT_CHECK([$AWK -f "$builddir/scripts/gen-options.awk" <options.def >options.h])
41
42 AT_DATA([context.h],
43 [[struct option { const char *name; int has_arg; int *flag; int val; };
44 int x, a[5];
45 ]])
46
47 # test 0: sanity test
48 AT_DATA([test0.c],
49 [[#include "context.h"
50 #include "options.h"
51
52 static const char sopts[] = SOPT_STRING;
53 static const struct option opts[] = { LOPTS_INITIALIZER, {0} };
54
55 int main(void)
56 {
57   return 0;
58 }
59 ]])
60 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [], [ignore])
61
62 # test 1: long option names and help text
63 AT_DATA([test1.c],
64 [[#include <stdio.h>
65 #include <stdlib.h>
66
67 #include "context.h"
68 #include "options.h"
69
70 static const struct option opts[] = { LOPTS_INITIALIZER };
71
72 int main(void)
73 {
74   unsigned i;
75
76   for (i = 0; i < sizeof opts / sizeof opts[0]; i++) {
77     struct lopt_help help = { "INVALID", "INVALID" };
78
79     if (!lopt_get_help(&opts[i], &help))
80       return EXIT_FAILURE;
81
82     printf("--%s", opts[i].name);
83     if (opts[i].has_arg)
84       printf("=%s", help.arg);
85     printf("\n%s", help.desc);
86     if (help.desc[0])
87       putchar('\n');
88   }
89
90   return 0;
91 }
92 ]])
93
94 # pick out interesting bits from the definitions file
95 sed -n '/^-/s/^.*--\([[^\= @<:@]]*\).*$/\1/p' options.def >options
96 sed -n '/^-/{
97   s/[[^=]]*\(=[[^@:>@ ]]*\).*$/\1/
98   s/^[[^=]].*//
99   s/^=//
100   p
101 }' options.def >argnames
102
103 AS_ECHO(["-"]) | sed -n '1s/^-.*//p
104 1,/^-/d
105 t clear
106 :clear
107 s/^-.*//p
108 t
109 s/^#.*//
110 s/^ *//
111 t next
112 :next
113 N
114 s/\n-.*//
115 t done
116 s/\n#.*//
117 s/\n */\n/g
118 t next
119 :done
120 s/"/\\\\"/g
121 s/[[^\n]][[^\n]]*/\\"&\\"/g
122 s/^\n*//
123 s/\n*$//
124 s/\n\n*/ /g
125 p
126 ' options.def - >helptext
127
128 exec 3<options 4<argnames 5<helptext 6>expout
129 while read opt <&3 && read arg <&4 && read help <&5; do
130   if test ${arg:+y}; then
131     AS_ECHO(["--$opt=$arg"]) >&6
132   else
133     AS_ECHO(["--$opt"]) >&6
134   fi
135   eval "set x $help"; shift
136   for arg
137   do
138     AS_ECHO(["$arg"]) >&6
139   done
140 done
141 exec 3<&- 4<&- 5<&- 6>&-
142
143 AT_CHECK([$CC -o test1$EXEEXT test1.c && ./test1$EXEEXT],
144   [0], [expout], [ignore])
145
146 # test 2: short option string
147 AT_DATA([test2.c],
148 [[#include <stdio.h>
149 #include <stdlib.h>
150
151 #include "context.h"
152 #include "options.h"
153
154 int main(void)
155 {
156   struct option lopts[] = {LOPTS_INITIALIZER};
157   unsigned i, j;
158
159   for (i = 0; i < sizeof SOPT_STRING - 1; i++) {
160     if (SOPT_STRING[i] != ':') {
161       for (j = 0; j < sizeof lopts / sizeof lopts[0]; j++) {
162         if (lopts[j].val == SOPT_STRING[i]) {
163           printf("--%s ", lopts[j].name);
164           break;
165         }
166       }
167     }
168     putchar(SOPT_STRING[i]);
169     if (SOPT_STRING[i+1] != ':')
170       putchar('\n');
171   }
172 }
173 ]])
174
175 sed -n '/^-/{
176   s/=.*/:/
177   s/[[@<:@]]/:/
178   s/^-\([[^-]]\)[[^:]]*/\1/p
179   s/^-.*//p
180 }' options.def >sopts
181
182 exec 3<options 4<sopts 5>expout
183 while read lopt <&3 && read sopt <&4; do
184   if test ${sopt:+y}; then
185     AS_ECHO(["--$lopt $sopt"]) >&5
186   fi
187 done
188 exec 3<&- 4<&- 5>&-
189
190 AT_CHECK([$CC -o test2$EXEEXT test2.c && ./test2$EXEEXT],
191   [0], [expout], [ignore])
192
193 # Check that all help strings are translatable
194 sed 's/\([[^\\]]\\\)" /\1\\n\\" /g' helptext >help-po
195 exec 3<options 4<argnames 5<help-po 6>expected.po
196 while read opt <&3 && read arg <&4 && read help <&5; do
197   if test ${arg:+y}; then
198     AS_ECHO(["msgctxt \"$opt\" msgid \"$arg\""]) >&6
199   fi
200   AS_ECHO(["msgctxt \"$opt\" msgid${help:+ }$help"]) >&6
201 done
202 exec 3<&- 4<&- 5<&- 6>&-
203
204 AT_CHECK([xgettext --keyword=PN_:1c,2 options.h
205   test -f messages.po || exit 77])
206
207 LC_ALL=C sort expected.po >expout
208 AT_CHECK([sed -n '/^msgctxt/{
209 t next
210 :next
211 N
212 s/\nmsgstr.*//
213 t done
214 s/\s*""//
215 s/\n/ /
216 t next
217 :done
218 p
219 }' messages.po | LC_ALL=C sort], [0], [expout])
220
221 AT_CLEANUP
222
223 AT_SETUP([gen-options.awk packed format])
224 AT_KEYWORDS([gen-options awk script scripts])
225
226 AT_DATA([test.c], [[#include <stdio.h>
227 struct option { const char *name; int has_arg; int *flag; int val; };
228
229 #include "options.h"
230
231 static unsigned opts[] = { LOPTS_PACKED_INITIALIZER };
232
233 int main(void)
234 {
235   unsigned i;
236   int x =
237 #if !LOPT_PACK_BITS
238   0
239 #elif LOPT_PACK_BITS <= 8
240   1
241 #elif LOPT_PACK_BITS <= 16
242   2
243 #elif LOPT_PACK_BITS <= 32
244   3
245 #else
246 #  error too big
247 #endif
248   ;
249   printf("%d\n", x);
250   for (i = 0; i < sizeof opts / sizeof opts[0]; i++) {
251     struct option o;
252
253     LOPT_UNPACK(o, opts[i]);
254     printf("--%s, %d, ", o.name, o.has_arg);
255     if (o.val > UCHAR_MAX)
256       printf("%d\n", o.val - UCHAR_MAX - 1);
257     else
258       printf("'%c'\n", o.val);
259   }
260 }
261 ]])
262
263 AT_DATA([single.dat],
264 [[--single-option
265 ]])
266 AT_CHECK([$AWK -f "$builddir/scripts/gen-options.awk" <single.dat >options.h])
267 AT_CHECK([$CC -o single$EXEEXT test.c && ./single$EXEEXT], [0],
268 [[0
269 --single-option, 0, 0
270 ]])
271
272 AT_DATA([16bit.dat],
273 [[-a, --the-first-option
274 -b, --the-second-option=ARG
275 -c, --the-third-option[=ARG]
276 -d, --the-fourth-option
277 ]])
278 AT_CHECK([$AWK -f "$builddir/scripts/gen-options.awk" <16bit.dat >options.h])
279 AT_CHECK([$CC -o 16bit$EXEEXT test.c && ./16bit$EXEEXT], [0],
280 [[2
281 --the-first-option, 0, 'a'
282 --the-second-option, 1, 'b'
283 --the-third-option, 2, 'c'
284 --the-fourth-option, 0, 'd'
285 ]])
286
287 AT_CLEANUP
288
289 AT_SETUP([gen-strtab.awk])
290 AT_KEYWORDS([gen-strtab awk script scripts])
291
292 AT_DATA([test.def],
293 [[
294 &a world
295 &b
296 hello world
297 &c
298 hello
299 world
300 &d world\n
301 &e
302 \\not a newline
303 &f
304 \not a newline
305 &g inline
306 continued
307 &h    no\
308 newline\
309 &i
310 \   leading whitespace
311 &j oneline
312 # with a comment
313 ]])
314
315 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test.def >test.h])
316
317 sed -n 's/^[[&]]\([[^ ]]*\).*/\1/p' test.def >identifiers
318
319 # test 0: sanity test
320 AT_DATA([test0.c],
321 [[#include "test.h"
322 #include <stdio.h>
323
324 int main(void)
325 {
326   printf("---\n");
327 ]])
328 exec 3<identifiers 4>>test0.c
329 while read ident <&3; do
330   AS_ECHO(['  printf("%s\n---\n", '"strtab+$ident);"]) >&4
331 done
332 AS_ECHO(['  return 0;']) >&4
333 AS_ECHO(['}']) >&4
334 exec 3<&- 4>&-
335
336 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [---
337 world
338 ---
339 hello world
340
341 ---
342 hello
343 world
344
345 ---
346 world
347
348 ---
349 \not a newline
350
351 ---
352
353 ot a newline
354
355 ---
356 inline
357 continued
358
359 ---
360 nonewline
361 ---
362    leading whitespace
363
364 ---
365 oneline
366 ---
367 ], [ignore])
368
369 AT_CLEANUP
370
371 AT_SETUP([gen-strtab.awk @nozero option])
372 AT_KEYWORDS([gen-strtab awk script scripts])
373
374 AT_DATA([test0.def],
375 [[&hello hello
376 ]])
377 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test0.def >test0.h])
378
379 AT_DATA([test1.def],
380 [[@nozero
381 &hello hello
382 ]])
383 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test1.def >test1.h])
384
385 AT_DATA([test.c],
386 [[#include <stdio.h>
387 #include HEADER
388 int main(void) { printf("%d %s\n", hello, strtab+hello); return 0; }
389 ]])
390 AT_CHECK([$CC -DHEADER='"test0.h"' -o test0$EXEEXT test.c && ./test0$EXEEXT],
391   [0], [[0 hello
392 ]])
393 AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c && ./test1$EXEEXT],
394   [0], [[1 hello
395 ]])
396
397 AT_CLEANUP
398
399 AT_SETUP([gen-strtab.awk l10n options])
400 AT_KEYWORDS([gen-strtab awk script scripts])
401
402 AT_DATA([l10n.sed], dnl (
403 [[/^#/b
404 s/.*N_(\([^)]*\)).*/\1/p
405 ]])
406
407 AT_DATA([test0.def],
408 [[&a hello world
409 &b world
410 &c goodbye
411 ]])
412 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test0.def >test0.h])
413 AT_CHECK([sed -n -f l10n.sed test0.h | LC_ALL=C sort], [0],
414 [["goodbye"
415 "hello world"
416 "world"
417 ]])
418
419 AT_DATA([test1.def],
420 [[&a hello world
421 &&b world
422 &&c goodbye
423 ]])
424 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test1.def >test1.h])
425 AT_CHECK([sed -n -f l10n.sed test1.h], [0],
426 [["hello world"
427 ]])
428
429 AT_DATA([test.c],
430 [[#include <stdio.h>
431 #include HEADER
432
433 int main(void)
434 {
435   printf("%s %s %s\n", strtab+a, strtab+b, strtab+c);
436   return 0;
437 }
438 ]])
439
440 AT_CHECK([$CC -DHEADER='"test0.h"' -o test0$EXEEXT test.c && ./test0$EXEEXT],
441   [0], [[hello world world goodbye
442 ]])
443
444 AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c && ./test1$EXEEXT],
445   [0], [[hello world world goodbye
446 ]])
447
448
449 AT_CLEANUP
450
451 AT_SETUP([gen-tree.awk])
452 AT_KEYWORDS([gen-tree awk script scripts])
453
454 AT_DATA([tree.def],
455 [[# comment
456 ROOT0
457   r0a, r0a_OFFSET
458     r0b, r0b_OFFSET
459       r0c
460     r0d
461   r0e, r0e_OFFSET
462     r0f
463     r0g
464 # comment
465 ROOT1
466   r1a, r1a_OFFSET
467     r1b, r1b_OFFSET
468       r1b
469       r1e
470       r1b
471   r1c, r1c_OFFSET
472     r1d, r1d_OFFSET
473       r1e
474       r1b
475       r1e
476 # comment
477 ]])
478
479 AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <tree.def >tree.h])
480
481 AT_DATA([test0.c],
482 [[#include "tree.h"
483 #include <stdio.h>
484
485 struct tree { unsigned id, subtree; };
486
487 static const struct tree tree0[] = {
488   ROOT0_INITIALIZER
489 };
490 static const struct tree tree1[] = {
491   ROOT1_INITIALIZER
492 };
493
494 void print_subtree(const struct tree *root, unsigned offset, int depth)
495 {
496   const struct tree *node;
497
498   for (node = &root[offset]; node->id; node++) {
499     printf("%*s%s", 2*depth, "", &tree_strtab[node->id]);
500     if (node->subtree) {
501       printf(", %s_OFFSET\n", &tree_strtab[node->id]);
502       print_subtree(root, node->subtree, depth+1);
503     } else {
504       putchar('\n');
505     }
506   }
507 }
508
509 int main(void)
510 {
511   printf("ROOT0\n");
512   print_subtree(tree0, 0, 1);
513   printf("ROOT1\n");
514   print_subtree(tree1, 0, 1);
515   return 0;
516 }
517 ]])
518 sed '/^#/d' tree.def >expout
519 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [expout])
520
521 AT_CLEANUP
522
523 # Test the gen-tree features that avoid creating string labels for nodes.
524 AT_SETUP([gen-tree.awk @nostrtab option])
525 AT_KEYWORDS([gen-tree awk script scripts])
526
527 AT_DATA([tree.def],
528 [[@nostrtab
529 ROOT
530  a 1, a_OFFSET
531   b 1
532   c 2
533  d 2, d_OFFSET
534   e 1
535   f 2
536 ]])
537 AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <tree.def >tree.h])
538
539 AT_DATA([test0.c],
540 [[float tree_strtab = 0;
541 #define a []
542 #define b []
543 #define c []
544 #define e []
545 #define f []
546 #include "tree.h"
547 #include <stdio.h>
548
549 static struct { int num, offset; } root[] = { ROOT_INITIALIZER };
550
551 int main(void)
552 {
553   unsigned i;
554   for (i = 0; i < sizeof root / sizeof root[0]; i++) {
555     printf("%d, %d\n", root[i].num, root[i].offset);
556   }
557 }
558 ]])
559
560 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0],
561 [[1, 3
562 2, 6
563 0, 0
564 1, 0
565 2, 0
566 0, 0
567 1, 0
568 2, 0
569 0, 0
570 ]])
571
572 AT_DATA([flat.def],
573 [[FLAT
574  a 1
575  b 2
576  c 3
577 @nostrtab
578 ]])
579 AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <flat.def >flat.h])
580
581 sed -e 's/tree\.h/flat.h/' -e 's/ROOT/FLAT/' test0.c >test1.c
582 AT_CHECK([$CC -o test1$EXEEXT test1.c && ./test1$EXEEXT], [0],
583 [[1, 0
584 2, 0
585 3, 0
586 0, 0
587 ]])
588
589 AT_CLEANUP
590
591 AT_SETUP([join.awk])
592 AT_KEYWORDS([join awk script scripts])
593
594 JOIN="$AWK -f $builddir/scripts/join.awk --"
595
596 AT_DATA([a],
597 [[1 a
598 3 a1 x
599 3 a2 x
600 5 a
601 6 a
602 8 a1 x
603 8 a2 x
604 9 a1
605 9 a2
606 9 a3
607 ]])
608
609 AT_DATA([b],
610 [[2 b
611 2 b
612 3 b y
613 4 b
614 6 b1 y
615 6 b2 y
616 7 b
617 8 b1 y
618 8 b2 y
619 ]])
620
621 AT_CHECK([$JOIN a b], [0],
622 [[3 a1 x b y
623 3 a2 x b y
624 6 a b1 y
625 6 a b2 y
626 8 a1 x b1 y
627 8 a1 x b2 y
628 8 a2 x b1 y
629 8 a2 x b2 y
630 ]])
631
632 AT_CHECK([$JOIN -v1 a b], [0],
633 [[1 a
634 5 a
635 9 a1
636 9 a2
637 9 a3
638 ]])
639
640 AT_CHECK([$JOIN -v2 a b], [0],
641 [[2 b
642 2 b
643 4 b
644 7 b
645 ]])
646
647 AT_CHECK([$JOIN -v1 -v2 a b], [0],
648 [[1 a
649 2 b
650 2 b
651 4 b
652 5 a
653 7 b
654 9 a1
655 9 a2
656 9 a3
657 ]])
658
659 AT_CHECK([$JOIN -a1 a b], [0],
660 [[1 a
661 3 a1 x b y
662 3 a2 x b y
663 5 a
664 6 a b1 y
665 6 a b2 y
666 8 a1 x b1 y
667 8 a1 x b2 y
668 8 a2 x b1 y
669 8 a2 x b2 y
670 9 a1
671 9 a2
672 9 a3
673 ]])
674
675 AT_CHECK([$JOIN -a2 a b], [0],
676 [[2 b
677 2 b
678 3 a1 x b y
679 3 a2 x b y
680 4 b
681 6 a b1 y
682 6 a b2 y
683 7 b
684 8 a1 x b1 y
685 8 a1 x b2 y
686 8 a2 x b1 y
687 8 a2 x b2 y
688 ]])
689
690 AT_CHECK([$JOIN -a1 -a2 a b], [0],
691 [[1 a
692 2 b
693 2 b
694 3 a1 x b y
695 3 a2 x b y
696 4 b
697 5 a
698 6 a b1 y
699 6 a b2 y
700 7 b
701 8 a1 x b1 y
702 8 a1 x b2 y
703 8 a2 x b1 y
704 8 a2 x b2 y
705 9 a1
706 9 a2
707 9 a3
708 ]])
709
710 AT_CHECK([$JOIN b a], [0],
711 [[3 b y a1 x
712 3 b y a2 x
713 6 b1 y a
714 6 b2 y a
715 8 b1 y a1 x
716 8 b1 y a2 x
717 8 b2 y a1 x
718 8 b2 y a2 x
719 ]])
720
721 AT_CHECK([$JOIN -v1 b a], [0],
722 [[2 b
723 2 b
724 4 b
725 7 b
726 ]])
727
728 AT_CHECK([$JOIN -v2 b a], [0],
729 [[1 a
730 5 a
731 9 a1
732 9 a2
733 9 a3
734 ]])
735
736 AT_CHECK([$JOIN -v1 -v2 b a], [0],
737 [[1 a
738 2 b
739 2 b
740 4 b
741 5 a
742 7 b
743 9 a1
744 9 a2
745 9 a3
746 ]])
747
748 AT_CHECK([$JOIN -a1 b a], [0],
749 [[2 b
750 2 b
751 3 b y a1 x
752 3 b y a2 x
753 4 b
754 6 b1 y a
755 6 b2 y a
756 7 b
757 8 b1 y a1 x
758 8 b1 y a2 x
759 8 b2 y a1 x
760 8 b2 y a2 x
761 ]])
762
763 AT_CHECK([$JOIN -a2 b a], [0],
764 [[1 a
765 3 b y a1 x
766 3 b y a2 x
767 5 a
768 6 b1 y a
769 6 b2 y a
770 8 b1 y a1 x
771 8 b1 y a2 x
772 8 b2 y a1 x
773 8 b2 y a2 x
774 9 a1
775 9 a2
776 9 a3
777 ]])
778
779 AT_CHECK([$JOIN -a1 -a2 b a], [0],
780 [[1 a
781 2 b
782 2 b
783 3 b y a1 x
784 3 b y a2 x
785 4 b
786 5 a
787 6 b1 y a
788 6 b2 y a
789 7 b
790 8 b1 y a1 x
791 8 b1 y a2 x
792 8 b2 y a1 x
793 8 b2 y a2 x
794 9 a1
795 9 a2
796 9 a3
797 ]])
798
799 AT_CHECK([echo wat | $JOIN -v1 - /dev/null], [0],
800 [[wat
801 ]])
802
803 AT_CLEANUP
804
805 m4_divert_push([PREPARE_TESTS])dnl
806 test_fix_ltdl () {
807   $PERL -e 'my $x = 42; exit $x;'; test $? = 42 || exit 77
808   $PERL -f "$srcdir/scripts/fix-ltdl.pl" "$@"
809 }
810 test_fix_gnulib () {
811   $PERL -e 'my $x = 42; exit $x;'; test $? = 42 || exit 77
812   $PERL -f "$srcdir/scripts/fix-gnulib.pl" "$@"
813 }
814 test_gnulib_mk () {
815   echo;
816   for arg
817   do
818     sed -n -f - "$srcdir/tests/data/gnulib.mk" <<EOF
819 /^## begin gnulib module $arg/,/^## end   gnulib module $arg/p
820 EOF
821   done
822 }
823 m4_divert_pop([PREPARE_TESTS])
824
825 AT_SETUP([fix-gnulib.pl SED_HEADER variables])
826
827 test_gnulib_mk gen-header >test.mk.in
828 AT_CHECK([grep SED_HEADER test.mk.in >expout || exit 99])
829 AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
830 grep SED_HEADER test.mk], [0], [expout])
831
832 AT_CLEANUP
833
834 AT_SETUP([fix-gnulib.pl %reldir% substitution])
835
836 test_gnulib_mk sys_types >test.mk.in
837 AT_CHECK([grep '%reldir%' test.mk.in >/dev/null || exit 99])
838
839 sed -n -f - test.mk.in >expout <<'EOF'
840 ${G;p;b}
841 /^## begin gnulib/,/^## end   gnulib/!b
842 /^#/{p;b}
843 s|(srcdir)|(top_srcdir)|
844 s|%reldir%|lib|
845 s|BUILT_SOURCES|gnulib_core_headers|
846 s|sys[[/_]]|lib/&|g
847 /^MOSTLYCLEANFILES/{h;b}
848 p
849 EOF
850
851 AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
852 sed -n -e '/^## begin gnulib/,/^## end   gnulib/p' \
853        -e '/CLEANFILES/p' test.mk],
854 [0], [expout])
855
856 AT_CLEANUP
857
858 AT_SETUP([fix-gnulib.pl warning removal])
859
860 AT_DATA([test.mk.in], [[
861 ## test begin
862 noinst_LTLIBRARIES += libgnu.la
863 libgnu_la_CFLAGS = $(AM_CFLAGS) $(GL_CFLAG_GNULIB_WARNINGS)
864 noinst_LIBRARIES += libgnu.a
865 libgnu_a_CFLAGS = $(AM_CFLAGS) $(GL_CFLAG_GNULIB_WARNINGS)
866 ## test end
867 ]])
868 AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
869 sed -n '/^## test begin/,/^## test end/p' test.mk], [0], [## test begin
870 EXTRA_LTLIBRARIES += libgnu.la
871 EXTRA_LIBRARIES += libgnu.a
872 ## test end
873 ])
874
875 AT_CLEANUP
876
877 AT_SETUP([fix-gnulib.pl header directory creation])
878
879 AT_DATA([extract.sed],
880 [[/AM_V_GEN/b ok
881 /gl_V_at/b ok
882 s/:.*/:/
883 h
884 b
885 :ok
886 s/'//g
887 x
888 G
889 p
890 n
891 s/[)].*/)/
892 p
893 ]])
894
895 test_gnulib_mk alloca-opt sys_types stddef >test.mk.in
896 AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
897 sed -n -f extract.sed test.mk], [0],
898 [[lib/alloca.h:
899         $(AM_V_GEN)$(MKDIR_P) lib
900         $(AM_V_at)
901 lib/sys/types.h:
902         $(AM_V_GEN)$(MKDIR_P) lib/sys
903         $(AM_V_at)
904 lib/stddef.h:
905         $(AM_V_GEN)$(MKDIR_P) lib
906         $(AM_V_at)
907 ]])
908
909 AT_CLEANUP
910
911 dnl TEST_FIND_AUTOMAKE_VER([to-check], [test-action])
912 dnl
913 dnl For each whitespace-separated version token in to-check, check if we can
914 dnl run the programs automake-VER and aclocal-VER.  The special token 'default'
915 dnl also checks the unversioned automake and aclocal (or, if set in the
916 dnl environment, $AUTOMAKE and $ACLOCAL).
917 dnl
918 dnl Then test-action is expanded such that shell variables $ac and $am refer to
919 dnl the aclocal and automake programs, and $amver is the actual version
920 dnl reported by --version.  The action should do nothing if the version is
921 dnl acceptable, or "continue" if the version is unacceptable.
922 dnl
923 dnl If an acceptable version is found, the AUTOMAKE and ACLOCAL environment
924 dnl variables are set accordingly.  Otherwise, the test group is skipped.
925 m4_define([TEST_FIND_AUTOMAKE],
926 [have_am=false
927 for am in $1; do
928   AS_CASE([$am],
929     [default], [ac=${ACLOCAL-aclocal} am=${AUTOMAKE-automake}],
930     [ac=aclocal-$am; am=automake-$am])
931   amver=`$am --version | sed -n '1s/.* //p'`
932   acver=`$ac --version | sed -n '1s/.* //p'`
933   set x $amver $acver; shift; test x"$[]#" = x"2" || continue
934   test x"$amver" = x"$acver" || continue
935   $2
936   have_am=:; break
937 done
938 AT_CHECK([$have_am || exit 77])
939 AUTOMAKE=$am; export AUTOMAKE
940 ACLOCAL=$ac; export ACLOCAL
941 AT_CHECK([$ACLOCAL --version && $AUTOMAKE --version], [0], [stdout])
942 ])
943
944 m4_define([TEST_LTDL_LIBOBJ_MANGLING],
945 [TEST_CONFIGURE_AC([[AM_INIT_AUTOMAKE([foreign subdir-objects])
946 AC_PROG_CC
947 LT_INIT
948 AC_SUBST([ltdl_LTLIBOBJS], [libltdl/test.lo])
949 AC_CONFIG_FILES([Makefile])
950 ]])
951
952 mkdir libltdl
953 AT_DATA([ltdl.mk.in], [[
954 AM_CPPFLAGS += -DSTRING=\"helloworld\"
955
956 noinst_LTLIBRARIES = libltdl/libltdl.la
957 libltdl_libltdl_la_SOURCES = libltdl/ltdl.c
958 libltdl_libltdl_la_LIBADD = $(ltdl_LTLIBOBJS)
959 libltdl_libltdl_la_DEPENDENCIES = $(ltdl_LTLIBOBJS)
960
961 EXTRA_DIST += libltdl/test.c
962 ]])
963 AT_DATA([Makefile.am], [[AM_CPPFLAGS =
964 include $(top_srcdir)/ltdl.mk
965 AM_LIBTOOLFLAGS = --quiet
966 bin_PROGRAMS = test
967 test_SOURCES =
968 test_LDADD = libltdl/libltdl.la
969 all-local: ; @printf '%s\n' $(AM_CPPFLAGS)
970 ]])
971 AT_DATA([libltdl/test.c], [[#include <stdio.h>
972 int foo(void) { printf("%s\n", STRING); return 0; }
973 ]])
974 AT_DATA([libltdl/ltdl.c], [[int foo(void); int main(void) { return foo(); }
975 ]])
976
977 AT_CHECK([test_fix_ltdl -i ltdl.mk.in -o ltdl.mk])
978 libtoolize; TEST_AUTORECONF
979 TEST_CONFIGURE([--disable-shared])
980 AT_CHECK([make -s && ./test], [0], [
981 helloworld
982 ])])
983
984 AT_SETUP([fix-ltdl.pl LIBOBJ mangling (<automake-1.16)])
985
986 TEST_FIND_AUTOMAKE([default 1.10 1.11 1.12 1.13 1.14 1.15],
987   [AS_VERSION_COMPARE(["$amver"], [1.16], [], [continue], [continue])])
988 TEST_LTDL_LIBOBJ_MANGLING
989
990 AT_CLEANUP
991
992 AT_SETUP([fix-ltdl.pl LIBOBJ mangling (>=automake-1.16)])
993
994 TEST_FIND_AUTOMAKE([default 1.16 1.17 1.18 1.19],
995   [AS_VERSION_COMPARE(["$amver"], [1.16], [continue])])
996 TEST_LTDL_LIBOBJ_MANGLING
997
998 AT_CLEANUP