From: Rusty Russell Date: Wed, 24 Aug 2011 03:22:46 +0000 (+0930) Subject: ccanlint: allow per-file restrictions, so we don't have to remove all tests. X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=05b39faed2c73b317f6a7f6f59ec0e8c69e5d5bf;hp=05ab011adecfe0ceb82f854a805138f4d235f15c ccanlint: allow per-file restrictions, so we don't have to remove all tests. For example, valgrind can't handle some things, so we may need to switch it off, but we don't want to do that for every test. So, start a standard format for per-file restrictions, eg: Ccanlint: tests_pass_valgrind test/foo.c:FAIL For the moment, only tests_pass_valgrind takes options, so it has to change: we now have a helper which returns the array of options applicable to a given file. --- diff --git a/tools/ccanlint/ccanlint.c b/tools/ccanlint/ccanlint.c index 81f96147..1c060ba7 100644 --- a/tools/ccanlint/ccanlint.c +++ b/tools/ccanlint/ccanlint.c @@ -186,6 +186,8 @@ static bool run_test(struct ccanlint *i, static void register_test(struct list_head *h, struct ccanlint *test) { list_add(h, &test->list); + test->options = talloc_array(NULL, char *, 1); + test->options[0] = NULL; } /** @@ -409,11 +411,30 @@ static char **collapse(char **lines, unsigned int *nump) if (lines[i][0]) lines[j++] = lines[i]; } + lines[j] = NULL; if (nump) *nump = j; return lines; } + +static void add_options(struct ccanlint *test, char **options, + unsigned int num_options) +{ + unsigned int num; + + if (!test->options) + num = 0; + else + /* -1, because last one is NULL. */ + num = talloc_array_length(test->options) - 1; + + test->options = talloc_realloc(NULL, test->options, + char *, + num + num_options + 1); + memcpy(&test->options[num], options, (num_options + 1)*sizeof(char *)); +} + static void add_info_options(struct ccan_file *info, bool mark_fails) { struct doc_section *d; @@ -425,9 +446,10 @@ static void add_info_options(struct ccan_file *info, bool mark_fails) continue; for (i = 0; i < d->num_lines; i++) { + unsigned int num_words; char **words = collapse(strsplit(d, d->lines[i], " \t"), - NULL); - if (!words[0]) + &num_words); + if (num_words == 0) continue; if (strncmp(words[0], "//", 2) == 0) @@ -454,14 +476,49 @@ static void add_info_options(struct ccan_file *info, bool mark_fails) if (!test->takes_options) warnx("%s: %s doesn't take options", info->fullname, words[0]); - /* Copy line exactly into options. */ - test->options = strstr(d->lines[i], words[0]) - + strlen(words[0]); + add_options(test, words+1, num_words-1); } } } } +/* If options are of form "filename: