7 static const struct option opts
[] =
9 { "a1", no_argument
, NULL
, 'a' },
10 { "a2", no_argument
, NULL
, 'a' },
15 one_test (const char *fmt
, int argc
, char *argv
[], int n
, int expected
[n
])
20 for (int i
= 0; i
< n
; ++i
)
23 if (ftruncate (fileno (stderr
), 0) != 0)
25 puts ("cannot truncate file");
29 int c
= getopt_long (argc
, argv
, fmt
, opts
, NULL
);
32 printf ("format '%s' test %d failed: expected '%c', got '%c'\n",
33 fmt
, i
, expected
[i
], c
);
36 if (ftell (stderr
) != 0)
38 printf ("format '%s' test %d failed: printed to stderr\n",
51 char fname
[] = "/tmp/bug-getopt5.XXXXXX";
52 int fd
= mkstemp (fname
);
55 printf ("mkstemp failed: %m\n");
60 if (freopen (fname
, "w+", stderr
) == NULL
)
62 puts ("cannot redirect stderr");
68 int ret
= one_test (":W;", 2,
69 (char *[2]) { (char *) "bug-getopt5", (char *) "--a" },
70 1, (int [1]) { 'a' });
72 ret
|= one_test (":W;", 3,
73 (char *[3]) { (char *) "bug-getopt5", (char *) "-W",
75 1, (int [1]) { 'a' });
83 #define TEST_FUNCTION do_test ()
84 #include "../test-skeleton.c"