-void test_succeed_argpar_parse(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_parse_ret parse_ret;
- GString * const res_str = g_string_new(NULL);
- gchar ** const 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() doesn't set 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 parsing items "
- "for command line `%s`", cmdline);
- goto end;
- }
-
- for (i = 0; i < parse_ret.items->n_items; i++) {
- append_to_res_str(res_str, parse_ret.items->items[i]);
- }
-
- 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);
-}
-
-/*
- * Parses `cmdline` with the iterator 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 * const cmdline,