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