From 19720c2c2c448d60534f484c29f07a042d430b89 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 22 Mar 2015 21:32:44 +0100 Subject: [PATCH] Added --fail-fast command-line switch --- include/criterion/options.h | 1 + src/main.c | 5 ++++- src/runner.c | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/criterion/options.h b/include/criterion/options.h index 94829cf..12d9888 100644 --- a/include/criterion/options.h +++ b/include/criterion/options.h @@ -33,6 +33,7 @@ struct criterion_options { bool no_early_exit; bool always_succeed; bool use_ascii; + bool fail_fast; }; extern struct criterion_options criterion_options; diff --git a/src/main.c b/src/main.c index 3911cd7..518faac 100644 --- a/src/main.c +++ b/src/main.c @@ -18,6 +18,7 @@ " -v or --version: prints the version of criterion " \ "these tests have been linked against\n" \ " -l or --list: prints all the tests in a list\n" \ + " -f or --fail-fast: exit after the first failure\n" \ " --ascii: don't use fancy unicode symbols " \ "or colors in the output\n" \ " --tap: enables TAP formatting\n" \ @@ -85,6 +86,7 @@ int main(int argc, char *argv[]) { {"help", no_argument, 0, 'h'}, {"list", no_argument, 0, 'l'}, {"ascii", no_argument, 0, 'k'}, + {"fail-fast", no_argument, 0, 'f'}, {"always-succeed", no_argument, 0, 'y'}, {"no-early-exit", no_argument, 0, 'z'}, {0, 0, 0, 0 } @@ -100,13 +102,14 @@ int main(int argc, char *argv[]) { bool do_list_tests = false; bool do_print_version = false; bool do_print_usage = false; - for (int c; (c = getopt_long(argc, argv, "hvl", opts, NULL)) != -1;) { + for (int c; (c = getopt_long(argc, argv, "hvlf", opts, NULL)) != -1;) { switch (c) { case 'b': criterion_options.logging_threshold = atoi(optarg ?: "1"); break; case 't': criterion_options.enable_tap_format = true; break; case 'y': criterion_options.always_succeed = true; break; 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 'l': do_list_tests = true; break; case 'v': do_print_version = true; break; case 'h': diff --git a/src/runner.c b/src/runner.c index 231bfc9..85b4238 100644 --- a/src/runner.c +++ b/src/runner.c @@ -98,6 +98,8 @@ static void map_tests(struct criterion_test_set *set, struct criterion_global_st FOREACH_SET(struct criterion_test *t, s->tests) { fun(stats, t, &s->suite); + if (criterion_options.fail_fast && stats->tests_failed > 0) + return; if (!is_runner()) return; }