6 one_test (const char *fmt
, int argc
, char *argv
[], int expected
[argc
- 1])
11 for (int i
= 0; i
< argc
- 1; ++i
)
14 if (ftruncate (fileno (stderr
), 0) != 0)
16 puts ("cannot truncate file");
20 int c
= getopt (argc
, argv
, fmt
);
23 printf ("format '%s' test %d failed: expected '%c', got '%c'\n",
24 fmt
, i
, expected
[i
], c
);
27 if (ftell (stderr
) != 0)
29 printf ("format '%s' test %d failed: printed to stderr\n",
42 char *fname
= tmpnam (NULL
);
45 puts ("cannot generate name for temporary file");
49 if (freopen (fname
, "w+", stderr
) == NULL
)
51 puts ("cannot redirect stderr");
57 int ret
= one_test ("+:a:b", 2,
58 (char *[2]) { (char *) "bug-getopt1", (char *) "-a" },
61 ret
|= one_test ("+:a:b", 3,
62 (char *[3]) { (char *) "bug-getopt1", (char *) "-b",
64 (int [2]) { 'b', ':' });
72 #define TEST_FUNCTION do_test ()
73 #include "../test-skeleton.c"