]> git.draconx.ca Git - dxcommon.git/blob - tests/scripts.at
gen-strtab.awk: Add an option to suppress object definitions.
[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 @macro option])
405 AT_KEYWORDS([gen-strtab awk script scripts])
406
407 AT_DATA([test0.def],
408 [[@macro
409 &foo foobar
410 &bar bar
411 &baz baz
412 ]])
413 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test0.def >test0.h])
414
415 AT_DATA([test0.c],
416 [[#include <stdio.h>
417 extern const char strtab[];
418 #include "test0.h"
419
420 int main(void)
421 {
422   static const char mystrtab[] = STRTAB_INITIALIZER;
423   printf("%s\n%s\n%s\n", mystrtab+foo, mystrtab+bar, mystrtab+baz);
424   return 0;
425 }
426 ]])
427 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0],
428 [[foobar
429 bar
430 baz
431 ]])
432
433 AT_CLEANUP
434
435 AT_SETUP([gen-strtab.awk l10n options])
436 AT_KEYWORDS([gen-strtab awk script scripts])
437
438 AT_DATA([l10n.sed], dnl (
439 [[/^#/b
440 s/.*N_(\([^)]*\)).*/\1/p
441 ]])
442
443 AT_DATA([test0.def],
444 [[&a hello world
445 &b world
446 &c goodbye
447 ]])
448 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test0.def >test0.h])
449 AT_CHECK([sed -n -f l10n.sed test0.h | LC_ALL=C sort], [0],
450 [["goodbye"
451 "hello world"
452 "world"
453 ]])
454
455 AT_DATA([test1.def],
456 [[&a hello world
457 &&b world
458 &&c goodbye
459 ]])
460 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test1.def >test1.h])
461 AT_CHECK([sed -n -f l10n.sed test1.h], [0],
462 [["hello world"
463 ]])
464
465 AT_DATA([test.c],
466 [[#include <stdio.h>
467 #include HEADER
468
469 int main(void)
470 {
471   printf("%s %s %s\n", strtab+a, strtab+b, strtab+c);
472   return 0;
473 }
474 ]])
475
476 AT_CHECK([$CC -DHEADER='"test0.h"' -o test0$EXEEXT test.c && ./test0$EXEEXT],
477   [0], [[hello world world goodbye
478 ]])
479
480 AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c && ./test1$EXEEXT],
481   [0], [[hello world world goodbye
482 ]])
483
484
485 AT_CLEANUP
486
487 AT_SETUP([gen-tree.awk])
488 AT_KEYWORDS([gen-tree awk script scripts])
489
490 AT_DATA([tree.def],
491 [[# comment
492 ROOT0
493   r0a, r0a_OFFSET
494     r0b, r0b_OFFSET
495       r0c
496     r0d
497   r0e, r0e_OFFSET
498     r0f
499     r0g
500 # comment
501 ROOT1
502   r1a, r1a_OFFSET
503     r1b, r1b_OFFSET
504       r1b
505       r1e
506       r1b
507   r1c, r1c_OFFSET
508     r1d, r1d_OFFSET
509       r1e
510       r1b
511       r1e
512 # comment
513 ]])
514
515 AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <tree.def >tree.h])
516
517 AT_DATA([test0.c],
518 [[#include "tree.h"
519 #include <stdio.h>
520
521 struct tree { unsigned id, subtree; };
522
523 static const struct tree tree0[] = {
524   ROOT0_INITIALIZER
525 };
526 static const struct tree tree1[] = {
527   ROOT1_INITIALIZER
528 };
529
530 void print_subtree(const struct tree *root, unsigned offset, int depth)
531 {
532   const struct tree *node;
533
534   for (node = &root[offset]; node->id; node++) {
535     printf("%*s%s", 2*depth, "", &tree_strtab[node->id]);
536     if (node->subtree) {
537       printf(", %s_OFFSET\n", &tree_strtab[node->id]);
538       print_subtree(root, node->subtree, depth+1);
539     } else {
540       putchar('\n');
541     }
542   }
543 }
544
545 int main(void)
546 {
547   printf("ROOT0\n");
548   print_subtree(tree0, 0, 1);
549   printf("ROOT1\n");
550   print_subtree(tree1, 0, 1);
551   return 0;
552 }
553 ]])
554 sed '/^#/d' tree.def >expout
555 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [expout])
556
557 AT_CLEANUP
558
559 # Test the gen-tree features that avoid creating string labels for nodes.
560 AT_SETUP([gen-tree.awk @nostrtab option])
561 AT_KEYWORDS([gen-tree awk script scripts])
562
563 AT_DATA([tree.def],
564 [[@nostrtab
565 ROOT
566  a 1, a_OFFSET
567   b 1
568   c 2
569  d 2, d_OFFSET
570   e 1
571   f 2
572 ]])
573 AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <tree.def >tree.h])
574
575 AT_DATA([test0.c],
576 [[float tree_strtab = 0;
577 #define a []
578 #define b []
579 #define c []
580 #define e []
581 #define f []
582 #include "tree.h"
583 #include <stdio.h>
584
585 static struct { int num, offset; } root[] = { ROOT_INITIALIZER };
586
587 int main(void)
588 {
589   unsigned i;
590   for (i = 0; i < sizeof root / sizeof root[0]; i++) {
591     printf("%d, %d\n", root[i].num, root[i].offset);
592   }
593   return 0;
594 }
595 ]])
596
597 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0],
598 [[1, 3
599 2, 6
600 0, 0
601 1, 0
602 2, 0
603 0, 0
604 1, 0
605 2, 0
606 0, 0
607 ]])
608
609 AT_DATA([flat.def],
610 [[FLAT
611  a 1
612  b 2
613  c 3
614 @nostrtab
615 ]])
616 AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <flat.def >flat.h])
617
618 sed -e 's/tree\.h/flat.h/' -e 's/ROOT/FLAT/' test0.c >test1.c
619 AT_CHECK([$CC -o test1$EXEEXT test1.c && ./test1$EXEEXT], [0],
620 [[1, 0
621 2, 0
622 3, 0
623 0, 0
624 ]])
625
626 AT_CLEANUP
627
628 AT_SETUP([join.awk])
629 AT_KEYWORDS([join awk script scripts])
630
631 JOIN="$AWK -f $builddir/scripts/join.awk --"
632
633 AT_DATA([a],
634 [[1 a
635 3 a1 x
636 3 a2 x
637 5 a
638 6 a
639 8 a1 x
640 8 a2 x
641 9 a1
642 9 a2
643 9 a3
644 ]])
645
646 AT_DATA([b],
647 [[2 b
648 2 b
649 3 b y
650 4 b
651 6 b1 y
652 6 b2 y
653 7 b
654 8 b1 y
655 8 b2 y
656 ]])
657
658 AT_CHECK([$JOIN a b], [0],
659 [[3 a1 x b y
660 3 a2 x b y
661 6 a b1 y
662 6 a b2 y
663 8 a1 x b1 y
664 8 a1 x b2 y
665 8 a2 x b1 y
666 8 a2 x b2 y
667 ]])
668
669 AT_CHECK([$JOIN -v1 a b], [0],
670 [[1 a
671 5 a
672 9 a1
673 9 a2
674 9 a3
675 ]])
676
677 AT_CHECK([$JOIN -v2 a b], [0],
678 [[2 b
679 2 b
680 4 b
681 7 b
682 ]])
683
684 AT_CHECK([$JOIN -v1 -v2 a b], [0],
685 [[1 a
686 2 b
687 2 b
688 4 b
689 5 a
690 7 b
691 9 a1
692 9 a2
693 9 a3
694 ]])
695
696 AT_CHECK([$JOIN -a1 a b], [0],
697 [[1 a
698 3 a1 x b y
699 3 a2 x b y
700 5 a
701 6 a b1 y
702 6 a b2 y
703 8 a1 x b1 y
704 8 a1 x b2 y
705 8 a2 x b1 y
706 8 a2 x b2 y
707 9 a1
708 9 a2
709 9 a3
710 ]])
711
712 AT_CHECK([$JOIN -a2 a b], [0],
713 [[2 b
714 2 b
715 3 a1 x b y
716 3 a2 x b y
717 4 b
718 6 a b1 y
719 6 a b2 y
720 7 b
721 8 a1 x b1 y
722 8 a1 x b2 y
723 8 a2 x b1 y
724 8 a2 x b2 y
725 ]])
726
727 AT_CHECK([$JOIN -a1 -a2 a b], [0],
728 [[1 a
729 2 b
730 2 b
731 3 a1 x b y
732 3 a2 x b y
733 4 b
734 5 a
735 6 a b1 y
736 6 a b2 y
737 7 b
738 8 a1 x b1 y
739 8 a1 x b2 y
740 8 a2 x b1 y
741 8 a2 x b2 y
742 9 a1
743 9 a2
744 9 a3
745 ]])
746
747 AT_CHECK([$JOIN b a], [0],
748 [[3 b y a1 x
749 3 b y a2 x
750 6 b1 y a
751 6 b2 y a
752 8 b1 y a1 x
753 8 b1 y a2 x
754 8 b2 y a1 x
755 8 b2 y a2 x
756 ]])
757
758 AT_CHECK([$JOIN -v1 b a], [0],
759 [[2 b
760 2 b
761 4 b
762 7 b
763 ]])
764
765 AT_CHECK([$JOIN -v2 b a], [0],
766 [[1 a
767 5 a
768 9 a1
769 9 a2
770 9 a3
771 ]])
772
773 AT_CHECK([$JOIN -v1 -v2 b a], [0],
774 [[1 a
775 2 b
776 2 b
777 4 b
778 5 a
779 7 b
780 9 a1
781 9 a2
782 9 a3
783 ]])
784
785 AT_CHECK([$JOIN -a1 b a], [0],
786 [[2 b
787 2 b
788 3 b y a1 x
789 3 b y a2 x
790 4 b
791 6 b1 y a
792 6 b2 y a
793 7 b
794 8 b1 y a1 x
795 8 b1 y a2 x
796 8 b2 y a1 x
797 8 b2 y a2 x
798 ]])
799
800 AT_CHECK([$JOIN -a2 b a], [0],
801 [[1 a
802 3 b y a1 x
803 3 b y a2 x
804 5 a
805 6 b1 y a
806 6 b2 y a
807 8 b1 y a1 x
808 8 b1 y a2 x
809 8 b2 y a1 x
810 8 b2 y a2 x
811 9 a1
812 9 a2
813 9 a3
814 ]])
815
816 AT_CHECK([$JOIN -a1 -a2 b a], [0],
817 [[1 a
818 2 b
819 2 b
820 3 b y a1 x
821 3 b y a2 x
822 4 b
823 5 a
824 6 b1 y a
825 6 b2 y a
826 7 b
827 8 b1 y a1 x
828 8 b1 y a2 x
829 8 b2 y a1 x
830 8 b2 y a2 x
831 9 a1
832 9 a2
833 9 a3
834 ]])
835
836 AT_CHECK([echo wat | $JOIN -v1 - /dev/null], [0],
837 [[wat
838 ]])
839
840 AT_CLEANUP
841
842 m4_divert_push([PREPARE_TESTS])dnl
843 test_fix_ltdl () {
844   $PERL -e 'my $x = 42; exit $x;'; test $? = 42 || exit 77
845   $PERL -f "$srcdir/scripts/fix-ltdl.pl" "$@"
846 }
847 test_fix_gnulib () {
848   $PERL -e 'my $x = 42; exit $x;'; test $? = 42 || exit 77
849   $PERL -f "$srcdir/scripts/fix-gnulib.pl" "$@"
850 }
851 test_gnulib_mk () {
852   echo;
853   for arg
854   do
855     sed -n -f - "$srcdir/tests/data/gnulib.mk" <<EOF
856 /^## begin gnulib module $arg/,/^## end   gnulib module $arg/p
857 EOF
858   done
859 }
860 m4_divert_pop([PREPARE_TESTS])
861
862 AT_SETUP([fix-gnulib.pl SED_HEADER variables])
863
864 test_gnulib_mk gen-header >test.mk.in
865 AT_CHECK([grep SED_HEADER test.mk.in >expout || exit 99])
866 AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
867 grep SED_HEADER test.mk], [0], [expout])
868
869 AT_CLEANUP
870
871 AT_SETUP([fix-gnulib.pl %reldir% substitution])
872
873 test_gnulib_mk sys_types >test.mk.in
874 AT_CHECK([grep '%reldir%' test.mk.in >/dev/null || exit 99])
875
876 sed -n -f - test.mk.in >expout <<'EOF'
877 ${G;p;b}
878 /^## begin gnulib/,/^## end   gnulib/!b
879 /^#/{p;b}
880 s|(srcdir)|(top_srcdir)|
881 s|%reldir%|lib|
882 s|BUILT_SOURCES|gnulib_core_headers|
883 s|sys[[/_]]|lib/&|g
884 /^MOSTLYCLEANFILES/{h;b}
885 p
886 EOF
887
888 AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
889 sed -n -e '/^## begin gnulib/,/^## end   gnulib/p' \
890        -e '/CLEANFILES/p' test.mk],
891 [0], [expout])
892
893 AT_CLEANUP
894
895 AT_SETUP([fix-gnulib.pl warning removal])
896
897 AT_DATA([test.mk.in], [[
898 ## test begin
899 noinst_LTLIBRARIES += libgnu.la
900 libgnu_la_CFLAGS = $(AM_CFLAGS) $(GL_CFLAG_GNULIB_WARNINGS)
901 noinst_LIBRARIES += libgnu.a
902 libgnu_a_CFLAGS = $(AM_CFLAGS) $(GL_CFLAG_GNULIB_WARNINGS)
903 ## test end
904 ]])
905 AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
906 sed -n '/^## test begin/,/^## test end/p' test.mk], [0], [## test begin
907 EXTRA_LTLIBRARIES += libgnu.la
908 EXTRA_LIBRARIES += libgnu.a
909 ## test end
910 ])
911
912 AT_CLEANUP
913
914 AT_SETUP([fix-gnulib.pl header directory creation])
915
916 AT_DATA([extract.sed],
917 [[/AM_V_GEN/b ok
918 /gl_V_at/b ok
919 s/:.*/:/
920 h
921 b
922 :ok
923 s/'//g
924 x
925 G
926 p
927 n
928 s/[)].*/)/
929 p
930 ]])
931
932 test_gnulib_mk alloca-opt sys_types stddef >test.mk.in
933 AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
934 sed -n -f extract.sed test.mk], [0],
935 [[lib/alloca.h:
936         $(AM_V_GEN)$(MKDIR_P) lib
937         $(AM_V_at)
938 lib/sys/types.h:
939         $(AM_V_GEN)$(MKDIR_P) lib/sys
940         $(AM_V_at)
941 lib/stddef.h:
942         $(AM_V_GEN)$(MKDIR_P) lib
943         $(AM_V_at)
944 ]])
945
946 AT_CLEANUP
947
948 dnl TEST_FIND_AUTOMAKE_VER([to-check], [test-action])
949 dnl
950 dnl For each whitespace-separated version token in to-check, check if we can
951 dnl run the programs automake-VER and aclocal-VER.  The special token 'default'
952 dnl also checks the unversioned automake and aclocal (or, if set in the
953 dnl environment, $AUTOMAKE and $ACLOCAL).
954 dnl
955 dnl Then test-action is expanded such that shell variables $ac and $am refer to
956 dnl the aclocal and automake programs, and $amver is the actual version
957 dnl reported by --version.  The action should do nothing if the version is
958 dnl acceptable, or "continue" if the version is unacceptable.
959 dnl
960 dnl If an acceptable version is found, the AUTOMAKE and ACLOCAL environment
961 dnl variables are set accordingly.  Otherwise, the test group is skipped.
962 m4_define([TEST_FIND_AUTOMAKE],
963 [have_am=false
964 for am in $1; do
965   AS_CASE([$am],
966     [default], [ac=${ACLOCAL-aclocal} am=${AUTOMAKE-automake}],
967     [ac=aclocal-$am; am=automake-$am])
968   amver=`$am --version | sed -n '1s/.* //p'`
969   acver=`$ac --version | sed -n '1s/.* //p'`
970   set x $amver $acver; shift; test x"$[]#" = x"2" || continue
971   test x"$amver" = x"$acver" || continue
972   $2
973   have_am=:; break
974 done
975 AT_CHECK([$have_am || exit 77])
976 AUTOMAKE=$am; export AUTOMAKE
977 ACLOCAL=$ac; export ACLOCAL
978 AT_CHECK([$ACLOCAL --version && $AUTOMAKE --version], [0], [stdout])
979 ])
980
981 m4_define([TEST_LTDL_LIBOBJ_MANGLING],
982 [TEST_CONFIGURE_AC([[AM_INIT_AUTOMAKE([foreign subdir-objects])
983 AC_PROG_CC
984 LT_INIT
985 AC_SUBST([ltdl_LTLIBOBJS], [libltdl/test.lo])
986 AC_CONFIG_FILES([Makefile])
987 ]])
988
989 mkdir libltdl
990 AT_DATA([ltdl.mk.in], [[
991 AM_CPPFLAGS += -DSTRING=\"helloworld\"
992
993 noinst_LTLIBRARIES = libltdl/libltdl.la
994 libltdl_libltdl_la_SOURCES = libltdl/ltdl.c
995 libltdl_libltdl_la_LIBADD = $(ltdl_LTLIBOBJS)
996 libltdl_libltdl_la_DEPENDENCIES = $(ltdl_LTLIBOBJS)
997
998 EXTRA_DIST += libltdl/test.c
999 ]])
1000 AT_DATA([Makefile.am], [[AM_CPPFLAGS =
1001 include $(top_srcdir)/ltdl.mk
1002 AM_LIBTOOLFLAGS = --quiet
1003 bin_PROGRAMS = test
1004 test_SOURCES =
1005 test_LDADD = libltdl/libltdl.la
1006 all-local: ; @printf '%s\n' $(AM_CPPFLAGS)
1007 ]])
1008 AT_DATA([libltdl/test.c], [[#include <stdio.h>
1009 int foo(void) { printf("%s\n", STRING); return 0; }
1010 ]])
1011 AT_DATA([libltdl/ltdl.c], [[int foo(void); int main(void) { return foo(); }
1012 ]])
1013
1014 AT_CHECK([test_fix_ltdl -i ltdl.mk.in -o ltdl.mk])
1015 libtoolize; TEST_AUTORECONF
1016 TEST_CONFIGURE([--disable-shared])
1017 AT_CHECK([make -s && ./test], [0], [
1018 helloworld
1019 ])])
1020
1021 AT_SETUP([fix-ltdl.pl LIBOBJ mangling (<automake-1.16)])
1022
1023 TEST_FIND_AUTOMAKE([default 1.10 1.11 1.12 1.13 1.14 1.15],
1024   [AS_VERSION_COMPARE(["$amver"], [1.16], [], [continue], [continue])])
1025 TEST_LTDL_LIBOBJ_MANGLING
1026
1027 AT_CLEANUP
1028
1029 AT_SETUP([fix-ltdl.pl LIBOBJ mangling (>=automake-1.16)])
1030
1031 TEST_FIND_AUTOMAKE([default 1.16 1.17 1.18 1.19],
1032   [AS_VERSION_COMPARE(["$amver"], [1.16], [continue])])
1033 TEST_LTDL_LIBOBJ_MANGLING
1034
1035 AT_CLEANUP