From 6e60dd8489444f28a821baf8a8143b1c79aafc75 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 6 May 2005 20:10:52 +0000 Subject: [PATCH] Add a testcase. 2005-05-06 Matthias Clasen * tests/option-test.c: Add a testcase. * glib/goption.c (g_option_context_parse): Treat '-' on its own as a non-option argument. (#168008, Tim Musson, Thomas Leonard and others) --- ChangeLog | 8 ++++++++ ChangeLog.pre-2-10 | 8 ++++++++ ChangeLog.pre-2-12 | 8 ++++++++ ChangeLog.pre-2-8 | 8 ++++++++ glib/goption.c | 2 +- tests/option-test.c | 27 +++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fbc9501d7..43d1b5920 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-05-06 Matthias Clasen + + * tests/option-test.c: Add a testcase. + + * glib/goption.c (g_option_context_parse): Treat '-' + on its own as a non-option argument. (#168008, Tim Musson, + Thomas Leonard and others) + 2005-05-05 Owen Taylor * glib/gdataset.[ch] glib/gdatasetprivate.h: Add diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index fbc9501d7..43d1b5920 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2005-05-06 Matthias Clasen + + * tests/option-test.c: Add a testcase. + + * glib/goption.c (g_option_context_parse): Treat '-' + on its own as a non-option argument. (#168008, Tim Musson, + Thomas Leonard and others) + 2005-05-05 Owen Taylor * glib/gdataset.[ch] glib/gdatasetprivate.h: Add diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index fbc9501d7..43d1b5920 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2005-05-06 Matthias Clasen + + * tests/option-test.c: Add a testcase. + + * glib/goption.c (g_option_context_parse): Treat '-' + on its own as a non-option argument. (#168008, Tim Musson, + Thomas Leonard and others) + 2005-05-05 Owen Taylor * glib/gdataset.[ch] glib/gdatasetprivate.h: Add diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index fbc9501d7..43d1b5920 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +2005-05-06 Matthias Clasen + + * tests/option-test.c: Add a testcase. + + * glib/goption.c (g_option_context_parse): Treat '-' + on its own as a non-option argument. (#168008, Tim Musson, + Thomas Leonard and others) + 2005-05-05 Owen Taylor * glib/gdataset.[ch] glib/gdatasetprivate.h: Add diff --git a/glib/goption.c b/glib/goption.c index a8528de36..234c1c938 100644 --- a/glib/goption.c +++ b/glib/goption.c @@ -1168,7 +1168,7 @@ g_option_context_parse (GOptionContext *context, gchar *arg, *dash; gboolean parsed = FALSE; - if ((*argv)[i][0] == '-' && !stop_parsing) + if ((*argv)[i][0] == '-' && (*argv)[i][1] != '\0' && !stop_parsing) { if ((*argv)[i][1] == '-') { diff --git a/tests/option-test.c b/tests/option-test.c index 9642b0fec..1383b2707 100644 --- a/tests/option-test.c +++ b/tests/option-test.c @@ -859,6 +859,30 @@ unknown_short_test (void) g_option_context_free (context); } +/* test that lone dashes are treated as non-options */ +void lonely_dash_test (void) +{ + GOptionContext *context; + gboolean retval; + GError *error = NULL; + gchar **argv; + int argc; + + context = g_option_context_new (NULL); + + /* Now try parsing */ + argv = split_string ("program -", &argc); + + retval = g_option_context_parse (context, &argc, &argv, &error); + + g_assert (retval); + + g_assert (argv[1] && strcmp (argv[1], "-") == 0); + + g_strfreev (argv); + g_option_context_free (context); +} + int main (int argc, char **argv) { @@ -904,5 +928,8 @@ main (int argc, char **argv) /* test for bug 166609 */ unknown_short_test (); + /* test for bug 168008 */ + lonely_dash_test (); + return 0; }