]> git.ipfire.org Git - thirdparty/glibc.git/blame - posix/tst-getopt_long1.c
posix/glob.c: update from gnulib
[thirdparty/glibc.git] / posix / tst-getopt_long1.c
CommitLineData
bd25564e
UD
1static void do_prepare (void);
2#define PREPARE(argc, argv) do_prepare ()
3static int do_test (void);
4#define TEST_FUNCTION do_test ()
5#include "../test-skeleton.c"
6
7
8static char *fname;
9
10
11static void
12do_prepare (void)
13{
14 if (create_temp_file ("tst-getopt_long1", &fname) < 0)
15 {
16 printf ("cannot create temp file: %m\n");
17 exit (1);
18 }
19}
20
21
22static const struct option opts[] =
23 {
24 { "one", no_argument, NULL, '1' },
25 { "two", no_argument, NULL, '2' },
26 { "one-one", no_argument, NULL, '3' },
27 { "four", no_argument, NULL, '4' },
28 { "onto", no_argument, NULL, '5' },
29 { NULL, 0, NULL, 0 }
30 };
31
32
33static int
34do_test (void)
35{
36 if (freopen (fname, "w+", stderr) == NULL)
37 {
38 printf ("freopen failed: %m\n");
39 return 1;
40 }
41
b1aff6a4 42 char *argv[] = { (char *) "program", (char *) "--on" };
bd25564e
UD
43 int argc = 2;
44
45 int c = getopt_long (argc, argv, "12345", opts, NULL);
46 printf ("return value: %c\n", c);
47
48 rewind (stderr);
49 char *line = NULL;
50 size_t len = 0;
51 if (getline (&line, &len, stderr) < 0)
52 {
53 printf ("cannot read stderr redirect: %m\n");
54 return 1;
55 }
56 printf ("message = \"%s\"\n", line);
57
58 static const char expected[] = "\
aeacb9f9 59program: option '--on' is ambiguous; possibilities: '--one' '--one-one' '--onto'\n";
bd25564e
UD
60
61 return c != '?' || strcmp (line, expected) != 0;
62}