From: Joel Rosdahl Date: Sat, 17 Jul 2010 20:53:34 +0000 (+0200) Subject: Verify that test (suite) names are valid C identifiers X-Git-Tag: v3.1~148 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fa618764c7ee81d74fd9bdfbca87a21785b0b2db;p=thirdparty%2Fccache.git Verify that test (suite) names are valid C identifiers Two reasons: 1. We may want to use the test names as identifiers in the future. 2. We can safely create and remove directories with such names. --- diff --git a/test/framework.c b/test/framework.c index 7faca1f59..28b280873 100644 --- a/test/framework.c +++ b/test/framework.c @@ -63,6 +63,22 @@ plural_s(unsigned n) return n == 1 ? "" : "s"; } +static void +verify_test_suite_name(const char *name) +{ + const char *p = name; + while (*p) { + if ((*p < '0' || *p > '9') + && (*p < 'A' || *p > 'Z') + && *p != '_' + && (*p < 'a' || *p > 'z')) { + fprintf(stderr, "Bad character ('%c') in suite/test name: %s\n", *p, name); + exit(1); + } + ++p; + } +} + int cct_run(suite_fn *suites, int verbose_output) { @@ -100,6 +116,7 @@ cct_run(suite_fn *suites, int verbose_output) void cct_suite_begin(const char *name) { + verify_test_suite_name(name); if (verbose) { printf("=== SUITE: %s ===\n", name); } @@ -125,6 +142,7 @@ void cct_suite_end() void cct_test_begin(const char *name) { + verify_test_suite_name(name); if (verbose) { printf("--- TEST: %s ---\n", name); }