X-Git-Url: http://git.draconx.ca/gitweb/dxcommon.git/blobdiff_plain/203a69fab1ff61e958dfb88599fd5d7f24648abf..62bc7469bf3ef88c4f81ddf615aa7dabe9ddbf74:/tests/scripts.at diff --git a/tests/scripts.at b/tests/scripts.at index fc8fbc3..70df388 100644 --- a/tests/scripts.at +++ b/tests/scripts.at @@ -220,6 +220,72 @@ p AT_CLEANUP +AT_SETUP([gen-options.awk packed format]) +AT_KEYWORDS([gen-options awk script scripts]) + +AT_DATA([test.c], [[#include +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" 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])