mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Added facility to write self-registering test cases as methods
This commit is contained in:
parent
7abc6365a9
commit
a36b8d0779
@ -33,5 +33,25 @@ namespace
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
METHOD_AS_TEST_CASE( TestClass::succeedingCase, "succeeding/TestClass/succeedingCase", "A method based test run that succeeds" );
|
METHOD_AS_TEST_CASE( TestClass::succeedingCase, "succeeding/TestClass/succeedingCase", "A method based test run that succeeds" );
|
||||||
METHOD_AS_TEST_CASE( TestClass::failingCase, "failing/TestClass/failingCase", "A method based test run that fails" );
|
METHOD_AS_TEST_CASE( TestClass::failingCase, "failing/TestClass/failingCase", "A method based test run that fails" );
|
||||||
|
|
||||||
|
|
||||||
|
struct Fixture
|
||||||
|
{
|
||||||
|
Fixture() : m_a( 1 ) {}
|
||||||
|
|
||||||
|
int m_a;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_CASE_METHOD( Fixture, "succeeding/Fixture/succeedingCase", "A method based test run that succeeds" )
|
||||||
|
{
|
||||||
|
REQUIRE( m_a == 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE_METHOD( Fixture, "succeeding/Fixture/failingCase", "A method based test run that fails" )
|
||||||
|
{
|
||||||
|
REQUIRE( m_a == 2 );
|
||||||
|
}
|
||||||
|
@ -135,6 +135,9 @@ struct AutoReg
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T, size_t>
|
||||||
|
struct FixtureWrapper{};
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#define INTERNAL_CATCH_TESTCASE( Name, Desc ) \
|
#define INTERNAL_CATCH_TESTCASE( Name, Desc ) \
|
||||||
@ -145,4 +148,12 @@ struct AutoReg
|
|||||||
#define CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
|
#define CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
|
||||||
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, Name, Desc ); }
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, Name, Desc ); }
|
||||||
|
|
||||||
|
#define TEST_CASE_METHOD( ClassName, TestName, Desc )\
|
||||||
|
namespace Catch{ template<> struct FixtureWrapper<ClassName, __LINE__> : ClassName \
|
||||||
|
{ \
|
||||||
|
void test(); \
|
||||||
|
}; }\
|
||||||
|
namespace { Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &Catch::FixtureWrapper<ClassName, __LINE__>::test, TestName, Desc ); } \
|
||||||
|
void Catch::FixtureWrapper<ClassName, __LINE__>::test()
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED
|
||||||
|
Loading…
Reference in New Issue
Block a user