diff --git a/include/criterion/options.h b/include/criterion/options.h index 12d9888..ca622a7 100644 --- a/include/criterion/options.h +++ b/include/criterion/options.h @@ -34,6 +34,7 @@ struct criterion_options { bool always_succeed; bool use_ascii; bool fail_fast; + const char *pattern; }; extern struct criterion_options criterion_options; diff --git a/src/main.c b/src/main.c index 86f1a20..63a6631 100644 --- a/src/main.c +++ b/src/main.c @@ -44,6 +44,8 @@ " -f or --fail-fast: exit after the first failure\n" \ " --ascii: don't use fancy unicode symbols " \ "or colors in the output\n" \ + " --pattern [PATTERN]: run tests matching the " \ + "given pattern\n" \ " --tap: enables TAP formatting\n" \ " --always-succeed: always exit with 0\n" \ " --no-early-exit: do not exit the test worker " \ @@ -110,6 +112,7 @@ int main(int argc, char *argv[]) { {"list", no_argument, 0, 'l'}, {"ascii", no_argument, 0, 'k'}, {"fail-fast", no_argument, 0, 'f'}, + {"pattern", required_argument, 0, 'p'}, {"always-succeed", no_argument, 0, 'y'}, {"no-early-exit", no_argument, 0, 'z'}, {0, 0, 0, 0 } @@ -133,6 +136,7 @@ int main(int argc, char *argv[]) { case 'z': criterion_options.no_early_exit = true; break; case 'k': criterion_options.use_ascii = true; break; case 'f': criterion_options.fail_fast = true; break; + case 'p': criterion_options.pattern = optarg; break; case 'l': do_list_tests = true; break; case 'v': do_print_version = true; break; case 'h': diff --git a/src/report.c b/src/report.c index cd9b68d..7494f0a 100644 --- a/src/report.c +++ b/src/report.c @@ -21,7 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#define _GNU_SOURCE #include +#include #include "criterion/criterion.h" #include "criterion/stats.h" #include "criterion/logging.h" @@ -95,6 +97,21 @@ ReportHook(PRE_TEST)() {} ReportHook(POST_FINI)() {} ReportHook(PRE_ALL)(struct criterion_test_set *set) { + if (criterion_options.pattern) { + FOREACH_SET(struct criterion_suite_set *s, set->suites) { + if ((s->suite.data && s->suite.data->disabled) || !s->tests) + continue; + + FOREACH_SET(struct criterion_test *test, s->tests) { + char *name = NULL; + asprintf(&name, "%s/%s", s->suite.name, test->name); + if (fnmatch(criterion_options.pattern, name, 0)) + test->data->disabled = true; + + free(name); + } + } + } if (criterion_options.enable_tap_format) { size_t enabled_count = 0; FOREACH_SET(struct criterion_suite_set *s, set->suites) {