aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-09-12 12:14:14 -0700
committerGarrett D'Amore <garrett@damore.org>2018-09-12 12:50:52 -0700
commit5f73996bf368e7f5d7249679c738a87873cb340d (patch)
treed73413a4f8c0f4a07fd6a6a5a08a8d6bfae41851 /tests
parent74b067f6c381567e3da89e8a95ca13b4ffe81302 (diff)
downloadnng-5f73996bf368e7f5d7249679c738a87873cb340d.tar.gz
nng-5f73996bf368e7f5d7249679c738a87873cb340d.tar.bz2
nng-5f73996bf368e7f5d7249679c738a87873cb340d.zip
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/options.c119
1 files changed, 55 insertions, 64 deletions
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";