examples_relevant.c 1.4 KB

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