diff options
author | Chad Versace <chad.versace@intel.com> | 2015-12-11 10:14:36 -0800 |
---|---|---|
committer | Chad Versace <chad.versace@intel.com> | 2015-12-11 11:28:57 -0800 |
commit | ae271b129cf3f1817b747e1c6c38f84dd8791b7c (patch) | |
tree | af8e08447e5ac67b7a8f0bd5cf2155325705b41c | |
parent | 521ed260890f00fef336234b2eadc00fc0992f33 (diff) |
framework: Support negative testname patterns
-rw-r--r-- | src/framework/runner/runner.c | 25 | ||||
-rw-r--r-- | src/framework/test/test_def.c | 5 |
2 files changed, 27 insertions, 3 deletions
diff --git a/src/framework/runner/runner.c b/src/framework/runner/runner.c index 92326c0..27d4dbd 100644 --- a/src/framework/runner/runner.c +++ b/src/framework/runner/runner.c @@ -119,6 +119,19 @@ runner_run_tests(void) return master_run(runner_num_tests); } +static bool +glob_is_negative(const char *glob) +{ + bool neg = false; + + while (glob && glob[0] == '!') { + ++glob; + neg = !neg; + } + + return neg; +} + void runner_enable_matching_tests(const cru_cstr_vec_t *testname_globs) { @@ -127,17 +140,23 @@ runner_enable_matching_tests(const cru_cstr_vec_t *testname_globs) test_def_t *def; char **glob; - bool include_all = testname_globs->len == 0; + const bool first_glob_is_neg = testname_globs->len > 0 && + glob_is_negative(testname_globs->data[0]); + + const bool implicit_all = testname_globs->len == 0 || first_glob_is_neg; cru_foreach_test_def(def) { bool enable = false; - if (include_all) { + if (implicit_all) { enable = test_def_match(def, "*"); } + // Last matching glob wins. cru_vec_foreach(glob, testname_globs) { - enable = test_def_match(def, *glob); + if (test_def_match(def, *glob)) { + enable = !glob_is_negative(*glob); + } } if (enable) { diff --git a/src/framework/test/test_def.c b/src/framework/test/test_def.c index eb1dcc9..634908d 100644 --- a/src/framework/test/test_def.c +++ b/src/framework/test/test_def.c @@ -32,6 +32,11 @@ bool test_def_match(const test_def_t *def, const char *glob) { + // Strip the leading '!' modifier before performing the match. + while (glob && glob[0] == '!') { + ++glob; + } + if (strncmp("example.", def->name, 8) == 0 && strncmp("example.", glob, 8) != 0) { return false; |