]> git.draconx.ca Git - dxcommon.git/blobdiff - tests/scripts.at
tests: Add missing returns test programs.
[dxcommon.git] / tests / scripts.at
index fc8fbc375a15b4f67652b66419e81dcfaa4ab8e4..6c90f5a425b69e0cd9f10905e110ef368d07e543 100644 (file)
@@ -169,6 +169,7 @@ int main(void)
     if (SOPT_STRING[i+1] != ':')
       putchar('\n');
   }
+  return 0;
 }
 ]])
 
@@ -220,6 +221,73 @@ p
 
 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);
+  }
+  return 0;
+}
+]])
+
+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])
 
@@ -488,6 +556,7 @@ int main(void)
   for (i = 0; i < sizeof root / sizeof root[0]; i++) {
     printf("%d, %d\n", root[i].num, root[i].offset);
   }
+  return 0;
 }
 ]])