diff options
author | Matthias Clasen <mclasen@redhat.com> | 2010-08-05 02:23:42 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2010-08-05 02:24:26 -0400 |
commit | 008615f9999641158a89e3e6163b1580cac53dd0 (patch) | |
tree | 0bd20e017480d0cf9e4ca1132f76f0442c7bad1a /glib | |
parent | e2657d8dce32e10869ec2b18edc7dbf489dd2941 (diff) | |
download | glib-008615f9999641158a89e3e6163b1580cac53dd0.tar.gz |
Test an option handling corner-case
Diffstat (limited to 'glib')
-rw-r--r-- | glib/tests/option-context.c | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/glib/tests/option-context.c b/glib/tests/option-context.c index a1e6b8a8f..ffb4d1340 100644 --- a/glib/tests/option-context.c +++ b/glib/tests/option-context.c @@ -1708,7 +1708,7 @@ missing_arg_test (void) g_strfreev (argv); /* Try parsing again */ - argv = split_string ("program --t", &argc); + argv = split_string ("program -t", &argc); retval = g_option_context_parse (context, &argc, &argv, &error); g_assert (retval == FALSE); @@ -1717,6 +1717,62 @@ missing_arg_test (void) g_option_context_free (context); } +static gchar *test_arg; + +static gboolean cb (const gchar *option_name, + const gchar *value, + gpointer data, + GError **error) +{ + test_arg = g_strdup (value); + return TRUE; +} + +void +dash_arg_test (void) +{ + GOptionContext *context; + gboolean retval; + GError *error = NULL; + gchar **argv; + int argc; + gboolean argb = FALSE; + GOptionEntry entries [] = + { { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, cb, NULL, NULL }, + { "three", '3', 0, G_OPTION_ARG_NONE, &argb, NULL, NULL }, + { NULL } }; + + g_test_bug ("577638"); + + context = g_option_context_new (NULL); + g_option_context_add_main_entries (context, entries, NULL); + + /* Now try parsing */ + argv = split_string ("program --test=-3", &argc); + + test_arg = NULL; + error = NULL; + retval = g_option_context_parse (context, &argc, &argv, &error); + g_assert (retval); + g_assert_no_error (error); + g_assert_cmpstr (test_arg, ==, "-3"); + + g_strfreev (argv); + g_free (test_arg); + test_arg = NULL; + + /* Try parsing again */ + argv = split_string ("program --test -3", &argc); + + error = NULL; + retval = g_option_context_parse (context, &argc, &argv, &error); + g_assert_no_error (error); + g_assert (retval); + g_assert_cmpstr (test_arg, ==, NULL); + + g_option_context_free (context); +} + static void test_basic (void) { @@ -1886,6 +1942,7 @@ main (int argc, g_test_add_func ("/option/bug/unknown-short", unknown_short_test); g_test_add_func ("/option/bug/lonely-dash", lonely_dash_test); g_test_add_func ("/option/bug/missing-arg", missing_arg_test); + g_test_add_func ("/option/bug/dash-arg", dash_arg_test); return g_test_run(); } |