diff options
author | Bardur Arantsson <bardur@scientician.net> | 2015-08-01 16:35:25 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2015-09-14 05:58:27 +0200 |
commit | 7b9f4e4e8169ca2fad3a1c7ca03f07ecfc46678e (patch) | |
tree | 0cef1ac0dc228b621afc90bc94e4e0dddcb90c82 /vendor/bandit/specs | |
parent | c6196b25d119a10e79deedef26a73e0d5a021b0e (diff) |
Bandit 2.0.0
Diffstat (limited to 'vendor/bandit/specs')
19 files changed, 1615 insertions, 31 deletions
diff --git a/vendor/bandit/specs/describe.spec.cpp b/vendor/bandit/specs/describe.spec.cpp index 7578fcac..d4600a28 100644 --- a/vendor/bandit/specs/describe.spec.cpp +++ b/vendor/bandit/specs/describe.spec.cpp @@ -3,7 +3,7 @@ using namespace bandit::fakes; namespace bd = bandit::detail; -go_bandit([](){ +SPEC_BEGIN(describe) describe("describe:", [](){ bandit::detail::voidfunc_t describe_fn; @@ -87,7 +87,7 @@ go_bandit([](){ describe("skip", [&](){ bool context_is_hard_skip; - auto describe_fn = + describe_fn = [&](){ context_is_hard_skip = context_stack->back()->hard_skip(); }; before_each([&](){ @@ -102,7 +102,16 @@ go_bandit([](){ }); }); + + describe("xdescribe", [&](){ + + it("pushes a context marked as skipped on the stack", [&](){ + xdescribe("context name", describe_fn, *reporter, *context_stack); + AssertThat(context_is_hard_skip, IsTrue()); + }); + + }); }); }); -}); +SPEC_END diff --git a/vendor/bandit/specs/fakes/fake_context.h b/vendor/bandit/specs/fakes/fake_context.h index 1161cfc7..e5d1d870 100644 --- a/vendor/bandit/specs/fakes/fake_context.h +++ b/vendor/bandit/specs/fakes/fake_context.h @@ -5,7 +5,8 @@ namespace bandit { namespace fakes { struct fake_context : public bandit::detail::context, public bandit::specs::logging_fake { - fake_context() : hard_skip_(false), name_("fake_context") + fake_context() : hard_skip_(false), name_("fake_context"), + custom_after_each_([](){}), custom_before_each_([](){}) {} const std::string& name() @@ -32,11 +33,13 @@ namespace bandit { namespace fakes { void run_before_eaches() { log() << "run_before_eaches" << std::endl; + custom_before_each_(); } void run_after_eaches() { log() << "run_after_eaches" << std::endl; + custom_after_each_(); } bool hard_skip() @@ -45,9 +48,21 @@ namespace bandit { namespace fakes { return hard_skip_; } + void with_after_each(detail::voidfunc_t call) + { + custom_after_each_ = call; + } + + void with_before_each(detail::voidfunc_t call) + { + custom_before_each_ = call; + } + private: bool hard_skip_; std::string name_; + detail::voidfunc_t custom_after_each_; + detail::voidfunc_t custom_before_each_; }; }} diff --git a/vendor/bandit/specs/it.spec.cpp b/vendor/bandit/specs/it.spec.cpp index b7f5a998..287a1ede 100644 --- a/vendor/bandit/specs/it.spec.cpp +++ b/vendor/bandit/specs/it.spec.cpp @@ -57,6 +57,140 @@ go_bandit([](){ call_it(); AssertThat(context->call_log(), Has().Exactly(1).EqualTo("run_after_eaches")); }); + + describe("but with a failing after_each", [&](){ + + before_each([&](){ + context->with_after_each([](){ AssertThat(2, Equals(3)); }); + }); + + it("tells reporter it's failed", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().Exactly(1).EqualTo("it_failed: my it (Expected: equal to 3 Actual: 2 )")); + }); + + it("doesn't report a succeeding test", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().None().EqualTo("it_succeeded: my it")); + }); + + it("tells run_policy that we have a failing test", [&](){ + call_it(); + AssertThat(run_policy->has_encountered_failure(), IsTrue()); + }); + }); + + describe("but with a std::exception in after_each", [&](){ + + before_each([&](){ + context->with_after_each([](){ throw std::logic_error("logic is wrong!"); }); + }); + + it("tells reporter it's failed", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().Exactly(1).EqualTo("it_failed: my it (exception: logic is wrong!)")); + }); + + it("doesn't report a succeeding test", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().None().EqualTo("it_succeeded: my it")); + }); + + it("tells run_policy that we have a failing test", [&](){ + call_it(); + AssertThat(run_policy->has_encountered_failure(), IsTrue()); + }); + + }); + + describe("but with an unknown error in after_each", [&](){ + + before_each([&](){ + context->with_after_each([](){ throw 25; }); + }); + + it("tells reporter it's failed", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().Exactly(1).EqualTo("it_unknown_error: my it")); + }); + + it("doesn't report a succeeding test", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().None().EqualTo("it_succeeded: my it")); + }); + + it("tells run_policy that we have a failing test", [&](){ + call_it(); + AssertThat(run_policy->has_encountered_failure(), IsTrue()); + }); + }); + + describe("but with a failing before_each", [&](){ + + before_each([&](){ + context->with_before_each([](){ AssertThat(2, Equals(3)); }); + }); + + it("tells reporter it's failed", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().Exactly(1).EqualTo("it_failed: my it (Expected: equal to 3 Actual: 2 )")); + }); + + it("doesn't report a succeeding test", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().None().EqualTo("it_succeeded: my it")); + }); + + it("tells run_policy that we have a failing test", [&](){ + call_it(); + AssertThat(run_policy->has_encountered_failure(), IsTrue()); + }); + }); + + describe("but with a std::exception in before_each", [&](){ + + before_each([&](){ + context->with_before_each([](){ throw std::logic_error("logic is wrong!"); }); + }); + + it("tells reporter it's failed", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().Exactly(1).EqualTo("it_failed: my it (exception: logic is wrong!)")); + }); + + it("doesn't report a succeeding test", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().None().EqualTo("it_succeeded: my it")); + }); + + it("tells run_policy that we have a failing test", [&](){ + call_it(); + AssertThat(run_policy->has_encountered_failure(), IsTrue()); + }); + }); + + describe("but with an unknown error in before_each", [&](){ + + before_each([&](){ + context->with_before_each([](){ throw 25; }); + }); + + it("tells reporter it's failed", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().Exactly(1).EqualTo("it_unknown_error: my it")); + }); + + it("doesn't report a succeeding test", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().None().EqualTo("it_succeeded: my it")); + }); + + it("tells run_policy that we have a failing test", [&](){ + call_it(); + AssertThat(run_policy->has_encountered_failure(), IsTrue()); + }); + }); + }); describe("with failing test", [&](){ @@ -79,11 +213,16 @@ go_bandit([](){ AssertThat(context->call_log(), Has().Exactly(1).EqualTo("run_after_eaches")); }); + it("tells run_policy that we have a failing test", [&](){ + call_it(); + AssertThat(run_policy->has_encountered_failure(), IsTrue()); + }); }); + describe("with crashing test", [&](){ before_each([&](){ - it_func = [](){ throw std::logic_error("serious crash"); }; + it_func = [](){ throw 44; }; }); it("tells reporter it's failed", [&](){ @@ -100,6 +239,39 @@ go_bandit([](){ call_it(); AssertThat(context->call_log(), Has().Exactly(1).EqualTo("run_after_eaches")); }); + + it("tells run_policy that we have a failing test", [&](){ + call_it(); + AssertThat(run_policy->has_encountered_failure(), IsTrue()); + }); + }); + + describe("with test throwing exception based on 'std::exception'", [&](){ + + before_each([&](){ + it_func = [](){ throw std::logic_error("logic error"); }; + }); + + it("tells reporter it's failed", [&](){ + call_it(); + AssertThat(reporter->call_log(), Has().Exactly(1).EqualTo("it_failed: my it (exception: logic error)")); + }); + + it("calls before_each in context", [&](){ + call_it(); + AssertThat(context->call_log(), Has().Exactly(1).EqualTo("run_before_eaches")); + }); + + it("calls after_each in context", [&](){ + call_it(); + AssertThat(context->call_log(), Has().Exactly(1).EqualTo("run_after_eaches")); + }); + + it("tells run_policy that we have a failing test", [&](){ + call_it(); + AssertThat(run_policy->has_encountered_failure(), IsTrue()); + }); + }); describe("it_skip", [&](){ @@ -117,6 +289,21 @@ go_bandit([](){ }); + describe("xit", [&](){ + + it("tells reporter it's skipped", [&](){ + xit("my it", [](){}, *reporter); + AssertThat(reporter->call_log(), Has().Exactly(1).EqualTo("it_skip: my it")); + }); + + it("doesn't call function", [&](){ + bool called = false; + xit("my it", [&](){ called = true; }, *reporter); + AssertThat(called, IsFalse()); + }); + + }); + describe("with a run policy that says to skip this 'it'", [&](){ bool it_was_called; diff --git a/vendor/bandit/specs/matchers/be_close_to.cpp b/vendor/bandit/specs/matchers/be_close_to.cpp new file mode 100644 index 00000000..64309673 --- /dev/null +++ b/vendor/bandit/specs/matchers/be_close_to.cpp @@ -0,0 +1,112 @@ +#include <specs/specs.h> + +using namespace bandit::Matchers; + +SPEC_BEGIN(Matchers::BeCloseTo) + +describe("be_close_to matcher", []{ + describe("when the actual value is declared as a float", [&]{ + float actualValue = 2.0 / 3.0; + + describe("and the expected value is also a float", [&]{ + float expectedValue; + + describe("with an explicit threshold", [&]{ + float threshold = 0.1; + + describe("and the values are within the given threshold", [&]{ + before_each([&]{ + expectedValue = 2.0 / 3.0 + 0.01; + }); + + it("must accept a positive match", [&]{ + actualValue must be_close_to(expectedValue).within(threshold); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_close_to(expectedValue).within(threshold); }()); + }); + }); + + describe("and the values are not within the given threshold", [&]{ + before_each([&]{ + expectedValue = 2.0 / 3.0 + 0.2; + }); + + it("must accept a negative match", [&]{ + actualValue must_not be_close_to(expectedValue).within(threshold); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_close_to(expectedValue).within(threshold); }()); + }); + }); + }); + + describe("without an explicit threshold", [&]{ + describe("and the values are within the default threshold", [&]{ + before_each([&]{ + expectedValue = 2.0 / 3.0 + 0.000001; + }); + + it("must accept a positive match", [&]{ + actualValue must be_close_to(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_close_to(expectedValue); }()); + }); + }); + + describe("and the values are not within the default threshold", [&]{ + before_each([&]{ + expectedValue = 2.0 / 3.0 + 0.1; + }); + + it("must accept a negative match", [&]{ + actualValue must_not be_close_to(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_close_to(expectedValue); }()); + }); + }); + }); + }); + + describe("and the expected value is a compatible non-float type", [&]{ + int expectedValue; + float threshold = 1; + + describe("and the values are within the given threshold", [&]{ + before_each([&]{ + expectedValue = 1; + }); + + it("must accept a positive match", [&]{ + actualValue must be_close_to(expectedValue).within(threshold); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_close_to(expectedValue).within(threshold); }()); + }); + }); + + describe("and the values are not within the given threshold", [&]{ + before_each([&]{ + expectedValue = 5; + }); + + it("must accept a negative match", [&]{ + actualValue must_not be_close_to(expectedValue).within(threshold); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_close_to(expectedValue).within(threshold); }()); + }); + }); + }); + }); +}); + +SPEC_END diff --git a/vendor/bandit/specs/matchers/be_empty.cpp b/vendor/bandit/specs/matchers/be_empty.cpp new file mode 100644 index 00000000..3ed4a6f9 --- /dev/null +++ b/vendor/bandit/specs/matchers/be_empty.cpp @@ -0,0 +1,89 @@ +#include <set> + +#include <specs/specs.h> + +using namespace bandit::Matchers; + +SPEC_BEGIN(Matchers::BeEmpty) + +describe("be_empty matcher", [&]{ + describe("when the value is an STL vector", [&]{ + describe("which is empty", [&]{ + std::vector<int> container; + + it("must pass a positive match", [&]{ + container must be_empty; + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not be_empty; }()); + }); + }); + + describe("which is not empty", [&]{ + std::vector<int> container {2, 7}; + + it("must pass a negative match", [&]{ + container must_not be_empty; + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must be_empty; }()); + }); + }); + }); + + describe("when the value is an STL map", [&]{ + describe("which is empty", [&]{ + std::map<int, int> container; + + it("must pass a positive match", [&]{ + container must be_empty; + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not be_empty; }()); + }); + }); + + describe("which is not empty", [&]{ + std::map<int, int> container {{5, 6}, {7,10}}; + + it("must pass a negative match", [&]{ + container must_not be_empty; + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must be_empty; }()); + }); + }); + }); + + describe("when the value is an STL set", [&]{ + describe("which is empty", [&]{ + std::set<int> container; + + it("must pass a positive match", [&]{ + container must be_empty; + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not be_empty; }()); + }); + }); + + describe("which is not empty", [&]{ + std::set<int> container {5, 7}; + + it("must pass a negative match", [&]{ + container must_not be_empty; + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must be_empty; }()); + }); + }); + }); +}); + +SPEC_END diff --git a/vendor/bandit/specs/matchers/be_falsy.cpp b/vendor/bandit/specs/matchers/be_falsy.cpp new file mode 100644 index 00000000..d8c71c1b --- /dev/null +++ b/vendor/bandit/specs/matchers/be_falsy.cpp @@ -0,0 +1,85 @@ +#include <specs/specs.h> + +using namespace bandit::Matchers; + +SPEC_BEGIN(Matchers::BeFalsy) + +describe("be_falsy matcher", [&]{ + describe("when the value is a built-in type", [&]{ + bool value; + + describe("which evaluates to false", [&]{ + before_each([&]{ + value = false; + }); + + it("must accept a positive match", [&]{ + value must be_falsy; + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ value must_not be_falsy; }()); + }); + }); + + describe("which evaluates to true", [&]{ + before_each([&]{ + value = true; + }); + + it("must accept a negative match", [&]{ + value must_not be_falsy; + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ value must be_falsy; }()); + }); + }); + }); + + describe("when the value is nullptr", [&]{ + auto value = nullptr; + + it("must accept a positive match", [&]{ + value must be_falsy; + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ value must_not be_falsy; }()); + }); + }); + + describe("when the value is a pointer", [&]{ + char* value; + + describe("which evaluates to false", [&]{ + before_each([&]{ + value = NULL; + }); + + it("must accept a positive match", [&]{ + value must be_falsy; + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ value must_not be_falsy; }()); + }); + }); + + describe("which evaluates to true", [&]{ + before_each([&]{ + value = (char*)"cat"; + }); + + it("must accept a negative match", [&]{ + value must_not be_falsy; + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ value must be_falsy; }()); + }); + }); + }); +}); + +SPEC_END diff --git a/vendor/bandit/specs/matchers/be_greater_than.cpp b/vendor/bandit/specs/matchers/be_greater_than.cpp new file mode 100644 index 00000000..17a97fe3 --- /dev/null +++ b/vendor/bandit/specs/matchers/be_greater_than.cpp @@ -0,0 +1,105 @@ +#include <specs/specs.h> + +using namespace bandit::Matchers; + +SPEC_BEGIN(Matchers::BeGreaterThan) + +describe("be_greater_than matcher", []{ + describe("when the actual value is a built-in type", [&]{ + int actualValue = 10; + + describe("and the expected value is the same built-in type", [&]{ + int expectedValue; + + describe("and the actual value is greater than the expected value", [&]{ + before_each([&]{ + expectedValue = 1; + }); + + it("must pass a positive match", [&]{ + actualValue must be_greater_than(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_greater_than(expectedValue); }()); + }); + }); + + describe("and the actual value is less than the expected value", [&]{ + before_each([&]{ + expectedValue = 100; + }); + + it("must pass a negative match", [&]{ + actualValue must_not be_greater_than(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_greater_than(expectedValue); }()); + }); + }); + + describe("and the actual value equals the expected value", [&]{ + before_each([&]{ + expectedValue = actualValue; + }); + + it("must pass a negative match", [&]{ + actualValue must_not be_greater_than(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_greater_than(expectedValue); }()); + }); + }); + }); + + describe("and the expected value is a different, but comparable, built-in type", [&]{ + float expectedValue; + + describe("and the actual value is greater than the expected value", [&]{ + before_each([&]{ + expectedValue = 1.1; + }); + + it("must pass a positive match", [&]{ + actualValue must be_greater_than(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_greater_than(expectedValue); }()); + }); + }); + + describe("and the actual value is less than the expected value", [&]{ + before_each([&]{ + expectedValue = 100.1; + }); + + it("must pass a negative match", [&]{ + actualValue must_not be_greater_than(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_greater_than(expectedValue); }()); + }); + }); + + describe("and the actual value equals the expected value", [&]{ + before_each([&]{ + expectedValue = actualValue; + }); + + it("must pass a negative match", [&]{ + actualValue must_not be_greater_than(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_greater_than(expectedValue); }()); + }); + }); + }); + }); +}); + +SPEC_END diff --git a/vendor/bandit/specs/matchers/be_gte.cpp b/vendor/bandit/specs/matchers/be_gte.cpp new file mode 100644 index 00000000..f0e18313 --- /dev/null +++ b/vendor/bandit/specs/matchers/be_gte.cpp @@ -0,0 +1,120 @@ +#include <specs/specs.h> + +using namespace bandit::Matchers; + + +SPEC_BEGIN(Matchers::BeGTE) + +describe("be_gte matcher", [&]{ + int someInteger = 10; + + describe("when the actual value is a built-in type", [&]{ + int actualValue = someInteger; + + describe("and the expected value is the same built-in type", [&]{ + int expectedValue; + + describe("and the actual value is greater than the expected value", [&]{ + before_each([&]{ + expectedValue = 1; + }); + + it("must pass a positive match", [&]{ + actualValue must be_gte(expectedValue); + actualValue must be_greater_than_or_equal_to(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_gte(expectedValue); }()); + AssertThrows(std::exception, [&]{ actualValue must_not be_greater_than_or_equal_to(expectedValue); }()); + }); + }); + + describe("and the actual value is less than the expected value", [&]{ + before_each([&]{ + expectedValue = 100; + }); + + it("must pass a negative match", [&]{ + actualValue must_not be_gte(expectedValue); + actualValue must_not be_greater_than_or_equal_to(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_gte(expectedValue); }()); + AssertThrows(std::exception, [&]{ actualValue must be_greater_than_or_equal_to(expectedValue); }()); + }); + }); + + describe("and the actual value equals the expected value", [&]{ + before_each([&]{ + expectedValue = actualValue; + }); + + it("must pass a positive match", [&]{ + actualValue must be_gte(expectedValue); + actualValue must be_greater_than_or_equal_to(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_gte(expectedValue); }()); + AssertThrows(std::exception, [&]{ actualValue must_not be_greater_than_or_equal_to(expectedValue); }()); + }); + }); + }); + + describe("and the expected value is a different, but comparable, built-in type", [&]{ + float expectedValue; + + describe("and the actual value is greater than the expected value", [&]{ + before_each([&]{ + expectedValue = 1.1; + }); + + it("must pass a positive match", [&]{ + actualValue must be_gte(expectedValue); + actualValue must be_greater_than_or_equal_to(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_gte(expectedValue); }()); + AssertThrows(std::exception, [&]{ actualValue must_not be_greater_than_or_equal_to(expectedValue); }()); + }); + }); + + describe("and the actual value is less than the expected value", [&]{ + before_each([&]{ + expectedValue = 100.1; + }); + + it("must pass a negative match", [&]{ + actualValue must_not be_gte(expectedValue); + actualValue must_not be_greater_than_or_equal_to(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_gte(expectedValue); }()); + AssertThrows(std::exception, [&]{ actualValue must be_greater_than_or_equal_to(expectedValue); }()); + }); + }); + + describe("and the actual value equals the expected value", [&]{ + before_each([&]{ + expectedValue = someInteger / 1.0; + }); + + it("must pass a positive match", [&]{ + actualValue must be_gte(expectedValue); + actualValue must be_greater_than_or_equal_to(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_gte(expectedValue); }()); + AssertThrows(std::exception, [&]{ actualValue must_not be_greater_than_or_equal_to(expectedValue); }()); + }); + }); + }); + }); +}); + +SPEC_END diff --git a/vendor/bandit/specs/matchers/be_less_than.cpp b/vendor/bandit/specs/matchers/be_less_than.cpp new file mode 100644 index 00000000..30f60c47 --- /dev/null +++ b/vendor/bandit/specs/matchers/be_less_than.cpp @@ -0,0 +1,105 @@ +#include <specs/specs.h> + +using namespace bandit::Matchers; + +SPEC_BEGIN(Matchers::BeLessThan) + +describe("be_less_than matcher", []{ + describe("when the actual value is a built-in type", [&]{ + int actualValue = 10; + + describe("and the expected value is the same built-in type", [&]{ + int expectedValue; + + describe("and the actual value is greater than the expected value", [&]{ + before_each([&]{ + expectedValue = 1; + }); + + it("must pass a negative match", [&]{ + actualValue must_not be_less_than(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_less_than(expectedValue); }()); + }); + }); + + describe("and the actual value is less than the expected value", [&]{ + before_each([&]{ + expectedValue = 100; + }); + + it("must pass a positive match", [&]{ + actualValue must be_less_than(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_less_than(expectedValue); }()); + }); + }); + + describe("and the actual value equals the expected value", [&]{ + before_each([&]{ + expectedValue = actualValue; + }); + + it("must pass a negative match", [&]{ + actualValue must_not be_less_than(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_less_than(expectedValue); }()); + }); + }); + }); + + describe("and the expected value is a different, but comparable, built-in type", [&]{ + float expectedValue; + + describe("and the actual value is greater than the expected value", [&]{ + before_each([&]{ + expectedValue = 1.1; + }); + + it("must pass a negative match", [&]{ + actualValue must_not be_less_than(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_less_than(expectedValue); }()); + }); + }); + + describe("and the actual value is less than the expected value", [&]{ + before_each([&]{ + expectedValue = 100.1; + }); + + it("must pass a positive match", [&]{ + actualValue must be_less_than(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_less_than(expectedValue); }()); + }); + }); + + describe("and the actual value equals the expected value", [&]{ + before_each([&]{ + expectedValue = actualValue; + }); + + it("must pass a negative match", [&]{ + actualValue must_not be_less_than(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_less_than(expectedValue); }()); + }); + }); + }); + }); +}); + +SPEC_END diff --git a/vendor/bandit/specs/matchers/be_lte.cpp b/vendor/bandit/specs/matchers/be_lte.cpp new file mode 100644 index 00000000..443ac1c5 --- /dev/null +++ b/vendor/bandit/specs/matchers/be_lte.cpp @@ -0,0 +1,119 @@ +#include <specs/specs.h> + +using namespace bandit::Matchers; + +SPEC_BEGIN(Matchers::BeLTE) + +describe("be_lte matcher", [&]{ + int someInteger = 10; + + describe("when the actual value is a built-in type", [&]{ + int actualValue = someInteger; + + describe("and the expected value is the same built-in type", [&]{ + int expectedValue; + + describe("and the actual value is greater than the expected value", [&]{ + before_each([&]{ + expectedValue = 1; + }); + + it("must pass a negative match", [&]{ + actualValue must_not be_lte(expectedValue); + actualValue must_not be_less_than_or_equal_to(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_lte(expectedValue); }()); + AssertThrows(std::exception, [&]{ actualValue must be_less_than_or_equal_to(expectedValue); }()); + }); + }); + + describe("and the actual value is less than the expected value", [&]{ + before_each([&]{ + expectedValue = 100; + }); + + it("must pass a positive match", [&]{ + actualValue must be_lte(expectedValue); + actualValue must be_less_than_or_equal_to(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_lte(expectedValue); }()); + AssertThrows(std::exception, [&]{ actualValue must_not be_less_than_or_equal_to(expectedValue); }()); + }); + }); + + describe("and the actual value equals the expected value", [&]{ + before_each([&]{ + expectedValue = actualValue; + }); + + it("must pass a positive match", [&]{ + actualValue must be_lte(expectedValue); + actualValue must be_less_than_or_equal_to(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_lte(expectedValue); }()); + AssertThrows(std::exception, [&]{ actualValue must_not be_less_than_or_equal_to(expectedValue); }()); + }); + }); + }); + + describe("and the expected value is a different, but comparable, built-in type", [&]{ + float expectedValue; + + describe("and the actual value is greater than the expected value", [&]{ + before_each([&]{ + expectedValue = 1.1; + }); + + it("must pass a negative match", [&]{ + actualValue must_not be_lte(expectedValue); + actualValue must_not be_less_than_or_equal_to(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must be_lte(expectedValue); }()); + AssertThrows(std::exception, [&]{ actualValue must be_less_than_or_equal_to(expectedValue); }()); + }); + }); + + describe("and the actual value is less than the expected value", [&]{ + before_each([&]{ + expectedValue = 100.1; + }); + + it("must pass a positive match", [&]{ + actualValue must be_lte(expectedValue); + actualValue must be_less_than_or_equal_to(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_lte(expectedValue); }()); + AssertThrows(std::exception, [&]{ actualValue must_not be_less_than_or_equal_to(expectedValue); }()); + }); + }); + + describe("and the actual value equals the expected value", [&]{ + before_each([&]{ + expectedValue = someInteger / 1.0; + }); + + it("must pass a positive match", [&]{ + actualValue must be_lte(expectedValue); + actualValue must be_less_than_or_equal_to(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not be_lte(expectedValue); }()); + AssertThrows(std::exception, [&]{ actualValue must_not be_less_than_or_equal_to(expectedValue); }()); + }); + }); + }); + }); +}); + +SPEC_END diff --git a/vendor/bandit/specs/matchers/be_null.cpp b/vendor/bandit/specs/matchers/be_null.cpp new file mode 100644 index 00000000..ae3cd40d --- /dev/null +++ b/vendor/bandit/specs/matchers/be_null.cpp @@ -0,0 +1,43 @@ +#include <specs/specs.h> + +using namespace bandit::Matchers; + +SPEC_BEGIN(Matchers::BeNull) + +describe("be_null matcher", [&]{ + describe("when the value is a pointer to a built-in type", [&]{ + int* value; + + describe("which is NULL", [&]{ + before_each([&]{ + value = NULL; + }); + + it("must pass a positive match", [&]{ + value must be_null; + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ value must_not be_null; }()); + }); + }); + + describe("which is not NULL", [&]{ + int i = 7; + + before_each([&]{ + value = &i; + }); + + it("must pass a negative match", [&]{ + value must_not be_null; + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ value must be_null; }()); + }); + }); + }); +}); + +SPEC_END diff --git a/vendor/bandit/specs/matchers/be_truthy.cpp b/vendor/bandit/specs/matchers/be_truthy.cpp new file mode 100644 index 00000000..5e583fbf --- /dev/null +++ b/vendor/bandit/specs/matchers/be_truthy.cpp @@ -0,0 +1,85 @@ +#include <specs/specs.h> + +using namespace bandit::Matchers; + +SPEC_BEGIN(Matchers::BeTruthy) + +describe("be_truthy matcher", [&]{ + describe("when the value is a built-in type", [&]{ + bool value; + + describe("which evaluates to false", [&]{ + before_each([&]{ + value = false; + }); + + it("must accept a negative match", [&]{ + value must_not be_truthy; + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ value must be_truthy; }()); + }); + }); + + describe("which evaluates to true", [&]{ + before_each([&]{ + value = true; + }); + + it("must accept a positive match", [&]{ + value must be_truthy; + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ value must_not be_truthy; }()); + }); + }); + }); + + describe("when the value is nullptr", [&]{ + auto value = nullptr; + + it("must accept a negative match", [&]{ + value must_not be_truthy; + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ value must be_truthy; }()); + }); + }); + + describe("when the value is a pointer", [&]{ + char* value; + + describe("which evaluates to false", [&]{ + before_each([&]{ + value = NULL; + }); + + it("must accept a negative match", [&]{ + value must_not be_truthy; + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ value must be_truthy; }()); + }); + }); + + describe("which evaluates to true", [&]{ + before_each([&]{ + value = (char*)"cat"; + }); + + it("must accept a positive match", [&]{ + value must be_truthy; + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ value must_not be_truthy; }()); + }); + }); + }); +}); + +SPEC_END diff --git a/vendor/bandit/specs/matchers/contain.cpp b/vendor/bandit/specs/matchers/contain.cpp new file mode 100644 index 00000000..2c0b4b3b --- /dev/null +++ b/vendor/bandit/specs/matchers/contain.cpp @@ -0,0 +1,156 @@ +#include <set> + +#include <specs/specs.h> + +using namespace bandit::Matchers; + +SPEC_BEGIN(Matchers::Contain) + +describe("contain matcher", [&]{ + std::string element0("element0"); + std::string element1("element1"); + + describe("when the container is an STL vector", [&]{ + describe("which contains the element", [&]{ + std::vector<std::string> container {element0, element1}; + + it("must pass a positive match", [&]{ + container must contain(element1); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not contain(element1); }()); + }); + }); + + describe("which does not contain the element", [&]{ + std::vector<int> container; + + it("must pass a negative match", [&]{ + container must_not contain(4); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must contain(4); }()); + }); + }); + }); + + describe("when the container is an STL map", [&]{ + describe("which contains the expected key", [&]{ + std::map<int, int> container {{5, 6}, {7,10}}; + + it("must pass a positive match", [&]{ + container must contain(5); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not contain(5); }()); + }); + }); + + describe("which does not contain the expected value", [&]{ + std::map<int, int> container; + + it("must pass a negative match", [&]{ + container must_not contain(6); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must contain(6); }()); + }); + }); + }); + + describe("when the container is an STL set", [&]{ + describe("which contains the element", [&]{ + std::set<int> container {5, 7}; + + it("must pass a positive match", [&]{ + container must contain(7); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not contain(7); }()); + }); + }); + + describe("which does not contain the element", [&]{ + std::set<int> container; + + it("must pass a negative match", [&]{ + container must_not contain(7); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must contain(7); }()); + }); + }); + }); + + describe("when the container is a C string", [&]{ + describe("which is null", [&]{ + char* container = NULL; + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must contain("foo"); }()); + }); + }); + + describe("which contains the substring", [&]{ + char* container = (char*)"jack and jill"; + char* element = (char*)"jack"; + + it("must pass a positive match", [&]{ + container must contain(element); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not contain(element); }()); + }); + }); + + describe("which does not contain the substring", [&]{ + char* container = (char*)"batman and robin"; + char* element = (char*)"catwoman"; + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must contain(element); }()); + }); + + it("must pass a negative match", [&]{ + container must_not contain(element); + }); + }); + }); + + describe("when the container is a const C string", [&]{ + describe("which contains the substring", [&]{ + const char* container = (char*)"jack and jill"; + const char* element = (char*)"jack"; + + it("must pass a positive match", [&]{ + container must contain(element); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not contain(element); }()); + }); + }); + + describe("which does not contain the substring", [&]{ + const char* container = (char*)"batman and robin"; + const char* element = (char*)"catwoman"; + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must contain(element); }()); + }); + + it("must pass a negative match", [&]{ + container must_not contain(element); + }); + }); + }); +}); + +SPEC_END diff --git a/vendor/bandit/specs/matchers/equal.cpp b/vendor/bandit/specs/matchers/equal.cpp new file mode 100644 index 00000000..f7f31b0b --- /dev/null +++ b/vendor/bandit/specs/matchers/equal.cpp @@ -0,0 +1,214 @@ +#include <specs/specs.h> + +using namespace bandit::Matchers; + +SPEC_BEGIN(Matchers::Equal) + +describe("when the actual value is a built-in type", []{ + int actualValue = 1; + + describe("and the expected value is the same built-in type", [&]{ + int expectedValue; + + describe("and the values are equal", [&]{ + before_each([&]{ + expectedValue = 1; + }); + + it("must accept a positive match", [&]{ + actualValue must equal(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not equal(expectedValue); }()); + }); + }); + + describe("and the values are not equal", [&]{ + before_each([&]{ + expectedValue = 147; + }); + + it("must accept a negative match", [&]{ + actualValue must_not equal(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must equal(expectedValue); }()); + }); + }); + }); + + describe("and the expected value is a different, but comparable, built-in type", [&]{ + long int expectedValue; + + describe("and the values are equal", [&]{ + before_each([&]{ + expectedValue = 1; + }); + + it("must accept a positive match", [&]{ + actualValue must equal(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not equal(expectedValue); }()); + }); + }); + + describe("and the values are not equal", [&]{ + before_each([&]{ + expectedValue = 42; + }); + + it("must accept a negative match", [&]{ + actualValue must_not equal(expectedValue); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must equal(expectedValue); }()); + }); + }); + }); +}); + +describe("when the actual value is declared as a C string", []{ + char* actualValue = (char*)"actualValue"; + + describe("and the expected value is declared as a C string", [&]{ + std::unique_ptr<char> expectedValue; + + before_each([&]{ + expectedValue.reset((char*)calloc(strlen(actualValue) + 1, sizeof(char))); + }); + + describe("and the values are equal", [&]{ + before_each([&]{ + stpcpy(expectedValue.get(), actualValue); + }); + + it("must accept a positive match", [&]{ + actualValue must equal(expectedValue.get()); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not equal(expectedValue.get()); }()); + }); + }); + + describe("and the values are not equal", [&]{ + before_each([&]{ + stpcpy(expectedValue.get(), "expectedVal"); + }); + + it("must accept a negative match", [&]{ + actualValue must_not equal(expectedValue.get()); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must equal(expectedValue.get()); }()); + }); + }); + }); + + describe("and the expected value is declared as a const C string", [&]{ + const char *expectedValue; + + describe("and the values are equal", [&]{ + before_each([&]{ + expectedValue = "actualValue"; + }); + + it("must accept a positive match", [&]{ + actualValue must equal(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not equal(expectedValue); }()); + }); + }); + }); + + describe("when the expected value is a unique_ptr to a C string", [&]{ + std::unique_ptr<char> expectedValue; + + before_each([&]{ + expectedValue.reset((char*)calloc(strlen(actualValue) + 1, sizeof(char))); + }); + + describe("and the values are equal", [&]{ + before_each([&]{ + stpcpy(expectedValue.get(), actualValue); + }); + + it("must accept a positive match", [&]{ + actualValue must equal(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not equal(expectedValue); }()); + }); + }); + }); +}); + +describe("when the actual value is a unique_ptr", []{ + std::unique_ptr<char> actualValue; + auto expectedValue = (char*)"expectedValue"; + + before_each([&]{ + actualValue.reset((char*)calloc(strlen(expectedValue) + 1, sizeof(char))); + }); + + describe("when the strings are equal", [&]{ + before_each([&]{ + stpcpy(actualValue.get(), expectedValue); + }); + + it("must accept a positive match", [&]{ + actualValue must equal(expectedValue); + }); + }); + + describe("when the strings are not equal", [&]{ + before_each([&]{ + stpcpy(actualValue.get(), "hello"); + }); + + it("must accept a negative match", [&]{ + actualValue must_not equal(expectedValue); + }); + }); +}); + +describe("when the actual value is declared as char array", []{ + describe("and the expected value is declared as a C string", []{ + char actualValue[] = "actualValue"; + + describe("and the values are equal", [&]{ + char* expectedValue = (char*)"actualValue"; + + it("must accept a positive match", [&]{ + actualValue must equal(expectedValue); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must_not equal(expectedValue); }()); + }); + }); + + describe("and the values are not equal", [&]{ + char* expectedValue = (char*)"expectedValue"; + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ actualValue must equal(expectedValue); }()); + }); + + it("must accept a negative match", [&]{ + actualValue must_not equal(expectedValue); + }); + }); + }); +}); + +SPEC_END
\ No newline at end of file diff --git a/vendor/bandit/specs/matchers/throw_exception.cpp b/vendor/bandit/specs/matchers/throw_exception.cpp new file mode 100644 index 00000000..c7531d5f --- /dev/null +++ b/vendor/bandit/specs/matchers/throw_exception.cpp @@ -0,0 +1,104 @@ +#include <specs/specs.h> + +using namespace bandit::Matchers; + +SPEC_BEGIN(Matchers::ThrowException) + +describe("throw_exception", []{ + describe("when no exception is specified", [&]{ + std::exception exception; + + std::function<void()> exception_block = [&]{ throw exception; }; + + describe("when the block throws an exception", [&]{ + it("must pass a positive match", [&]{ + exception_block must throw_exception; + }); + + it("must reject a negative match", [&]{ + AssertThrows(MatcherException, [&]{ exception_block must_not throw_exception; }()); + }); + }); + + describe("when the block does not throw an exception", [&]{ + std::function<void()> quiet_block = [&]{}; + + it("must pass a negative match", [&]{ + quiet_block must_not throw_exception; + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ quiet_block must throw_exception; }()); + }); + }); + }); + + describe("with an exception class specified", [&]{ + std::logic_error expected_exception("logic_error"); + + describe("when the block throws the expected exception", [&]{ + std::function<void()> exception_block = [&]{ throw expected_exception; }; + + it("must pass a positive match", [&]{ + exception_block must throw_exception.operator()<decltype(expected_exception)>(); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ exception_block must_not throw_exception.operator()<decltype(expected_exception)>(); }()); + }); + }); + + // TODO: Because C++ lacks reflection, there's no way to implement + // subclass-checking. I'm leaving these tests here for when the + // language has evolved sufficiently. + xdescribe("when the block throws a sublass of the specified exception", [&]{ + std::function<void()> subclass_block = [&]{ throw std::invalid_argument("invalid argument"); }; + + describe("when subclasses are expected", [&]{ + it("must pass a positive match", [&]{ + subclass_block must throw_exception.operator()<std::logic_error>().or_subclass(); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ subclass_block must_not throw_exception.operator()<std::logic_error>().or_subclass(); }()); + }); + }); + + describe("when subclasses are not expected", [&]{ + it("must pass a negative match", [&]{ + subclass_block must_not throw_exception.operator()<std::logic_error>(); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ subclass_block must throw_exception.operator()<std::logic_error>(); }()); + }); + }); + }); + + describe("when the block throws an unrelated exception", [&]{ + std::function<void()> unrelated_block = [&]{ throw std::range_error("range error"); }; + + it("must pass a negative match", [&]{ + unrelated_block must_not throw_exception.operator()<decltype(expected_exception)>(); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ unrelated_block must throw_exception.operator()<decltype(expected_exception)>(); }()); + }); + }); + + describe("when the block does not throw an exception", [&]{ + std::function<void()> quiet_block = [&]{}; + + it("must pass a negative match", [&]{ + quiet_block must_not throw_exception.operator()<decltype(expected_exception)>(); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ quiet_block must throw_exception.operator()<decltype(expected_exception)>(); }()); + }); + }); + }); +}); + +SPEC_END diff --git a/vendor/bandit/specs/options.spec.cpp b/vendor/bandit/specs/options.spec.cpp index 02e2818c..74d057ec 100644 --- a/vendor/bandit/specs/options.spec.cpp +++ b/vendor/bandit/specs/options.spec.cpp @@ -6,7 +6,7 @@ namespace bd = bandit::detail; go_bandit([](){ describe("options:", [&](){ - + it("parses the '--help' option", [&](){ const char* args[] = {"executable", "--help"}; argv_helper argv(2, args); @@ -82,12 +82,20 @@ go_bandit([](){ AssertThat(opt.only(), Equals("")); }); + it("parses the '--break-on-failure' oprtion", [&](){ + const char* args[] = {"executable", "--break-on-failure"}; + argv_helper argv(2, args); + + bd::options opt(argv.argc(), argv.argv()); + + AssertThat(opt.break_on_failure(), IsTrue()); + }); + describe("with no arguments", [&](){ const char* args[] = {"executable"}; argv_helper argv(1, args); bd::options opt(argv.argc(), argv.argv()); - it("cannot find '--help'", [&](){ AssertThat(opt.help(), IsFalse()); }); @@ -95,11 +103,15 @@ go_bandit([](){ it("cannot find '--version'", [&](){ AssertThat(opt.version(), IsFalse()); }); - + it("cannot find '--no-color'", [&](){ AssertThat(opt.no_color(), IsFalse()); }); + it("cannot fine '--break-on-failure'", [&](){ + AssertThat(opt.break_on_failure(), IsFalse()) + }); + it("uses default formatter for '--formatter'", [&](){ AssertThat(opt.formatter(), Equals(bd::options::formatters::FORMATTER_DEFAULT)); }); diff --git a/vendor/bandit/specs/run.spec.cpp b/vendor/bandit/specs/run.spec.cpp index 4ef5ffc6..6e59bac7 100644 --- a/vendor/bandit/specs/run.spec.cpp +++ b/vendor/bandit/specs/run.spec.cpp @@ -11,7 +11,7 @@ go_bandit([](){ fake_reporter_ptr reporter; std::unique_ptr<bd::contextstack_t> context_stack; - auto call_run = [&](){ + auto call_run = [&]() -> int { bd::options opt(argv->argc(), argv->argv()); return bandit::run(opt, *specs, *context_stack, *reporter); }; diff --git a/vendor/bandit/specs/run_policies/bandit_run_policy.spec.cpp b/vendor/bandit/specs/run_policies/bandit_run_policy.spec.cpp index 3f383402..75f56bc6 100644 --- a/vendor/bandit/specs/run_policies/bandit_run_policy.spec.cpp +++ b/vendor/bandit/specs/run_policies/bandit_run_policy.spec.cpp @@ -8,29 +8,53 @@ go_bandit([](){ std::unique_ptr<bd::context> global_context; std::string only_pattern; std::string skip_pattern; + bool break_on_failure; + + auto create_policy = [&]() -> bd::bandit_run_policy { + return bd::bandit_run_policy(skip_pattern.c_str(), only_pattern.c_str(), break_on_failure); + }; before_each([&](){ contextstack = std::unique_ptr<bd::contextstack_t>(new bd::contextstack_t()); bool hard_skip = false; global_context = std::unique_ptr<bd::context>(new bd::bandit_context("", hard_skip)); contextstack->push_back(global_context.get()); + break_on_failure = false; }); describe("neither skip nor only specified", [&](){ - before_each([&](){ only_pattern = ""; skip_pattern = ""; }); it("always says run", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name", *contextstack), IsTrue()); }); + describe("with 'break-on-failure' set", [&](){ + + before_each([&](){ + break_on_failure = true; + }); + + it("says run if no failure has been encountered", [&](){ + bd::bandit_run_policy policy = create_policy(); + AssertThat(policy.should_run("it name", *contextstack), IsTrue()); + }); + + it("says don't run if a failure has been encountered", [&](){ + bd::bandit_run_policy policy = create_policy(); + policy.encountered_failure(); + AssertThat(policy.should_run("it name", *contextstack), IsFalse()); + }); + + }); + describe("has context marked with 'hard_skip' in stack", [&](){ std::unique_ptr<bd::context> hard_skip_context; - + before_each([&](){ bool hard_skip = true; hard_skip_context = std::unique_ptr<bd::context>(new bd::bandit_context("always ignore", hard_skip)); @@ -38,7 +62,7 @@ go_bandit([](){ }); it("never runs", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name", *contextstack), IsFalse()); AssertThat(policy.should_run("it name matches 'skip'", *contextstack), IsFalse()); AssertThat(policy.should_run("it name matches 'only'", *contextstack), IsFalse()); @@ -65,7 +89,7 @@ go_bandit([](){ }); it("never runs", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name", *contextstack), IsFalse()); }); @@ -81,12 +105,12 @@ go_bandit([](){ }); it("runs if spec's name doesn't match", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name", *contextstack), IsTrue()); }); it("doesn't run if spec's name matches", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name matching 'skip'", *contextstack), IsFalse()); }); @@ -111,7 +135,7 @@ go_bandit([](){ }); it("always runs", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name", *contextstack), IsTrue()); }); @@ -127,12 +151,12 @@ go_bandit([](){ }); it("doesn't run if spec's name doesn't match", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name", *contextstack), IsFalse()); }); it("runs if spec's name matches", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name matching 'only'", *contextstack), IsTrue()); }); @@ -157,12 +181,12 @@ go_bandit([](){ }); it("doesn't run if 'it' doesn't match 'only'", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name", *contextstack), IsFalse()); }); it("runs if 'it' matches 'only'", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it matches 'only'", *contextstack), IsTrue()); }); @@ -178,12 +202,12 @@ go_bandit([](){ }); it("runs if spec's name doesn't match anything", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name", *contextstack), IsTrue()); }); it("doesn't run if spec's name matches 'skip'", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name matching 'skip'", *contextstack), IsFalse()); }); @@ -202,16 +226,16 @@ go_bandit([](){ }); it("runs if spec's name doesn't match anything", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name", *contextstack), IsTrue()); }); it("doesn't run if spec's name matches 'skip'", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name matching 'skip'", *contextstack), IsFalse()); }); it("runs if spec's name matches 'only'", [&](){ - bd::bandit_run_policy policy(skip_pattern.c_str(), only_pattern.c_str()); + bd::bandit_run_policy policy = create_policy(); AssertThat(policy.should_run("it name matching 'only'", *contextstack), IsTrue()); }); diff --git a/vendor/bandit/specs/util/argv_helper.h b/vendor/bandit/specs/util/argv_helper.h index 4e92e725..dac26765 100644 --- a/vendor/bandit/specs/util/argv_helper.h +++ b/vendor/bandit/specs/util/argv_helper.h @@ -15,13 +15,13 @@ namespace bandit { namespace specs { namespace util { // struct argv_helper { - argv_helper(int argc, const char* argv[]) - : argc_(argc) + argv_helper(int argc_a, const char* argv_a[]) + : argc_(argc_a) { - non_const_argv_ = new char*[argc]; - for(int i=0; i < argc; i++) + non_const_argv_ = new char*[argc_]; + for(int i=0; i < argc_; i++) { - std::string s(argv[i]); + std::string s(argv_a[i]); non_const_argv_[i] = new char[s.size() + 1]; for(size_t c=0;c<s.size();c++) { |