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