X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fexamples_relevant.c;fp=tools%2Fccanlint%2Ftests%2Fexamples_relevant.c;h=283e78c10cda3914ce3ccaaad328c31be94d5f89;hb=598b7d1351176b73247855893fd49c5e38f5800a;hp=0000000000000000000000000000000000000000;hpb=2b46b6e66a6a842923640c881cd235166a4c9ad5;p=ccan-lca-2011.git diff --git a/tools/ccanlint/tests/examples_relevant.c b/tools/ccanlint/tests/examples_relevant.c new file mode 100644 index 0000000..283e78c --- /dev/null +++ b/tools/ccanlint/tests/examples_relevant.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void examples_relevant_check(struct manifest *m, + bool keep, + unsigned int *timeleft, + struct score *score) +{ + struct ccan_file *f; + struct doc_section *d; + + list_for_each(&m->h_files, f, list) { + list_for_each(get_ccan_file_docs(f), d, list) { + unsigned int i; + bool found = false; + + if (!streq(d->type, "example")) + continue; + + for (i = 0; i < d->num_lines; i++) { + if (strstr(d->lines[i], d->function)) + found = true; + } + + if (!found) { + score_file_error(score, f, d->srcline+1, + "Example for %s doesn't" + " mention it", d->function); + } + } + } + + if (!score->error) { + score->score = score->total; + score->pass = true; + return; + } +} + +struct ccanlint examples_relevant = { + .key = "examples_relevant", + .name = "Example: sections demonstrate appropriate function", + .check = examples_relevant_check, + .needs = "examples_exist" +}; + +REGISTER_TEST(examples_relevant);