X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fidempotent.c;h=340a0698ac6aecbcb8baf85d231ce4e4d8d978fc;hp=7ab4a57b7e31080e5630be981de524f4967524c9;hb=2926cafb52b9d95646d9dafa877d53f2368d8b2c;hpb=7a163ea2dcafc056fdafc8c71ef011e2bfdbeb65 diff --git a/tools/ccanlint/tests/idempotent.c b/tools/ccanlint/tests/idempotent.c index 7ab4a57b..340a0698 100644 --- a/tools/ccanlint/tests/idempotent.c +++ b/tools/ccanlint/tests/idempotent.c @@ -24,13 +24,14 @@ static const char explain[] static void fix_name(char *name) { - unsigned int i, j; + unsigned int i; - for (i = j = 0; name[i]; i++) { - if (isalnum(name[i]) || name[i] == '_') - name[j++] = toupper(name[i]); + for (i = 0; name[i]; i++) { + if (isalnum(name[i])) + name[i] = toupper(name[i]); + else + name[i] = '_'; } - name[j] = '\0'; } static void handle_idem(struct manifest *m, struct score *score) @@ -44,10 +45,10 @@ static void handle_idem(struct manifest *m, struct score *score) /* Main header gets CCAN_FOO_H, others CCAN_FOO_XXX_H */ if (strstarts(e->file->name, m->basename) - || strlen(e->file->name) != strlen(m->basename) + 2) + || strlen(e->file->name) == strlen(m->basename) + 2) name = talloc_asprintf(score, "CCAN_%s_H", m->basename); else - name = talloc_asprintf(score, "CCAN_%s_%s_H", + name = talloc_asprintf(score, "CCAN_%s_%s", m->basename, e->file->name); fix_name(name); @@ -90,7 +91,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) @@ -185,17 +185,20 @@ static void check_idempotent(struct manifest *m, list_for_each(&m->h_files, f, list) { if (!check_idem(f, score)) - return; + score->error = "Headers are not idempotent"; + } + if (!score->error) { + score->pass = true; + score->score = score->total; } - score->pass = true; - score->score = score->total; } -struct ccanlint idempotent = { - .key = "idempotent", +struct ccanlint headers_idempotent = { + .key = "headers_idempotent", .name = "Module headers are #ifndef/#define wrapped", .check = check_idempotent, .handle = handle_idem, + .needs = "" }; -REGISTER_TEST(idempotent, NULL); +REGISTER_TEST(headers_idempotent);