X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;ds=sidebyside;f=ccan%2Fopt%2Ftest%2Frun-helpers.c;h=10b241908add534cd0f816457214debe28be1fea;hb=3d45cf27cf586c9afe078ceb06fee115ea246a92;hp=589962fe4d8fadaffe6dc4cafd2764b2b5838a22;hpb=2d6e39ce1994c9537caf9a711b69a2c61f1ec35d;p=ccan diff --git a/ccan/opt/test/run-helpers.c b/ccan/opt/test/run-helpers.c index 589962fe..10b24190 100644 --- a/ccan/opt/test/run-helpers.c +++ b/ccan/opt/test/run-helpers.c @@ -19,9 +19,6 @@ static int saved_fprintf(FILE *ignored, const char *fmt, ...); #define vfprintf(f, fmt, ap) saved_vprintf(fmt, ap) static int saved_vprintf(const char *fmt, va_list ap); -#define malloc(size) saved_malloc(size) -static void *saved_malloc(size_t size); - #include #include #include @@ -65,13 +62,6 @@ static int saved_fprintf(FILE *ignored, const char *fmt, ...) return ret; } -#undef malloc -static void *last_allocation; -static void *saved_malloc(size_t size) -{ - return last_allocation = malloc(size); -} - static void set_args(int *argc, char ***argv, ...) { va_list ap; @@ -87,7 +77,7 @@ static void set_args(int *argc, char ***argv, ...) /* Test helpers. */ int main(int argc, char *argv[]) { - plan_tests(452); + plan_tests(454); /* opt_set_bool */ { @@ -132,7 +122,7 @@ int main(int argc, char *argv[]) } /* opt_set_charp */ { - char *arg = (char *)"wrong"; + char *arg = cast_const(char *, "wrong"); reset_options(); opt_register_arg("-a", opt_set_charp, NULL, &arg, "All"); ok1(parse_args(&argc, &argv, "-a", "string", NULL)); @@ -1005,6 +995,8 @@ int main(int argc, char *argv[]) fail("opt_show_version_and_exit returned?"); } else { ok1(exitval - 1 == 0); + /* We should have freed table!. */ + ok1(opt_table == NULL); } ok1(strcmp(output, "1.2.3\n") == 0); free(output); @@ -1027,14 +1019,14 @@ int main(int argc, char *argv[]) fail("opt_usage_and_exit returned?"); } else { ok1(exitval - 1 == 0); + /* We should have freed table!. */ + ok1(opt_table == NULL); } ok1(strstr(output, "[args]")); ok1(strstr(output, argv[0])); - ok1(strstr(output, "[-a]")); + ok1(strstr(output, "\n-a")); free(output); free(argv); - /* It exits without freeing usage string. */ - free(last_allocation); output = NULL; }