|
Packit |
6c4009 |
static void do_prepare (void);
|
|
Packit |
6c4009 |
#define PREPARE(argc, argv) do_prepare ()
|
|
Packit |
6c4009 |
static int do_test (void);
|
|
Packit |
6c4009 |
#define TEST_FUNCTION do_test ()
|
|
Packit |
6c4009 |
#include "../test-skeleton.c"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static char *fname;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static void
|
|
Packit |
6c4009 |
do_prepare (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (create_temp_file ("tst-getopt_long1", &fname) < 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("cannot create temp file: %m\n");
|
|
Packit |
6c4009 |
exit (1);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static const struct option opts[] =
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
{ "one", no_argument, NULL, '1' },
|
|
Packit |
6c4009 |
{ "two", no_argument, NULL, '2' },
|
|
Packit |
6c4009 |
{ "one-one", no_argument, NULL, '3' },
|
|
Packit |
6c4009 |
{ "four", no_argument, NULL, '4' },
|
|
Packit |
6c4009 |
{ "onto", no_argument, NULL, '5' },
|
|
Packit |
6c4009 |
{ NULL, 0, NULL, 0 }
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (freopen (fname, "w+", stderr) == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("freopen failed: %m\n");
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
char *argv[] = { (char *) "program", (char *) "--on" };
|
|
Packit |
6c4009 |
int argc = 2;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int c = getopt_long (argc, argv, "12345", opts, NULL);
|
|
Packit |
6c4009 |
printf ("return value: %c\n", c);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
rewind (stderr);
|
|
Packit |
6c4009 |
char *line = NULL;
|
|
Packit |
6c4009 |
size_t len = 0;
|
|
Packit |
6c4009 |
if (getline (&line, &len, stderr) < 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("cannot read stderr redirect: %m\n");
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
printf ("message = \"%s\"\n", line);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static const char expected[] = "\
|
|
Packit |
6c4009 |
program: option '--on' is ambiguous; possibilities: '--one' '--one-one' '--onto'\n";
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return c != '?' || strcmp (line, expected) != 0;
|
|
Packit |
6c4009 |
}
|