mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-04 05:59:32 +01:00 
			
		
		
		
	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.
This commit is contained in:
		@@ -112,8 +112,10 @@
 | 
				
			|||||||
// "BDD-style" convenience wrappers
 | 
					// "BDD-style" convenience wrappers
 | 
				
			||||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
 | 
					#ifdef CATCH_CONFIG_VARIADIC_MACROS
 | 
				
			||||||
#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
 | 
					#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
 | 
				
			||||||
 | 
					#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
#define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags )
 | 
					#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
 | 
					#endif
 | 
				
			||||||
#define CATCH_GIVEN( desc )    CATCH_SECTION( "Given: " desc, "" )
 | 
					#define CATCH_GIVEN( desc )    CATCH_SECTION( "Given: " desc, "" )
 | 
				
			||||||
#define CATCH_WHEN( desc )     CATCH_SECTION( " When: " desc, "" )
 | 
					#define CATCH_WHEN( desc )     CATCH_SECTION( " When: " desc, "" )
 | 
				
			||||||
@@ -179,8 +181,10 @@
 | 
				
			|||||||
// "BDD-style" convenience wrappers
 | 
					// "BDD-style" convenience wrappers
 | 
				
			||||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
 | 
					#ifdef CATCH_CONFIG_VARIADIC_MACROS
 | 
				
			||||||
#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
 | 
					#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
 | 
				
			||||||
 | 
					#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
#define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags )
 | 
					#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
 | 
					#endif
 | 
				
			||||||
#define GIVEN( desc )    SECTION( "   Given: " desc, "" )
 | 
					#define GIVEN( desc )    SECTION( "   Given: " desc, "" )
 | 
				
			||||||
#define WHEN( desc )     SECTION( "    When: " desc, "" )
 | 
					#define WHEN( desc )     SECTION( "    When: " desc, "" )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -66,3 +66,38 @@ SCENARIO(   "This is a really long scenario name to see how the list command dea
 | 
				
			|||||||
            THEN( "The, deliberately very long and overly verbose (you see what I did there?) section names must wrap, along with an indent" )
 | 
					            THEN( "The, deliberately very long and overly verbose (you see what I did there?) section names must wrap, along with an indent" )
 | 
				
			||||||
                SUCCEED("boo!");
 | 
					                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);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user