Merge branch 'master' of https://github.com/jbrwilkinson/Catch
# By James Wilkinson
# Via James Wilkinson
* 'master' of https://github.com/jbrwilkinson/Catch:
Added SCENARIO_METHOD for BDD testing with fixtures.
diff --git a/include/catch.hpp b/include/catch.hpp
index b05c485..4251cd0 100644
--- a/include/catch.hpp
+++ b/include/catch.hpp
@@ -112,8 +112,10 @@
// "BDD-style" convenience wrappers
#ifdef CATCH_CONFIG_VARIADIC_MACROS
#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
+#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
#else
#define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags )
+#define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
#endif
#define CATCH_GIVEN( desc ) CATCH_SECTION( "Given: " desc, "" )
#define CATCH_WHEN( desc ) CATCH_SECTION( " When: " desc, "" )
@@ -179,8 +181,10 @@
// "BDD-style" convenience wrappers
#ifdef CATCH_CONFIG_VARIADIC_MACROS
#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
+#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
#else
#define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags )
+#define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
#endif
#define GIVEN( desc ) SECTION( " Given: " desc, "" )
#define WHEN( desc ) SECTION( " When: " desc, "" )
diff --git a/projects/SelfTest/BDDTests.cpp b/projects/SelfTest/BDDTests.cpp
index 4220c82..3b5c959 100644
--- a/projects/SelfTest/BDDTests.cpp
+++ b/projects/SelfTest/BDDTests.cpp
@@ -66,3 +66,38 @@
THEN( "The, deliberately very long and overly verbose (you see what I did there?) section names must wrap, along with an indent" )
SUCCEED("boo!");
}
+
+namespace {
+
+// a trivial fixture example to support SCENARIO_METHOD tests
+struct Fixture
+{
+ Fixture()
+ : d_counter(0)
+ {
+ }
+
+ int counter()
+ {
+ return d_counter++;
+ }
+
+ int d_counter;
+};
+
+}
+
+SCENARIO_METHOD(Fixture,
+ "BDD tests requiring Fixtures to provide commonly-accessed data or methods",
+ "[bdd][fixtures]") {
+ const int before(counter());
+ GIVEN("No operations precede me") {
+ REQUIRE(before == 0);
+ WHEN("We get the count") {
+ const int after(counter());
+ THEN("Subsequently values are higher") {
+ REQUIRE(after > before);
+ }
+ }
+ }
+}