Remove "invalid argument" statuses
[argpar.git] / tests / test_argpar.c
index f9f8f4991bb7e1eee484067f9ecc0879a9ff5a6a..fee82a9ed06031c32ae5dc70ff159735c3f6da75 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <stdbool.h>
 #include <glib.h>
@@ -225,9 +226,9 @@ void test_succeed_argpar_iter(const char * const cmdline,
                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 expected "
+               "argpar_iter_ingested_orig_args() returns the expected "
                "number of ingested original arguments for command line `%s`",
                cmdline);
 
@@ -624,6 +625,60 @@ void succeed_tests(void)
                        "-f --yeah= -f",
                        descrs, 3);
        }
+
+       /* `-` 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);
+       }
+
+       /* `--` 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);
+       }
+
+       /* 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];
+
+               sprintf(cmdline, "--%s=23", opt_name);
+               test_succeed(cmdline, cmdline, descrs, 1);
+       }
 }
 
 /*
@@ -837,38 +892,7 @@ void fail_tests(void)
                        descrs);
        }
 
-       /* Invalid `-` */
-       {
-               const struct argpar_opt_descr descrs[] = {
-                       { 0, 'a', NULL, false },
-                       { 0, 'b', NULL, false },
-                       { 0, 'c', NULL, true },
-                       ARGPAR_OPT_DESCR_SENTINEL
-               };
-
-               test_fail(
-                       "-ab - -c",
-                       "While parsing argument #2 (`-`): Invalid argument",
-                       ARGPAR_ITER_NEXT_STATUS_ERROR_INVALID_ARG,
-                       descrs);
-       }
-
-       /* Invalid `--` */
-       {
-               const struct argpar_opt_descr descrs[] = {
-                       { 0, 'a', NULL, false },
-                       { 0, 'b', NULL, false },
-                       { 0, 'c', NULL, true },
-                       ARGPAR_OPT_DESCR_SENTINEL
-               };
-
-               test_fail(
-                       "-ab -- -c",
-                       "While parsing argument #2 (`--`): Invalid argument",
-                       ARGPAR_ITER_NEXT_STATUS_ERROR_INVALID_ARG,
-                       descrs);
-       }
-
+       /* Unexpected long option argument */
        {
                const struct argpar_opt_descr descrs[] = {
                        { 0, 'c', "chevre", false },
@@ -885,7 +909,7 @@ void fail_tests(void)
 
 int main(void)
 {
-       plan_tests(419);
+       plan_tests(434);
        succeed_tests();
        fail_tests();
        return exit_status();
This page took 0.024239 seconds and 4 git commands to generate.