From 5f73996bf368e7f5d7249679c738a87873cb340d Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 12 Sep 2018 12:14:14 -0700 Subject: fixes #720 fix for #715 still not right The fix for #715 to address const is still not quite right. In ISO C, the argv array is just char **. getopt() in POSIX uses char *const[]. That part is right, but we should then not pass const char ** in calls. Furthermore, really the optarg should also not be constified. This aligns us closer to getopt() and leads to the fewest problems. This does represent a slight breaking change, but as old code should still compile and run, we don't think we should bump the API version for this change. Furthermore, we don't think anyone else is actually using this API yet. --- tests/options.c | 119 ++++++++++++++++++++++++++------------------------------ 1 file changed, 55 insertions(+), 64 deletions(-) (limited to 'tests') diff --git a/tests/options.c b/tests/options.c index db04eea6..2d81bd83 100644 --- a/tests/options.c +++ b/tests/options.c @@ -27,14 +27,12 @@ static nng_optspec case1[] = { }; TestMain("Option Parsing", { - Convey("Simple works", { - - int opti = 1; - const char *av[6]; - int ac = 5; - int v; - const char *a = NULL; + int opti = 1; + char *av[6]; + int ac = 5; + int v; + char *a = NULL; av[0] = "program"; av[1] = "-f"; @@ -55,12 +53,11 @@ TestMain("Option Parsing", { }); Convey("Long works", { - - int opti = 1; - const char *av[6]; - int ac = 5; - int v; - const char *a = NULL; + int opti = 1; + char *av[6]; + int ac = 5; + int v; + char *a = NULL; av[0] = "program"; av[1] = "--flag"; @@ -81,12 +78,11 @@ TestMain("Option Parsing", { }); Convey("Attached short works", { - - int opti = 1; - const char *av[3]; - int ac = 3; - int v; - const char *a = NULL; + int opti = 1; + char *av[3]; + int ac = 3; + int v; + char *a = NULL; av[0] = "program"; av[1] = "-v123"; @@ -101,12 +97,11 @@ TestMain("Option Parsing", { }); Convey("Attached long (=) works", { - - int opti = 1; - const char *av[3]; - int ac = 3; - int v; - const char *a = NULL; + int opti = 1; + char *av[3]; + int ac = 3; + int v; + char *a = NULL; av[0] = "program"; av[1] = "--value=123"; @@ -121,12 +116,11 @@ TestMain("Option Parsing", { }); Convey("Attached long (:) works", { - - int opti = 1; - const char *av[3]; - int ac = 3; - int v; - const char *a = NULL; + int opti = 1; + char *av[3]; + int ac = 3; + int v; + char *a = NULL; av[0] = "program"; av[1] = "--value:123"; @@ -141,12 +135,11 @@ TestMain("Option Parsing", { }); Convey("Negative bad short works", { - - int opti = 1; - const char *av[3]; - int ac = 3; - int v; - const char *a = NULL; + int opti = 1; + char *av[3]; + int ac = 3; + int v; + char *a = NULL; av[0] = "program"; av[1] = "-Z"; @@ -156,12 +149,11 @@ TestMain("Option Parsing", { }); Convey("Negative bad long works", { - - int opti = 1; - const char *av[3]; - int ac = 3; - int v; - const char *a = NULL; + int opti = 1; + char *av[3]; + int ac = 3; + int v; + char *a = NULL; av[0] = "program"; av[1] = "--something"; @@ -171,11 +163,11 @@ TestMain("Option Parsing", { }); Convey("Separator flag works", { - int opti = 1; - const char *av[5]; - int ac = 5; - int v; - const char *a = NULL; + int opti = 1; + char *av[5]; + int ac = 5; + int v; + char *a = NULL; av[0] = "program"; av[1] = "-f"; @@ -190,22 +182,22 @@ TestMain("Option Parsing", { }); Convey("No options works", { - int opti = 1; - const char *av[1]; - int ac = 1; - int v; - const char *a = NULL; + int opti = 1; + char *av[1]; + int ac = 1; + int v; + char *a = NULL; av[0] = "program"; So(nng_opts_parse(ac, av, case1, &v, &a, &opti) == -1); }); Convey("No options (but arguments) works", { - int opti = 1; - const char *av[2]; - int ac = 2; - int v; - const char *a = NULL; + int opti = 1; + char *av[2]; + int ac = 2; + int v; + char *a = NULL; av[0] = "program"; av[1] = "123"; @@ -213,12 +205,11 @@ TestMain("Option Parsing", { So(opti == 1); }); Convey("Mixed long and short works", { - - int opti = 1; - const char *av[7]; - int ac = 7; - int v; - const char *a = NULL; + int opti = 1; + char *av[7]; + int ac = 7; + int v; + char *a = NULL; av[0] = "program"; av[1] = "--value=123"; -- cgit v1.2.3-70-g09d2