1 AT_BANNER([Script tests])
3 AT_SETUP([gen-options.awk])
8 --option-with-flagval (&x, 5)
11 --option-with-optional-arg[=OPTIONAL]
14 -a, --option-with-sopt
16 -b, --option-with-sopt-and-arg=SOPTARG
17 -c, --option-with-sopt-and-optional-arg[=SOPTOPTIONAL]
18 --option-with-arg-and-val=ARGVAL (42)
19 --option-with-arg-and-flagval=ARGFLAGVAL (&a[1], 'x')
20 --option-with-optional-arg-and-val[=OPTIONALARGVAL] (54)
21 --option-with-optional-arg-and-flagval[=OPTIONALFLAGVAL] (0, 0)
24 that has a line randomly indented
33 AT_CHECK([$AWK -f "$builddir/scripts/gen-options.awk" <options.def >options.h])
36 [[struct option { const char *name; int has_arg; int *flag; int val; };
42 [[#include "context.h"
45 static const char sopts[] = SOPT_STRING;
46 static const struct option opts[] = { LOPTS_INITIALIZER, {0} };
53 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [], [ignore])
55 # test 1: long option names and help text
63 static const struct option opts[] = { LOPTS_INITIALIZER };
69 for (i = 0; i < sizeof opts / sizeof opts[0]; i++) {
70 struct lopt_help help = { "INVALID", "INVALID" };
72 if (!lopt_get_help(&opts[i], &help))
75 printf("--%s", opts[i].name);
77 printf("=%s", help.arg);
78 printf("\n%s", help.desc);
87 # pick out interesting bits from the definitions file
88 sed -n '/^-/s/^.*--\([[^\= @<:@]]*\).*$/\1/p' options.def >options
90 s/[[^=]]*\(=[[^@:>@ ]]*\).*$/\1/
94 }' options.def >argnames
96 AS_ECHO(["-"]) | sed -n '1s/^-.*//p
114 s/[[^\n]][[^\n]]*/\\"&\\"/g
119 ' options.def - >helptext
121 exec 3<options 4<argnames 5<helptext 6>expout
122 while read opt <&3 && read arg <&4 && read help <&5; do
123 if test ${arg:+y}; then
124 AS_ECHO(["--$opt=$arg"]) >&6
126 AS_ECHO(["--$opt"]) >&6
128 eval "set x $help"; shift
131 AS_ECHO(["$arg"]) >&6
134 exec 3<&- 4<&- 5<&- 6>&-
136 AT_CHECK([$CC -o test1$EXEEXT test1.c && ./test1$EXEEXT],
137 [0], [expout], [ignore])
139 # test 2: short option string
149 struct option lopts[] = {LOPTS_INITIALIZER};
152 for (i = 0; i < sizeof SOPT_STRING - 1; i++) {
153 if (SOPT_STRING[i] != ':') {
154 for (j = 0; j < sizeof lopts / sizeof lopts[0]; j++) {
155 if (lopts[j].val == SOPT_STRING[i]) {
156 printf("--%s ", lopts[j].name);
161 putchar(SOPT_STRING[i]);
162 if (SOPT_STRING[i+1] != ':')
171 s/^-\([[^-]]\)[[^:]]*/\1/p
173 }' options.def >sopts
175 exec 3<options 4<sopts 5>expout
176 while read lopt <&3 && read sopt <&4; do
177 if test ${sopt:+y}; then
178 AS_ECHO(["--$lopt $sopt"]) >&5
183 AT_CHECK([$CC -o test2$EXEEXT test2.c && ./test2$EXEEXT],
184 [0], [expout], [ignore])
186 # Check that all help strings are translatable
187 sed 's/\([[^\\]]\\\)" /\1\\n\\" /g' helptext >help-po
188 exec 3<options 4<argnames 5<help-po 6>expected.po
189 while read opt <&3 && read arg <&4 && read help <&5; do
190 if test ${arg:+y}; then
191 AS_ECHO(["msgctxt \"$opt\" msgid \"$arg\""]) >&6
193 AS_ECHO(["msgctxt \"$opt\" msgid${help:+ }$help"]) >&6
195 exec 3<&- 4<&- 5<&- 6>&-
197 AT_CHECK([xgettext --keyword=PN_:1c,2 options.h
198 test -f messages.po || exit 77])
200 LC_ALL=C sort expected.po >expout
201 AT_CHECK([sed -n '/^msgctxt/{
212 }' messages.po | LC_ALL=C sort], [0], [expout])
216 AT_SETUP([gen-strtab.awk])
241 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test.def >test.h])
243 sed -n 's/^[[&]]\([[^ ]]*\).*/\1/p' test.def >identifiers
245 # test 0: sanity test
254 exec 3<identifiers 4>>test0.c
255 while read ident <&3; do
256 AS_ECHO([' printf("%s\n---\n", '"strtab+$ident);"]) >&4
258 AS_ECHO([' return 0;']) >&4
262 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [---