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