diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-11-23 19:13:18 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-11-23 19:13:18 -0800 |
| commit | 77f85a4d2b46e1ccc34a4c86e8c97392fa73e280 (patch) | |
| tree | 7e0e1e2dd4fd9718ffb75dcc8a4d49aebef6aea2 /src/supplemental/util/options_test.c | |
| parent | aa7f8ec46f8b6e910372fbbd0696bf2c369d4fcd (diff) | |
| download | nng-77f85a4d2b46e1ccc34a4c86e8c97392fa73e280.tar.gz nng-77f85a4d2b46e1ccc34a4c86e8c97392fa73e280.tar.bz2 nng-77f85a4d2b46e1ccc34a4c86e8c97392fa73e280.zip | |
options parser: Add a couple of tests for ambiguous and missing arguments
Diffstat (limited to 'src/supplemental/util/options_test.c')
| -rw-r--r-- | src/supplemental/util/options_test.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/supplemental/util/options_test.c b/src/supplemental/util/options_test.c index f139f6fe..e365f97e 100644 --- a/src/supplemental/util/options_test.c +++ b/src/supplemental/util/options_test.c @@ -8,6 +8,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng/nng.h" #include <nuts.h> #include <nng/supplemental/util/options.h> @@ -258,6 +259,49 @@ test_mixed_long_short(void) NUTS_TRUE(opti == 6); } +void +test_ambiguous(void) +{ + int opti = 1; + char *av[2]; + int ac = 2; + int v; + char *a = NULL; + + nng_optspec spec[] = { + { "flag", 'f', 1, false }, + { "fluid", 0, 2, false }, + { NULL, 0, 0, false }, + }; + + av[0] = "program"; + av[1] = "--fl"; + NUTS_FAIL(nng_opts_parse(ac, av, spec, &v, &a, &opti), NNG_EAMBIGUOUS); +} + +void +test_missing_arg(void) +{ + int opti = 1; + char *av[2]; + int ac = 2; + int v; + char *a = NULL; + + nng_optspec spec[] = { + { "flag", 'f', 1, true }, + { NULL, 0, 0, false }, + }; + + av[0] = "program"; + av[1] = "--fl"; + NUTS_FAIL(nng_opts_parse(ac, av, spec, &v, &a, &opti), NNG_ENOARG); + av[0] = "program"; + av[1] = "-f"; + opti = 1; + NUTS_FAIL(nng_opts_parse(ac, av, spec, &v, &a, &opti), NNG_ENOARG); +} + NUTS_TESTS = { { "simple options", test_simple_options }, { "long options", test_long_options }, @@ -270,5 +314,7 @@ NUTS_TESTS = { { "bad long", test_negative_bad_long }, { "arg only", test_arg_only }, { "options mixed long short", test_mixed_long_short }, + { "ambiguous options", test_ambiguous }, + { "missing argument", test_missing_arg }, { NULL, NULL }, }; |
