Add further tests of cosh and sinh.
[glibc.git] / posix / bug-getopt2.c
blob93c3035ccd4d0a3e4e081bc27450bec88ae93727
1 /* BZ 11039 */
2 #include <unistd.h>
3 #include <stdio.h>
5 static int
6 one_test (const char *fmt, int argc, char *argv[], int expected[argc - 1])
8 int res = 0;
9 for (int i = 0; i < argc - 1; ++i)
11 rewind (stderr);
12 if (ftruncate (fileno (stderr), 0) != 0)
14 puts ("cannot truncate file");
15 return 1;
18 int c = getopt (argc, argv, fmt);
19 if (c != expected[i])
21 printf ("format '%s' test %d failed: expected '%c', got '%c'\n",
22 fmt, i, expected[i], c);
23 res = 1;
25 if (ftell (stderr) == 0)
27 printf ("format '%s' test %d failed: not printed to stderr\n",
28 fmt, i);
29 res = 1;
33 return res;
37 static int
38 do_test (void)
40 char *fname = tmpnam (NULL);
41 if (fname == NULL)
43 puts ("cannot generate name for temporary file");
44 return 1;
47 if (freopen (fname, "w+", stderr) == NULL)
49 puts ("cannot redirect stderr");
50 return 1;
53 remove (fname);
55 optind = 0;
56 int ret = one_test ("+a", 2,
57 (char *[2]) { (char *) "bug-getopt2", (char *) "-+" },
58 (int [1]) { '?' });
60 optind = 1;
61 ret |= one_test ("+a", 2,
62 (char *[2]) { (char *) "bug-getopt2", (char *) "-+" },
63 (int [1]) { '?' });
65 if (ret == 0)
66 puts ("all OK");
68 return ret;
71 #define TEST_FUNCTION do_test ()
72 #include "../test-skeleton.c"