From: Rusty Russell Date: Mon, 15 Nov 2010 02:29:52 +0000 (+1030) Subject: ccanlint: print error information even if we pass. X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=ca951c94fba731b878f5bb3f81bb99c397dc4e12 ccanlint: print error information even if we pass. This means we can see messages even if we don't fail; ie. for compiler warnings once they are no longer fatal. This means that various tests have to be more careful in not setting score->error. --- diff --git a/tools/ccanlint/ccanlint.c b/tools/ccanlint/ccanlint.c index 8f36c2aa..a5901ac3 100644 --- a/tools/ccanlint/ccanlint.c +++ b/tools/ccanlint/ccanlint.c @@ -149,7 +149,7 @@ static bool run_test(struct ccanlint *i, printf("\n"); } - if (!quiet && !score->pass) { + if ((!quiet && !score->pass) || verbose) { struct file_error *f; if (score->error) @@ -165,7 +165,7 @@ static bool run_test(struct ccanlint *i, else printf("%s\n", f->error); } - if (i->handle) + if (!quiet && !score->pass && i->handle) i->handle(m, score); } diff --git a/tools/ccanlint/ccanlint.h b/tools/ccanlint/ccanlint.h index 76e14a2a..41a569fa 100644 --- a/tools/ccanlint/ccanlint.h +++ b/tools/ccanlint/ccanlint.h @@ -192,7 +192,6 @@ char *get_symbol_token(void *ctx, const char **line); /* Similarly for ->doc_sections */ struct list_head *get_ccan_file_docs(struct ccan_file *f); - /* Add an error about this file (and line, if non-zero) to the score struct */ void score_file_error(struct score *, struct ccan_file *f, unsigned line, const char *error); diff --git a/tools/ccanlint/tests/has_examples.c b/tools/ccanlint/tests/has_examples.c index 7c957772..31afaecf 100644 --- a/tools/ccanlint/tests/has_examples.c +++ b/tools/ccanlint/tests/has_examples.c @@ -61,7 +61,7 @@ static void extract_examples(struct manifest *m, unsigned int *timeleft, struct score *score) { - struct ccan_file *f; + struct ccan_file *f, *mainh = NULL; /* gcc complains uninitialized */ struct doc_section *d; bool have_info_example = false, have_header_example = false; @@ -81,6 +81,7 @@ static void extract_examples(struct manifest *m, || strlen(f->name) != strlen(m->basename) + 2) continue; + 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); @@ -91,23 +92,21 @@ static void extract_examples(struct manifest *m, } } - if (!have_info_example && !have_header_example) { - score->error = "You don't have any Example: sections"; - score->score = 0; - } else if (!have_info_example) { - score->error = "You don't have an Example: section in _info"; - score->score = 1; - score->pass = true; - } else if (!have_header_example) { - score->error = talloc_asprintf(score, - "You don't have an Example: section in %s.h", - m->basename); - score->score = 1; - score->pass = true; - } else { + 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 has_examples = { diff --git a/tools/ccanlint/tests/idempotent.c b/tools/ccanlint/tests/idempotent.c index 7ab4a57b..bf21b226 100644 --- a/tools/ccanlint/tests/idempotent.c +++ b/tools/ccanlint/tests/idempotent.c @@ -90,7 +90,6 @@ static bool check_idem(struct ccan_file *f, struct score *score) /* FIXME: We assume small headers probably uninteresting. */ return true; - score->error = "Headers are not idempotent"; for (i = 0; i < f->num_lines; i++) { if (line_info[i].type == DOC_LINE || line_info[i].type == COMMENT_LINE) @@ -184,8 +183,10 @@ static void check_idempotent(struct manifest *m, struct ccan_file *f; list_for_each(&m->h_files, f, list) { - if (!check_idem(f, score)) + if (!check_idem(f, score)) { + score->error = "Headers are not idempotent"; return; + } } score->pass = true; score->score = score->total;