examples_relevant.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <tools/ccanlint/ccanlint.h>
  2. #include <tools/tools.h>
  3. #include <ccan/str/str.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <unistd.h>
  8. #include <limits.h>
  9. #include <errno.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <err.h>
  13. #include <string.h>
  14. #include <ctype.h>
  15. static void examples_relevant_check(struct manifest *m,
  16. unsigned int *timeleft,
  17. struct score *score)
  18. {
  19. struct ccan_file *f;
  20. struct doc_section *d;
  21. list_for_each(&m->h_files, f, list) {
  22. list_for_each(get_ccan_file_docs(f), d, list) {
  23. unsigned int i;
  24. bool found = false;
  25. if (!streq(d->type, "example"))
  26. continue;
  27. if (!d->function) {
  28. score_file_error(score, f, d->srcline+1,
  29. "Function name not found in summary line");
  30. continue;
  31. }
  32. for (i = 0; i < d->num_lines; i++) {
  33. if (strstr(d->lines[i], d->function))
  34. found = true;
  35. }
  36. if (!found) {
  37. score_file_error(score, f, d->srcline+1,
  38. "Example for %s doesn't"
  39. " mention it", d->function);
  40. }
  41. }
  42. }
  43. if (!score->error) {
  44. score->score = score->total;
  45. score->pass = true;
  46. return;
  47. }
  48. }
  49. struct ccanlint examples_relevant = {
  50. .key = "examples_relevant",
  51. .name = "Example: sections demonstrate appropriate function",
  52. .check = examples_relevant_check,
  53. .needs = "examples_exist"
  54. };
  55. REGISTER_TEST(examples_relevant);