7 one_test (const char *fmt
, int argc
, char *argv
[], int expected
[argc
- 1])
12 for (int i
= 0; i
< argc
- 1; ++i
)
15 if (ftruncate (fileno (stderr
), 0) != 0)
17 puts ("cannot truncate file");
21 int c
= getopt (argc
, argv
, fmt
);
24 printf ("format '%s' test %d failed: expected '%c', got '%c'\n",
25 fmt
, i
, expected
[i
], c
);
28 if (ftell (stderr
) != 0)
30 printf ("format '%s' test %d failed: printed to stderr\n",
43 char fname
[] = "/tmp/bug-getopt1.XXXXXX";
44 int fd
= mkstemp (fname
);
47 printf ("mkstemp failed: %m\n");
52 if (freopen (fname
, "w+", stderr
) == NULL
)
54 puts ("cannot redirect stderr");
60 int ret
= one_test ("+:a:b", 2,
61 (char *[2]) { (char *) "bug-getopt1", (char *) "-a" },
64 ret
|= one_test ("+:a:b", 3,
65 (char *[3]) { (char *) "bug-getopt1", (char *) "-b",
67 (int [2]) { 'b', ':' });
75 #define TEST_FUNCTION do_test ()
76 #include "../test-skeleton.c"