From fa618764c7ee81d74fd9bdfbca87a21785b0b2db Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sat, 17 Jul 2010 22:53:34 +0200 Subject: [PATCH] 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. --- test/framework.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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); } -- 2.47.3