compile_test_helpers.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. cfile->compiled = compile_object(m, cfile->name, &err);
  26. if (cfile->compiled)
  27. return NULL;
  28. return err;
  29. }
  30. static void *do_compile_test_helpers(struct manifest *m)
  31. {
  32. char *cmdout = NULL;
  33. struct ccan_file *i;
  34. list_for_each(&m->other_test_c_files, i, list) {
  35. compile_tests.total_score++;
  36. cmdout = compile(m, i);
  37. if (cmdout)
  38. return talloc_asprintf(m,
  39. "Failed to compile helper C"
  40. " code file %s:\n%s",
  41. i->name, cmdout);
  42. }
  43. return NULL;
  44. }
  45. static const char *describe_compile_test_helpers(struct manifest *m,
  46. void *check_result)
  47. {
  48. return check_result;
  49. }
  50. struct ccanlint compile_test_helpers = {
  51. .name = "Compiling test helper files",
  52. .total_score = 1,
  53. .check = do_compile_test_helpers,
  54. .describe = describe_compile_test_helpers,
  55. .can_run = can_build,
  56. };
  57. REGISTER_TEST(compile_test_helpers, &depends_built);