mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-20 11:35:39 +02:00
Reorganised (some) usage tests so they can be included multiple times
This commit is contained in:
@@ -8,32 +8,29 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
namespace
|
||||
namespace{ namespace ClassTests {
|
||||
|
||||
#ifndef CLASS_TEST_HELPERS_INCLUDED // Don't compile this more than once per TU
|
||||
#define CLASS_TEST_HELPERS_INCLUDED
|
||||
|
||||
class TestClass
|
||||
{
|
||||
class TestClass
|
||||
std::string s;
|
||||
|
||||
public:
|
||||
TestClass()
|
||||
: s( "hello" )
|
||||
{}
|
||||
|
||||
void succeedingCase()
|
||||
{
|
||||
std::string s;
|
||||
|
||||
public:
|
||||
TestClass()
|
||||
: s( "hello" )
|
||||
{}
|
||||
|
||||
void succeedingCase()
|
||||
{
|
||||
REQUIRE( s == "hello" );
|
||||
}
|
||||
void failingCase()
|
||||
{
|
||||
REQUIRE( s == "world" );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
METHOD_AS_TEST_CASE( TestClass::succeedingCase, "A METHOD_AS_TEST_CASE based test run that succeeds", "[class]" )
|
||||
METHOD_AS_TEST_CASE( TestClass::failingCase, "A METHOD_AS_TEST_CASE based test run that fails", "[.][class][failing]" )
|
||||
|
||||
REQUIRE( s == "hello" );
|
||||
}
|
||||
void failingCase()
|
||||
{
|
||||
REQUIRE( s == "world" );
|
||||
}
|
||||
};
|
||||
|
||||
struct Fixture
|
||||
{
|
||||
@@ -42,6 +39,13 @@ struct Fixture
|
||||
int m_a;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
METHOD_AS_TEST_CASE( TestClass::succeedingCase, "A METHOD_AS_TEST_CASE based test run that succeeds", "[class]" )
|
||||
METHOD_AS_TEST_CASE( TestClass::failingCase, "A METHOD_AS_TEST_CASE based test run that fails", "[.][class][failing]" )
|
||||
|
||||
TEST_CASE_METHOD( Fixture, "A TEST_CASE_METHOD based test run that succeeds", "[class]" )
|
||||
{
|
||||
REQUIRE( m_a == 1 );
|
||||
@@ -55,3 +59,5 @@ namespace Inner
|
||||
REQUIRE( m_a == 2 );
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace ClassTests
|
||||
|
Reference in New Issue
Block a user