]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Verify that test (suite) names are valid C identifiers
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 17 Jul 2010 20:53:34 +0000 (22:53 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 17 Jul 2010 20:53:34 +0000 (22:53 +0200)
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

index 7faca1f5915818065818ae50afe618042504b0f1..28b280873cdde2a2aac1f7560af6d83d02bfa8ed 100644 (file)
@@ -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);
        }