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