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