X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fexamples_exist.c;h=073a0b2c215c74e57b1b53cbed309a864c1a5aa9;hp=947d76a4a768751053e6830b4bb788cb2c56df77;hb=509fc838deaf1c53638bcae6c1a826c2f990b827;hpb=051db34fb275491d4d5dfa5bf7970e8e525766d8 diff --git a/tools/ccanlint/tests/examples_exist.c b/tools/ccanlint/tests/examples_exist.c index 947d76a4..073a0b2c 100644 --- a/tools/ccanlint/tests/examples_exist.c +++ b/tools/ccanlint/tests/examples_exist.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -16,10 +17,9 @@ /* Creates and adds an example file. */ static char *add_example(struct manifest *m, struct ccan_file *source, - bool keep, struct doc_section *example) { - char *name; + char *name, *linemarker; unsigned int i; int fd; struct ccan_file *f; @@ -33,7 +33,7 @@ static char *add_example(struct manifest *m, struct ccan_file *source, while (strchr(name, ' ')) *strchr(name, ' ') = '_'; - name = maybe_temp_file(m, ".c", keep, name); + name = temp_file(m, ".c", name); f = new_ccan_file(m, talloc_dirname(m, name), talloc_basename(m, name)); talloc_steal(f, name); list_add_tail(&m->examples, &f->list); @@ -43,12 +43,18 @@ static char *add_example(struct manifest *m, struct ccan_file *source, return talloc_asprintf(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); + write(fd, linemarker, strlen(linemarker)); + for (i = 0; i < example->num_lines; i++) { if (write(fd, example->lines[i], strlen(example->lines[i])) != strlen(example->lines[i]) || write(fd, "\n", 1) != 1) { close(fd); - return "Failure writing to temporary file"; + return cast_const(char *, + "Failure writing to temporary file"); } } close(fd); @@ -57,7 +63,6 @@ static char *add_example(struct manifest *m, struct ccan_file *source, /* FIXME: We should have one example per function in header. */ static void extract_examples(struct manifest *m, - bool keep, unsigned int *timeleft, struct score *score) { @@ -68,7 +73,7 @@ static void extract_examples(struct manifest *m, score->total = 2; list_for_each(get_ccan_file_docs(m->info_file), d, list) { if (streq(d->type, "example")) { - score->error = add_example(m, m->info_file, keep, d); + score->error = add_example(m, m->info_file, d); if (score->error) return; have_info_example = true; @@ -84,7 +89,7 @@ static void extract_examples(struct manifest *m, mainh = f; list_for_each(get_ccan_file_docs(f), d, list) { if (streq(d->type, "example")) { - score->error = add_example(m, f, keep, d); + score->error = add_example(m, f, d); if (score->error) return; have_header_example = true; @@ -92,21 +97,19 @@ static void extract_examples(struct manifest *m, } } + /* We don't fail ccanlint for this. */ + score->pass = true; if (have_info_example && have_header_example) { score->score = score->total; - score->pass = true; return; } - score->error = "Expect examples in header and _info"; if (!have_info_example) score_file_error(score, m->info_file, 0, "No Example: section"); if (!have_header_example) score_file_error(score, mainh, 0, "No Example: section"); score->score = have_info_example + have_header_example; - /* We pass if we find any example. */ - score->pass = score->score != 0; } struct ccanlint examples_exist = {