6 static const struct option opts[] =
8 { "a1", no_argument, NULL, 'a' },
9 { "a2", no_argument, NULL, 'a' },
14 one_test (const char *fmt, int argc, char *argv[], int n, int expected[n])
19 for (int i = 0; i < n; ++i)
22 if (ftruncate (fileno (stderr), 0) != 0)
24 puts ("cannot truncate file");
28 int c = getopt_long (argc, argv, fmt, opts, NULL);
31 printf ("format '%s' test %d failed: expected '%c', got '%c'\n",
32 fmt, i, expected[i], c);
35 if (ftell (stderr) != 0)
37 printf ("format '%s' test %d failed: printed to stderr\n",
50 char *fname = tmpnam (NULL);
53 puts ("cannot generate name for temporary file");
57 if (freopen (fname, "w+", stderr) == NULL)
59 puts ("cannot redirect stderr");
65 int ret = one_test (":W;", 2,
66 (char *[2]) { (char *) "bug-getopt5", (char *) "--a" },
67 1, (int [1]) { 'a' });
69 ret |= one_test (":W;", 3,
70 (char *[3]) { (char *) "bug-getopt5", (char *) "-W",
72 1, (int [1]) { 'a' });
80 #define TEST_FUNCTION do_test ()
81 #include "../test-skeleton.c"