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