Added pattern filtering over parameters

This commit is contained in:
Snaipe 2015-03-22 23:16:09 +01:00
parent 0d64a92b50
commit 8c8d14901e
3 changed files with 22 additions and 0 deletions

View file

@ -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;

View file

@ -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':

View file

@ -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 <stdio.h>
#include <fnmatch.h>
#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) {