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