examples_relevant.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 void examples_relevant_check(struct manifest *m,
  17. bool keep,
  18. unsigned int *timeleft,
  19. struct score *score)
  20. {
  21. struct ccan_file *f;
  22. struct doc_section *d;
  23. list_for_each(&m->h_files, f, list) {
  24. list_for_each(get_ccan_file_docs(f), d, list) {
  25. unsigned int i;
  26. bool found = false;
  27. if (!streq(d->type, "example"))
  28. continue;
  29. if (!d->function) {
  30. score_file_error(score, f, d->srcline+1,
  31. "Function name not found in summary line");
  32. continue;
  33. }
  34. for (i = 0; i < d->num_lines; i++) {
  35. if (strstr(d->lines[i], d->function))
  36. found = true;
  37. }
  38. if (!found) {
  39. score_file_error(score, f, d->srcline+1,
  40. "Example for %s doesn't"
  41. " mention it", d->function);
  42. }
  43. }
  44. }
  45. if (!score->error) {
  46. score->score = score->total;
  47. score->pass = true;
  48. return;
  49. }
  50. }
  51. struct ccanlint examples_relevant = {
  52. .key = "examples_relevant",
  53. .name = "Example: sections demonstrate appropriate function",
  54. .check = examples_relevant_check,
  55. .needs = "examples_exist"
  56. };
  57. REGISTER_TEST(examples_relevant);