X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fexamples_compile.c;h=80c5ba631375e58bd24d78463b6aa65139434679;hb=dfecdec7d1d1fb99cb73182a7d8da0e23074a4b2;hp=82b479620c614ba6c1e7d995003b60bdd96a0864;hpb=3cd1d24a9e2e578890951d723e0461ed13444650;p=ccan diff --git a/tools/ccanlint/tests/examples_compile.c b/tools/ccanlint/tests/examples_compile.c index 82b47962..80c5ba63 100644 --- a/tools/ccanlint/tests/examples_compile.c +++ b/tools/ccanlint/tests/examples_compile.c @@ -122,6 +122,7 @@ static char *compile(const void *ctx, "", lib_list(m), file->compiled); if (errmsg) { talloc_free(file->compiled); + file->compiled = NULL; return errmsg; } return NULL; @@ -429,6 +430,7 @@ static struct ccan_file *mangle_example(struct manifest *m, } close(fd); f->contents = talloc_steal(f, contents); + list_add(&m->mangled_examples, &f->list); return f; } @@ -444,41 +446,41 @@ static void *build_examples(struct manifest *m, bool keep, examples_compile.total_score = 0; list_for_each(&m->examples, i, list) { - char *ret, *ret1 = NULL, *ret2; - struct ccan_file *mangle1 = NULL, *mangle2; + char *ret, *ret1, *ret2 = NULL; + struct ccan_file *mangle1, *mangle2 = NULL; examples_compile.total_score++; /* Simplify our dumb parsing. */ strip_leading_whitespace(get_ccan_file_lines(i)); - ret = compile(score, m, i, keep); + ret = compile(i, m, i, keep); if (!ret) { prev = get_ccan_file_lines(i); score->score++; continue; } + /* Try standalone. */ + mangle1 = mangle_example(m, i, get_ccan_file_lines(i), keep); + ret1 = compile(i, m, mangle1, keep); + if (!ret1) { + prev = get_ccan_file_lines(i); + score->score++; + continue; + } + /* Try combining with previous (successful) example... */ if (prev) { char **new = combine(i, get_ccan_file_lines(i), prev); - mangle1 = mangle_example(m, i, new, keep); - ret1 = compile(score, m, mangle1, keep); - if (!ret1) { + mangle2 = mangle_example(m, i, new, keep); + ret2 = compile(i, m, mangle2, keep); + if (!ret2) { prev = new; score->score++; continue; } } - /* Try standalone. */ - mangle2 = mangle_example(m, i, get_ccan_file_lines(i), keep); - ret2 = compile(score, m, mangle2, keep); - if (!ret2) { - prev = get_ccan_file_lines(i); - score->score++; - continue; - } - score->errors = talloc_asprintf_append(score->errors, "%s: tried standalone example:\n" "%s\n" @@ -486,26 +488,32 @@ static void *build_examples(struct manifest *m, bool keep, i->name, get_ccan_file_contents(i), ret); - if (mangle1) { - score->errors = talloc_asprintf_append(score->errors, - "%s: tried combining with" - " previous example:\n" - "%s\n" - "Errors: %s\n\n", - i->name, - get_ccan_file_contents(mangle1), - ret1); - } score->errors = talloc_asprintf_append(score->errors, "%s: tried adding headers, wrappers:\n" "%s\n" "Errors: %s\n\n", i->name, + get_ccan_file_contents(mangle1), + ret1); + + if (mangle2) { + score->errors = talloc_asprintf_append(score->errors, + "%s: tried combining with" + " previous example:\n" + "%s\n" + "Errors: %s\n\n", + i->name, get_ccan_file_contents(mangle2), ret2); + } /* This didn't work, so not a candidate for combining. */ prev = NULL; } + + if (strcmp(score->errors, "") == 0) { + talloc_free(score); + return NULL; + } return score; }