X-Git-Url: http://git.efficios.com/?p=argpar.git;a=blobdiff_plain;f=tests%2Ftest_argpar.c;h=87646a9a0a9d99fcc28a6ededbc035eee4eddeae;hp=2a24567f30f1f7c89132de2dd9f958ce6a6a044c;hb=10aefab2119c89f4afa4f46a619eae20d6be7512;hpb=fc07e5264804963a3de6d1b929a9eb4fd37e49d4 diff --git a/tests/test_argpar.c b/tests/test_argpar.c index 2a24567..87646a9 100644 --- a/tests/test_argpar.c +++ b/tests/test_argpar.c @@ -18,43 +18,53 @@ #include #include +#include #include +#include #include #include "tap/tap.h" #include "argpar/argpar.h" /* - * Append `item` to `res_str` to incrementally build an expected command line string. + * Formats `item` and appends the resulting string to `res_str` to + * incrementally build an expected command line string. + * + * This function: + * + * * Prefers the `--long-opt=arg` style over the `-s arg` style. + * + * * Uses the `arg` form for non-option arguments, where `A` is the + * original argument index and `B` is the non-option argument index. */ static -void append_to_res_str(GString *res_str, const struct argpar_item *item) +void append_to_res_str(GString * const res_str, + const struct argpar_item * const item) { if (res_str->len > 0) { g_string_append_c(res_str, ' '); } - switch (item->type) { + switch (argpar_item_type(item)) { case ARGPAR_ITEM_TYPE_OPT: { - const struct argpar_item_opt *item_opt = - (const void *) item; + const struct argpar_opt_descr * const descr = + argpar_item_opt_descr(item); + const char * const arg = argpar_item_opt_arg(item); - if (item_opt->descr->long_name) { + if (descr->long_name) { g_string_append_printf(res_str, "--%s", - item_opt->descr->long_name); + descr->long_name); - if (item_opt->arg) { - g_string_append_printf(res_str, "=%s", - item_opt->arg); + if (arg) { + g_string_append_printf(res_str, "=%s", arg); } - } else if (item_opt->descr->short_name) { + } else if (descr->short_name) { g_string_append_printf(res_str, "-%c", - item_opt->descr->short_name); + descr->short_name); - if (item_opt->arg) { - g_string_append_printf(res_str, " %s", - item_opt->arg); + if (arg) { + g_string_append_printf(res_str, " %s", arg); } } @@ -62,12 +72,14 @@ void append_to_res_str(GString *res_str, const struct argpar_item *item) } case ARGPAR_ITEM_TYPE_NON_OPT: { - const struct argpar_item_non_opt *item_non_opt = - (const void *) item; + const char * const arg = argpar_item_non_opt_arg(item); + const unsigned int orig_index = + argpar_item_non_opt_orig_index(item); + const unsigned int non_opt_index = + argpar_item_non_opt_non_opt_index(item); - g_string_append_printf(res_str, "%s<%u,%u>", - item_non_opt->arg, item_non_opt->orig_index, - item_non_opt->non_opt_index); + g_string_append_printf(res_str, "%s<%u,%u>", arg, orig_index, + non_opt_index); break; } default: @@ -75,121 +87,80 @@ void append_to_res_str(GString *res_str, const struct argpar_item *item) } } -/* Test using the all-at-once argpar_parse function. */ - -static -void test_succeed_argpar_parse(const char *cmdline, - const char *expected_cmd_line, - const struct argpar_opt_descr *descrs, - unsigned int expected_ingested_orig_args) -{ - struct argpar_parse_ret parse_ret; - GString *res_str = g_string_new(NULL); - gchar **argv = g_strsplit(cmdline, " ", 0); - unsigned int i; - - assert(argv); - assert(res_str); - parse_ret = argpar_parse(g_strv_length(argv), - (const char * const *) argv, descrs, false); - ok(parse_ret.items, - "argpar_parse() succeeds for command line `%s`", cmdline); - ok(!parse_ret.error, - "argpar_parse() does not write an error for command line `%s`", cmdline); - ok(parse_ret.ingested_orig_args == expected_ingested_orig_args, - "argpar_parse() returns the correct number of ingested " - "original arguments for command line `%s`", cmdline); - if (parse_ret.ingested_orig_args != expected_ingested_orig_args) { - diag("Expected: %u Got: %u", expected_ingested_orig_args, - parse_ret.ingested_orig_args); - } - - if (!parse_ret.items) { - fail("argpar_parse() returns the expected parsed arguments " - "for command line `%s`", cmdline); - goto end; - } - - for (i = 0; i < parse_ret.items->n_items; i++) { - const struct argpar_item *item = parse_ret.items->items[i]; - - append_to_res_str(res_str, item); - } - - ok(strcmp(expected_cmd_line, res_str->str) == 0, - "argpar_parse() returns the expected parsed arguments " - "for command line `%s`", cmdline); - if (strcmp(expected_cmd_line, res_str->str) != 0) { - diag("Expected: `%s`", expected_cmd_line); - diag("Got: `%s`", res_str->str); - } - -end: - argpar_parse_ret_fini(&parse_ret); - g_string_free(res_str, TRUE); - g_strfreev(argv); -} - -/* Test using the iterator API. */ - +/* + * Parses `cmdline` with the argpar API using the option descriptors + * `descrs`, and ensures that the resulting effective command line is + * `expected_cmd_line` and that the number of ingested original + * arguments is `expected_ingested_orig_args`. + * + * This function splits `cmdline` on spaces to create an original + * argument array. + * + * This function builds the resulting command line from parsing items + * by space-separating each formatted item (see append_to_res_str()). + */ static -void test_succeed_argpar_iter(const char *cmdline, - const char *expected_cmd_line, - const struct argpar_opt_descr *descrs, - unsigned int expected_ingested_orig_args) +void test_succeed(const char * const cmdline, + const char * const expected_cmd_line, + const struct argpar_opt_descr * const descrs, + const unsigned int expected_ingested_orig_args) { struct argpar_iter *iter = NULL; const struct argpar_item *item = NULL; - char *error = NULL; - GString *res_str = g_string_new(NULL); - gchar **argv = g_strsplit(cmdline, " ", 0); + const struct argpar_error *error = NULL; + GString * const res_str = g_string_new(NULL); + gchar ** const argv = g_strsplit(cmdline, " ", 0); unsigned int i, actual_ingested_orig_args; assert(argv); assert(res_str); - iter = argpar_iter_create(g_strv_length(argv), (const char * const *) argv, descrs); assert(iter); for (i = 0; ; i++) { - enum argpar_iter_parse_next_status status; + enum argpar_iter_next_status status; ARGPAR_ITEM_DESTROY_AND_RESET(item); - status = argpar_iter_parse_next(iter, &item, &error); - - ok(status == ARGPAR_ITER_PARSE_NEXT_STATUS_OK || - status == ARGPAR_ITER_PARSE_NEXT_STATUS_END || - status == ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT, - "argpar_iter_parse_next() for command line `%s` call #%u: status", cmdline, i); - - if (status == ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) { - ok(error, "argpar_iter_parse_next() for command line `%s` call #%u: error returned", cmdline, i); - } else { - ok(!error, "argpar_iter_parse_next() for command line `%s` call #%u: no error returned", cmdline, i); - } - - if (status == ARGPAR_ITER_PARSE_NEXT_STATUS_END || - status == ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) { - ok(!item, "argpar_iter_parse_next() for command line `%s` call #%u: no item returned", cmdline, i); + status = argpar_iter_next(iter, &item, &error); + + ok(status == ARGPAR_ITER_NEXT_STATUS_OK || + status == ARGPAR_ITER_NEXT_STATUS_END, + "argpar_iter_next() returns the expected status " + "(%d) for command line `%s` (call %u)", + status, cmdline, i + 1); + ok(!error, + "argpar_iter_next() doesn't set an error for " + "command line `%s` (call %u)", + cmdline, i + 1); + + if (status == ARGPAR_ITER_NEXT_STATUS_END) { + ok(!item, + "argpar_iter_next() doesn't set an item " + "for status `ARGPAR_ITER_NEXT_STATUS_END` " + "and command line `%s` (call %u)", + cmdline, i + 1); break; } append_to_res_str(res_str, item); } - actual_ingested_orig_args = argpar_iter_get_ingested_orig_args(iter); + actual_ingested_orig_args = argpar_iter_ingested_orig_args(iter); ok(actual_ingested_orig_args == expected_ingested_orig_args, - "argpar_iter_get_ingested_orig_args() returns the correct number of ingested " - "original arguments for command line `%s`", cmdline); + "argpar_iter_ingested_orig_args() returns the expected " + "number of ingested original arguments for command line `%s`", + cmdline); + if (actual_ingested_orig_args != expected_ingested_orig_args) { diag("Expected: %u Got: %u", expected_ingested_orig_args, actual_ingested_orig_args); } ok(strcmp(expected_cmd_line, res_str->str) == 0, - "argpar_iter_parse_next() returns the expected parsed arguments " + "argpar_iter_next() returns the expected parsing items " "for command line `%s`", cmdline); + if (strcmp(expected_cmd_line, res_str->str) != 0) { diag("Expected: `%s`", expected_cmd_line); diag("Got: `%s`", res_str->str); @@ -197,35 +168,9 @@ void test_succeed_argpar_iter(const char *cmdline, argpar_item_destroy(item); argpar_iter_destroy(iter); + assert(!error); g_string_free(res_str, TRUE); g_strfreev(argv); - free(error); -} - -/* - * Tests that the command line `cmdline`, with non-quoted - * space-delimited arguments, once parsed given the option descriptors - * `descrs`, succeeds and gives the expected command line `expected_cmd_line` - * and number of ingested original arguments `expected_ingested_orig_args`. - * - * The resulting command-line is built from the resulting arguments, - * space-delimiting each argument, preferring the `--long-opt=arg` style - * over the `-s arg` style, and using the `arg` form for non-option - * arguments where `A` is the original argument index and `B` is the - * non-option argument index. - * - * Test with both the parse-all-at-once and iterator-style APIs. - */ -static -void test_succeed(const char *cmdline, - const char *expected_cmd_line, - const struct argpar_opt_descr *descrs, - unsigned int expected_ingested_orig_args) -{ - test_succeed_argpar_parse(cmdline, expected_cmd_line, descrs, - expected_ingested_orig_args); - test_succeed_argpar_iter(cmdline, expected_cmd_line, descrs, - expected_ingested_orig_args); } static @@ -415,84 +360,6 @@ void succeed_tests(void) descrs, 7); } - /* Unknown short option (space form) */ - { - const struct argpar_opt_descr descrs[] = { - { 0, 'd', NULL, true }, - ARGPAR_OPT_DESCR_SENTINEL - }; - - test_succeed( - "-d salut -e -d meow", - "-d salut", - descrs, 2); - } - - /* Unknown short option (glued form) */ - { - const struct argpar_opt_descr descrs[] = { - { 0, 'd', NULL, true }, - ARGPAR_OPT_DESCR_SENTINEL - }; - - test_succeed( - "-dsalut -e -d meow", - "-d salut", - descrs, 1); - } - - /* Unknown long option (space form) */ - { - const struct argpar_opt_descr descrs[] = { - { 0, '\0', "sink", true }, - ARGPAR_OPT_DESCR_SENTINEL - }; - - test_succeed( - "--sink party --food --sink impulse", - "--sink=party", - descrs, 2); - } - - /* Unknown long option (equal form) */ - { - const struct argpar_opt_descr descrs[] = { - { 0, '\0', "sink", true }, - ARGPAR_OPT_DESCR_SENTINEL - }; - - test_succeed( - "--sink=party --food --sink=impulse", - "--sink=party", - descrs, 1); - } - - /* Unknown option before non-option argument */ - { - const struct argpar_opt_descr descrs[] = { - { 0, '\0', "thumb", true }, - ARGPAR_OPT_DESCR_SENTINEL - }; - - test_succeed( - "--thumb=party --food bateau --thumb waves", - "--thumb=party", - descrs, 1); - } - - /* Unknown option after non-option argument */ - { - const struct argpar_opt_descr descrs[] = { - { 0, '\0', "thumb", true }, - ARGPAR_OPT_DESCR_SENTINEL - }; - - test_succeed( - "--thumb=party wound --food --thumb waves", - "--thumb=party wound<1,0>", - descrs, 2); - } - /* Valid `---opt` */ { const struct argpar_opt_descr descrs[] = { @@ -584,139 +451,247 @@ void succeed_tests(void) "-f --yeah= -f", descrs, 3); } -} -/* Test using the all-at-once argpar_parse function. */ + /* `-` non-option argument */ + { + const struct argpar_opt_descr descrs[] = { + { 0, 'f', NULL, false }, + ARGPAR_OPT_DESCR_SENTINEL + }; -static -void test_fail_argpar_parse(const char *cmdline, const char *expected_error, - const struct argpar_opt_descr *descrs) -{ - struct argpar_parse_ret parse_ret; - gchar **argv = g_strsplit(cmdline, " ", 0); - - parse_ret = argpar_parse(g_strv_length(argv), - (const char * const *) argv, descrs, true); - ok(!parse_ret.items, - "argpar_parse() fails for command line `%s`", cmdline); - ok(parse_ret.error, - "argpar_parse() writes an error string for command line `%s`", - cmdline); - if (parse_ret.items) { - fail("argpar_parse() writes the expected error string"); - goto end; + test_succeed( + "-f - -f", + "-f -<1,0> -f", + descrs, 3); } - ok(strcmp(expected_error, parse_ret.error) == 0, - "argpar_parse() writes the expected error string " - "for command line `%s`", cmdline); - if (strcmp(expected_error, parse_ret.error) != 0) { - diag("Expected: `%s`", expected_error); - diag("Got: `%s`", parse_ret.error); + /* `--` non-option argument */ + { + const struct argpar_opt_descr descrs[] = { + { 0, 'f', NULL, false }, + ARGPAR_OPT_DESCR_SENTINEL + }; + + test_succeed( + "-f -- -f", + "-f --<1,0> -f", + descrs, 3); } -end: - argpar_parse_ret_fini(&parse_ret); - g_strfreev(argv); -} + /* Very long name of long option */ + { + const char opt_name[] = + "kale-chips-waistcoat-yr-bicycle-rights-gochujang-" + "woke-tumeric-flexitarian-biodiesel-chillwave-cliche-" + "ethical-cardigan-listicle-pok-pok-sustainable-live-" + "edge-jianbing-gochujang-butcher-disrupt-tattooed-" + "tumeric-prism-photo-booth-vape-kogi-jean-shorts-" + "blog-williamsburg-fingerstache-palo-santo-artisan-" + "affogato-occupy-skateboard-adaptogen-neutra-celiac-" + "put-a-bird-on-it-kombucha-everyday-carry-hot-chicken-" + "craft-beer-subway-tile-tote-bag-disrupt-selvage-" + "raclette-art-party-readymade-paleo-heirloom-trust-" + "fund-small-batch-kinfolk-woke-cardigan-prism-" + "chambray-la-croix-hashtag-unicorn-edison-bulb-tbh-" + "cornhole-cliche-tattooed-green-juice-adaptogen-" + "kitsch-lo-fi-vexillologist-migas-gentrify-" + "viral-raw-denim"; + const struct argpar_opt_descr descrs[] = { + { 0, '\0', opt_name, true }, + ARGPAR_OPT_DESCR_SENTINEL + }; + char cmdline[1024]; -/* Test using the iterator API. */ + sprintf(cmdline, "--%s=23", opt_name); + test_succeed(cmdline, cmdline, descrs, 1); + } +} +/* + * Parses `cmdline` with the argpar API using the option descriptors + * `descrs`, and ensures that argpar_iter_next() fails with status + * `expected_status` and that it sets an error having: + * + * * The original argument index `expected_orig_index`. + * + * * If applicable: + * + * * The unknown option name `expected_unknown_opt_name`. + * + * * The option descriptor at index `expected_opt_descr_index` of + * `descrs`. + * + * * The option type `expected_is_short`. + * + * This function splits `cmdline` on spaces to create an original + * argument array. + */ static -void test_fail_argpar_iter(const char *cmdline, const char *expected_error, - const struct argpar_opt_descr *descrs) +void test_fail(const char * const cmdline, + const enum argpar_error_type expected_error_type, + const unsigned int expected_orig_index, + const char * const expected_unknown_opt_name, + const unsigned int expected_opt_descr_index, + const bool expected_is_short, + const struct argpar_opt_descr * const descrs) { struct argpar_iter *iter = NULL; const struct argpar_item *item = NULL; - gchar **argv = g_strsplit(cmdline, " ", 0); + gchar ** const argv = g_strsplit(cmdline, " ", 0); unsigned int i; - char *error = NULL; + const struct argpar_error *error = NULL; iter = argpar_iter_create(g_strv_length(argv), (const char * const *) argv, descrs); assert(iter); for (i = 0; ; i++) { - enum argpar_iter_parse_next_status status; + enum argpar_iter_next_status status; ARGPAR_ITEM_DESTROY_AND_RESET(item); - status = argpar_iter_parse_next(iter, &item, &error); - - ok(status == ARGPAR_ITER_PARSE_NEXT_STATUS_OK || - status == ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR || - status == ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT, - "argpar_iter_parse_next() for command line `%s` call #%u: status", cmdline, i); - - if (status != ARGPAR_ITER_PARSE_NEXT_STATUS_OK) { - ok(!item, "argpar_iter_parse_next() for command line `%s` call #%u: no item returned", cmdline, i); - ok(error, "argpar_iter_parse_next() for command line `%s` call #%u: error returned", cmdline, i); + status = argpar_iter_next(iter, &item, &error); + ok(status == ARGPAR_ITER_NEXT_STATUS_OK || + (status == ARGPAR_ITER_NEXT_STATUS_ERROR && + argpar_error_type(error) == expected_error_type), + "argpar_iter_next() returns the expected status " + "and error type (%d) for command line `%s` (call %u)", + expected_error_type, cmdline, i + 1); + + if (status != ARGPAR_ITER_NEXT_STATUS_OK) { + ok(!item, + "argpar_iter_next() doesn't set an item " + "for other status than " + "`ARGPAR_ITER_NEXT_STATUS_OK` " + "and command line `%s` (call %u)", + cmdline, i + 1); + ok(error, + "argpar_iter_next() sets an error for " + "other status than " + " `ARGPAR_ITER_NEXT_STATUS_OK` " + "and command line `%s` (call %u)", + cmdline, i + 1); + ok(argpar_error_orig_index(error) == + expected_orig_index, + "argpar_iter_next() sets an error with " + "the expected original argument index " + "for command line `%s` (call %u)", + cmdline, i + 1); + + if (argpar_error_type(error) == ARGPAR_ERROR_TYPE_UNKNOWN_OPT) { + ok(strcmp(argpar_error_unknown_opt_name(error), + expected_unknown_opt_name) == 0, + "argpar_iter_next() sets an error with " + "the expected unknown option name " + "for command line `%s` (call %u)", + cmdline, i + 1); + } else { + bool is_short; + + ok(argpar_error_opt_descr(error, &is_short) == + &descrs[expected_opt_descr_index], + "argpar_iter_next() sets an error with " + "the expected option descriptor " + "for command line `%s` (call %u)", + cmdline, i + 1); + ok(is_short == expected_is_short, + "argpar_iter_next() sets an error with " + "the expected option type " + "for command line `%s` (call %u)", + cmdline, i + 1); + } break; } - ok(item, "argpar_iter_parse_next() for command line `%s` call #%u: item returned", cmdline, i); - ok(!error, "argpar_iter_parse_next() for command line `%s` call #%u: no error returned", cmdline, i); + ok(item, + "argpar_iter_next() sets an item for status " + "`ARGPAR_ITER_NEXT_STATUS_OK` " + "and command line `%s` (call %u)", + cmdline, i + 1); + ok(!error, + "argpar_iter_next() doesn't set an error for status " + "`ARGPAR_ITER_NEXT_STATUS_OK` " + "and command line `%s` (call %u)", + cmdline, i + 1); } + /* ok(strcmp(expected_error, error) == 0, - "argpar_iter_parse_next() writes the expected error string " + "argpar_iter_next() sets the expected error string " "for command line `%s`", cmdline); + if (strcmp(expected_error, error) != 0) { diag("Expected: `%s`", expected_error); diag("Got: `%s`", error); } + */ argpar_item_destroy(item); argpar_iter_destroy(iter); - free(error); + argpar_error_destroy(error); g_strfreev(argv); } -/* - * Tests that the command line `cmdline`, with non-quoted - * space-delimited arguments, once parsed given the option descriptors - * `descrs`, fails and gives the expected error `expected_error`. - * - * Test with both the parse-all-at-once and iterator-style APIs. - */ - -static -void test_fail(const char *cmdline, const char *expected_error, - const struct argpar_opt_descr *descrs) -{ - test_fail_argpar_parse(cmdline, expected_error, descrs); - test_fail_argpar_iter(cmdline, expected_error, descrs); -} - static void fail_tests(void) { - /* Unknown long option */ + + /* Unknown short option (space form) */ { const struct argpar_opt_descr descrs[] = { - { 0, '\0', "thumb", true }, + { 0, 'd', NULL, true }, ARGPAR_OPT_DESCR_SENTINEL }; test_fail( - "--thumb=party --meow", - "While parsing argument #2 (`--meow`): Unknown option `--meow`", + "-d salut -e -d meow", + ARGPAR_ERROR_TYPE_UNKNOWN_OPT, + 2, "-e", 0, false, descrs); } - /* Unknown short option */ + /* Unknown short option (glued form) */ { const struct argpar_opt_descr descrs[] = { - { 0, '\0', "thumb", true }, + { 0, 'd', 0, true }, ARGPAR_OPT_DESCR_SENTINEL }; test_fail( - "--thumb=party -x", - "While parsing argument #2 (`-x`): Unknown option `-x`", + "-dsalut -e -d meow", + ARGPAR_ERROR_TYPE_UNKNOWN_OPT, + 1, "-e", 0, false, descrs); } - /* Missing long option argument */ + /* Unknown long option (space form) */ + { + const struct argpar_opt_descr descrs[] = { + { 0, '\0', "sink", true }, + ARGPAR_OPT_DESCR_SENTINEL + }; + + test_fail( + "--sink party --food --sink impulse", + ARGPAR_ERROR_TYPE_UNKNOWN_OPT, + 2, "--food", 0, false, + descrs); + } + + /* Unknown long option (equal form) */ + { + const struct argpar_opt_descr descrs[] = { + { 0, '\0', "sink", true }, + ARGPAR_OPT_DESCR_SENTINEL + }; + + test_fail( + "--sink=party --food --sink=impulse", + ARGPAR_ERROR_TYPE_UNKNOWN_OPT, + 1, "--food", 0, false, + descrs); + } + + /* Unknown option before non-option argument */ { const struct argpar_opt_descr descrs[] = { { 0, '\0', "thumb", true }, @@ -724,55 +699,55 @@ void fail_tests(void) }; test_fail( - "--thumb", - "While parsing argument #1 (`--thumb`): Missing required argument for option `--thumb`", + "--thumb=party --food=18 bateau --thumb waves", + ARGPAR_ERROR_TYPE_UNKNOWN_OPT, + 1, "--food", 0, false, descrs); } - /* Missing short option argument */ + /* Unknown option after non-option argument */ { const struct argpar_opt_descr descrs[] = { - { 0, 'k', NULL, true }, + { 0, '\0', "thumb", true }, ARGPAR_OPT_DESCR_SENTINEL }; test_fail( - "-k", - "While parsing argument #1 (`-k`): Missing required argument for option `-k`", + "--thumb=party wound --food --thumb waves", + ARGPAR_ERROR_TYPE_UNKNOWN_OPT, + 2, "--food", 0, false, descrs); } - /* Missing short option argument (multiple glued) */ + /* Missing long option argument */ { const struct argpar_opt_descr descrs[] = { - { 0, 'a', NULL, false }, - { 0, 'b', NULL, false }, - { 0, 'c', NULL, true }, + { 0, '\0', "thumb", true }, ARGPAR_OPT_DESCR_SENTINEL }; test_fail( - "-abc", - "While parsing argument #1 (`-abc`): Missing required argument for option `-c`", + "allo --thumb", + ARGPAR_ERROR_TYPE_MISSING_OPT_ARG, + 1, NULL, 0, false, descrs); } - /* Invalid `-` */ + /* Missing short option argument */ { const struct argpar_opt_descr descrs[] = { - { 0, 'a', NULL, false }, - { 0, 'b', NULL, false }, - { 0, 'c', NULL, true }, + { 0, 'k', NULL, true }, ARGPAR_OPT_DESCR_SENTINEL }; test_fail( - "-ab - -c", - "While parsing argument #2 (`-`): Invalid argument", + "zoom heille -k", + ARGPAR_ERROR_TYPE_MISSING_OPT_ARG, + 2, NULL, 0, true, descrs); } - /* Invalid `--` */ + /* Missing short option argument (multiple glued) */ { const struct argpar_opt_descr descrs[] = { { 0, 'a', NULL, false }, @@ -782,11 +757,13 @@ void fail_tests(void) }; test_fail( - "-ab -- -c", - "While parsing argument #2 (`--`): Invalid argument", + "-abc", + ARGPAR_ERROR_TYPE_MISSING_OPT_ARG, + 0, NULL, 2, true, descrs); } + /* Unexpected long option argument */ { const struct argpar_opt_descr descrs[] = { { 0, 'c', "chevre", false }, @@ -794,15 +771,16 @@ void fail_tests(void) }; test_fail( - "--chevre=fromage", - "While parsing argument #1 (`--chevre=fromage`): Unexpected argument for option `--chevre`", + "ambulance --chevre=fromage tar -cjv", + ARGPAR_ERROR_TYPE_UNEXPECTED_OPT_ARG, + 1, NULL, 0, false, descrs); } } int main(void) { - plan_tests(419); + plan_tests(309); succeed_tests(); fail_tests(); return exit_status();