ccanlint: print error information even if we pass.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 15 Nov 2010 02:29:52 +0000 (12:59 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 15 Nov 2010 02:29:52 +0000 (12:59 +1030)
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.

tools/ccanlint/ccanlint.c
tools/ccanlint/ccanlint.h
tools/ccanlint/tests/has_examples.c
tools/ccanlint/tests/idempotent.c

index 8f36c2aa521f2d3c2132c508e367a1376fbbe2fa..a5901ac318b8b00b0a160457e0f51d4370d32f4c 100644 (file)
@@ -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);
        }
 
index 76e14a2aac0c8f9b77631dd4f296b55637dcf495..41a569fab89c8fd906d6951fe635e14e9dae6c97 100644 (file)
@@ -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);
index 7c95777222a992aea510b005d3aa7b735dddb78d..31afaecf3774fd251061489a3be01532d3dcd29a 100644 (file)
@@ -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 = {
index 7ab4a57b7e31080e5630be981de524f4967524c9..bf21b22621339022c17f52448cd213bd5631c4b2 100644 (file)
@@ -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;