6 static const struct option opts
[] =
8 { "alpha", optional_argument
, NULL
, 'a' },
13 one_test (const char *fmt
, int argc
, char *argv
[], int n
, int expected
[n
])
18 for (int i
= 0; i
< n
; ++i
)
21 if (ftruncate (fileno (stderr
), 0) != 0)
23 puts ("cannot truncate file");
27 int c
= getopt_long (argc
, argv
, fmt
, opts
, NULL
);
30 printf ("%s: format '%s' test %d failed: expected '%c', got '%c'\n",
31 argv
[0], fmt
, i
, expected
[i
], c
);
34 else if (optarg
!= NULL
)
36 printf ("%s: format '%s' test %d failed: optarg is \"%s\", not NULL\n",
37 argv
[0], fmt
, i
, optarg
);
40 if (ftell (stderr
) != 0)
42 printf ("%s: format '%s' test %d failed: printed to stderr\n",
55 char *fname
= tmpnam (NULL
);
58 puts ("cannot generate name for temporary file");
62 if (freopen (fname
, "w+", stderr
) == NULL
)
64 puts ("cannot redirect stderr");
70 int ret
= one_test ("W;", 2,
71 (char *[2]) { (char *) "bug-getopt4a", (char *) "--a" },
72 1, (int [1]) { 'a' });
74 ret
|= one_test ("W;", 3,
75 (char *[3]) { (char *) "bug-getopt4b", (char *) "-W",
77 1, (int [1]) { 'a' });
85 #define TEST_FUNCTION do_test ()
86 #include "../test-skeleton.c"