X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fopt%2Ftest%2Frun-helpers.c;h=48b7cd8b11dfba607bdc32a501bde99f37370487;hp=f8041ead39d1f73c3b095e0fb890db2ec886453a;hb=f20e4f235ac89f3901f248f91c3ac5a33088349d;hpb=d89e5744f30b584ac4909ce1164af1289c41359b diff --git a/ccan/opt/test/run-helpers.c b/ccan/opt/test/run-helpers.c index f8041ead..48b7cd8b 100644 --- a/ccan/opt/test/run-helpers.c +++ b/ccan/opt/test/run-helpers.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "utils.h" /* We don't actually want it to exit... */ @@ -48,7 +49,7 @@ static int saved_printf(const char *fmt, ...) /* Test helpers. */ int main(int argc, char *argv[]) { - plan_tests(88); + plan_tests(96); /* opt_set_bool */ { @@ -66,6 +67,9 @@ int main(int argc, char *argv[]) ok1(!arg); ok1(parse_args(&argc, &argv, "-b", "true", NULL)); ok1(arg); + ok1(!parse_args(&argc, &argv, "-b", "unknown", NULL)); + ok1(arg); + ok1(strstr(err_output, ": -b: Invalid argument 'unknown'")); } /* opt_set_invbool */ { @@ -84,6 +88,9 @@ int main(int argc, char *argv[]) ok1(arg); ok1(parse_args(&argc, &argv, "-b", "true", NULL)); ok1(!arg); + ok1(!parse_args(&argc, &argv, "-b", "unknown", NULL)); + ok1(!arg); + ok1(strstr(err_output, ": -b: Invalid argument 'unknown'")); } /* opt_set_charp */ { @@ -122,6 +129,17 @@ int main(int argc, char *argv[]) ok1(arg == 0); ok1(!parse_args(&argc, &argv, "-a", "100crap", NULL)); ok1(!parse_args(&argc, &argv, "-a", "4294967296", NULL)); + if (ULONG_MAX == UINT_MAX) { + pass("Can't test overflow"); + pass("Can't test error message"); + } else { + char buf[30]; + sprintf(buf, "%lu", ULONG_MAX); + ok1(!parse_args(&argc, &argv, "-a", buf, NULL)); + ok1(strstr(err_output, ": -a: value '") + && strstr(err_output, buf) + && strstr(err_output, "' does not fit into an integer")); + } } /* opt_set_longval */ {