AT_CLEANUP
+AT_SETUP([gen-options.awk packed format])
+AT_KEYWORDS([gen-options awk script scripts])
+
+AT_DATA([test.c], [[#include <stdio.h>
+struct option { const char *name; int has_arg; int *flag; int val; };
+
+#include "options.h"
+
+static unsigned opts[] = { LOPTS_PACKED_INITIALIZER };
+
+int main(void)
+{
+ unsigned i;
+ int x =
+#if !LOPT_PACK_BITS
+ 0
+#elif LOPT_PACK_BITS <= 8
+ 1
+#elif LOPT_PACK_BITS <= 16
+ 2
+#elif LOPT_PACK_BITS <= 32
+ 3
+#else
+# error too big
+#endif
+ ;
+ printf("%d\n", x);
+ for (i = 0; i < sizeof opts / sizeof opts[0]; i++) {
+ struct option o;
+
+ LOPT_UNPACK(o, opts[i]);
+ printf("--%s, %d, ", o.name, o.has_arg);
+ if (o.val > UCHAR_MAX)
+ printf("%d\n", o.val - UCHAR_MAX - 1);
+ else
+ printf("'%c'\n", o.val);
+ }
+}
+]])
+
+AT_DATA([single.dat],
+[[--single-option
+]])
+AT_CHECK([$AWK -f "$builddir/scripts/gen-options.awk" <single.dat >options.h])
+AT_CHECK([$CC -o single$EXEEXT test.c && ./single$EXEEXT], [0],
+[[0
+--single-option, 0, 0
+]])
+
+AT_DATA([16bit.dat],
+[[-a, --the-first-option
+-b, --the-second-option=ARG
+-c, --the-third-option[=ARG]
+-d, --the-fourth-option
+]])
+AT_CHECK([$AWK -f "$builddir/scripts/gen-options.awk" <16bit.dat >options.h])
+AT_CHECK([$CC -o 16bit$EXEEXT test.c && ./16bit$EXEEXT], [0],
+[[2
+--the-first-option, 0, 'a'
+--the-second-option, 1, 'b'
+--the-third-option, 2, 'c'
+--the-fourth-option, 0, 'd'
+]])
+
+AT_CLEANUP
+
AT_SETUP([gen-strtab.awk])
AT_KEYWORDS([gen-strtab awk script scripts])