7 static const struct option opts
[] =
9 { "alpha", no_argument
, NULL
, 'a' },
10 { "beta", required_argument
, NULL
, 'b' },
15 one_test (const char *fmt
, int argc
, char *argv
[], int n
, int expected
[n
],
21 for (int i
= 0; i
< n
; ++i
)
24 if (ftruncate (fileno (stderr
), 0) != 0)
26 puts ("cannot truncate file");
30 int c
= getopt_long (argc
, argv
, fmt
, opts
, NULL
);
33 printf ("format '%s' test %d failed: expected '%c', got '%c'\n",
34 fmt
, i
, expected
[i
], c
);
37 if ((ftell (stderr
) != 0) != out
[i
])
39 printf ("format '%s' test %d failed: %sprinted to stderr\n",
40 fmt
, i
, out
[i
] ? "not " : "");
52 char fname
[] = "/tmp/bug-getopt3.XXXXXX";
53 int fd
= mkstemp (fname
);
56 printf ("mkstemp failed: %m\n");
61 if (freopen (fname
, "w+", stderr
) == NULL
)
63 puts ("cannot redirect stderr");
69 int ret
= one_test ("ab:W;", 2,
70 (char *[2]) { (char *) "bug-getopt3", (char *) "-a;" },
71 2, (int [2]) { 'a', '?' }, (int [2]) { 0, 1 });
73 ret
|= one_test ("ab:W;", 2,
74 (char *[2]) { (char *) "bug-getopt3", (char *) "-a:" }, 2,
75 (int [2]) { 'a', '?' }, (int [2]) { 0, 1 });
83 #define TEST_FUNCTION do_test ()
84 #include "../test-skeleton.c"