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