X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fexamples_exist.c;h=c42a2e4e9ff27c5f183b498e798c3ae10a1e238f;hp=073a0b2c215c74e57b1b53cbed309a864c1a5aa9;hb=c5a49e4942e98f17744f2a50dead077b34d0ceaf;hpb=509fc838deaf1c53638bcae6c1a826c2f990b827 diff --git a/tools/ccanlint/tests/examples_exist.c b/tools/ccanlint/tests/examples_exist.c index 073a0b2c..c42a2e4e 100644 --- a/tools/ccanlint/tests/examples_exist.c +++ b/tools/ccanlint/tests/examples_exist.c @@ -1,7 +1,8 @@ #include #include -#include #include +#include +#include #include #include #include @@ -24,28 +25,26 @@ static char *add_example(struct manifest *m, struct ccan_file *source, int fd; struct ccan_file *f; - name = talloc_asprintf(m, "%s/example-%s-%s.c", - talloc_dirname(m, - source->fullname), - source->name, - example->function); + name = tal_fmt(m, "example-%s-%s", + source->name, example->function); /* example->function == 'struct foo' */ while (strchr(name, ' ')) *strchr(name, ' ') = '_'; - name = temp_file(m, ".c", name); - f = new_ccan_file(m, talloc_dirname(m, name), talloc_basename(m, name)); - talloc_steal(f, name); + name = temp_file(m, ".c", take(name)); + f = new_ccan_file(m, take(path_dirname(m, name)), + take(path_basename(m, name))); + tal_steal(f, name); list_add_tail(&m->examples, &f->list); fd = open(f->fullname, O_WRONLY | O_CREAT | O_EXCL, 0600); if (fd < 0) - return talloc_asprintf(m, "Creating temporary file %s: %s", - f->fullname, strerror(errno)); + return tal_fmt(m, "Creating temporary file %s: %s", + f->fullname, strerror(errno)); /* Add #line to demark where we are from, so errors are correct! */ - linemarker = talloc_asprintf(f, "#line %i \"%s\"\n", - example->srcline+2, source->fullname); + linemarker = tal_fmt(f, "#line %i \"%s\"\n", + example->srcline+2, source->fullname); write(fd, linemarker, strlen(linemarker)); for (i = 0; i < example->num_lines; i++) { @@ -80,13 +79,12 @@ static void extract_examples(struct manifest *m, } } - /* Check main header. */ + /* Check all headers for examples. */ list_for_each(&m->h_files, f, list) { - if (!strstarts(f->name, m->basename) - || strlen(f->name) != strlen(m->basename) + 2) - continue; + if (strstarts(f->name, m->basename) + && strlen(f->name) == strlen(m->basename) + 2) + mainh = f; - mainh = f; list_for_each(get_ccan_file_docs(f), d, list) { if (streq(d->type, "example")) { score->error = add_example(m, f, d); @@ -116,7 +114,7 @@ struct ccanlint examples_exist = { .key = "examples_exist", .name = "_info and main header file have Example: sections", .check = extract_examples, - .needs = "info_exists" + .needs = "info_exists main_header_exists" }; REGISTER_TEST(examples_exist);