X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fcompile_test_helpers.c;fp=tools%2Fccanlint%2Ftests%2Fcompile_test_helpers.c;h=017a5308cbc4b48f6cba5b5f7bb6cae615efbdcc;hb=4e0dfdadf206c74dc9e5f302545b2419cc4798f4;hp=0000000000000000000000000000000000000000;hpb=3f011090d857a625f9eccfca6dd33d1b897417a8;p=ccan diff --git a/tools/ccanlint/tests/compile_test_helpers.c b/tools/ccanlint/tests/compile_test_helpers.c new file mode 100644 index 00000000..017a5308 --- /dev/null +++ b/tools/ccanlint/tests/compile_test_helpers.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const char *can_build(struct manifest *m) +{ + if (safe_mode) + return "Safe mode enabled"; + return NULL; +} + +static int cleanup_testfile(char *testfile) +{ + unlink(testfile); + return 0; +} + +static char *objname(const void *ctx, const char *cfile) +{ + return talloc_asprintf(ctx, "%.*s.o ", strlen(cfile) - 2, cfile); +} + +static char *compile(struct manifest *m, const char *cfile) +{ + char *obj; + + obj = objname(m, cfile); + talloc_set_destructor(obj, cleanup_testfile); + return run_command(m, "cc " CFLAGS " -c -o %s %s", obj, cfile); +} + +static void *do_compile_test_helpers(struct manifest *m) +{ + char *cmdout = NULL; + struct ccan_file *i; + + list_for_each(&m->other_test_c_files, i, list) { + compile_tests.total_score++; + cmdout = compile(m, i->name); + if (cmdout) + return talloc_asprintf(m, + "Failed to compile helper C" + " code file %s:\n%s", + i->name, cmdout); + } + return NULL; +} + +static const char *describe_compile_test_helpers(struct manifest *m, + void *check_result) +{ + return check_result; +} + +struct ccanlint compile_test_helpers = { + .name = "Compiling test helper files", + .total_score = 1, + .check = do_compile_test_helpers, + .describe = describe_compile_test_helpers, + .can_run = can_build, +}; + +REGISTER_TEST(compile_test_helpers, &depends_built);