6 static const struct option opts
[] =
8 { "alpha", no_argument
, NULL
, 'a' },
9 { "beta", required_argument
, NULL
, 'b' },
14 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) != out
[i
])
38 printf ("format '%s' test %d failed: %sprinted to stderr\n",
39 fmt
, i
, out
[i
] ? "not " : "");
51 char *fname
= tmpnam (NULL
);
54 puts ("cannot generate name for temporary file");
58 if (freopen (fname
, "w+", stderr
) == NULL
)
60 puts ("cannot redirect stderr");
66 int ret
= one_test ("ab:W;", 2,
67 (char *[2]) { (char *) "bug-getopt3", (char *) "-a;" },
68 2, (int [2]) { 'a', '?' }, (int [2]) { 0, 1 });
70 ret
|= one_test ("ab:W;", 2,
71 (char *[2]) { (char *) "bug-getopt3", (char *) "-a:" }, 2,
72 (int [2]) { 'a', '?' }, (int [2]) { 0, 1 });
80 #define TEST_FUNCTION do_test ()
81 #include "../test-skeleton.c"