compile_test_helpers.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <tools/ccanlint/ccanlint.h>
  2. #include <tools/tools.h>
  3. #include <ccan/talloc/talloc.h>
  4. #include <ccan/str/str.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9. #include <limits.h>
  10. #include <errno.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <err.h>
  14. #include <string.h>
  15. #include <ctype.h>
  16. static const char *can_build(struct manifest *m)
  17. {
  18. if (safe_mode)
  19. return "Safe mode enabled";
  20. return NULL;
  21. }
  22. static char *compile(struct manifest *m, struct ccan_file *cfile)
  23. {
  24. char *err;
  25. char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, cfile->name);
  26. cfile->compiled = compile_object(m, fullfile, ccan_dir, &err);
  27. if (cfile->compiled)
  28. return NULL;
  29. return err;
  30. }
  31. static void *do_compile_test_helpers(struct manifest *m)
  32. {
  33. char *cmdout = NULL;
  34. struct ccan_file *i;
  35. list_for_each(&m->other_test_c_files, i, list) {
  36. compile_tests.total_score++;
  37. cmdout = compile(m, i);
  38. if (cmdout)
  39. return talloc_asprintf(m,
  40. "Failed to compile helper C"
  41. " code file %s:\n%s",
  42. i->name, cmdout);
  43. }
  44. return NULL;
  45. }
  46. static const char *describe_compile_test_helpers(struct manifest *m,
  47. void *check_result)
  48. {
  49. return check_result;
  50. }
  51. struct ccanlint compile_test_helpers = {
  52. .key = "compile-helpers",
  53. .name = "Module test helper objects compile",
  54. .total_score = 1,
  55. .check = do_compile_test_helpers,
  56. .describe = describe_compile_test_helpers,
  57. .can_run = can_build,
  58. };
  59. REGISTER_TEST(compile_test_helpers, &depends_built);