mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
A single embedded runner instance can now be used for multiple nested runs, with results reset between each. Meta test runner looking very clean now.
This commit is contained in:
parent
684baf1053
commit
6c010e25d9
@ -17,53 +17,14 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
|
|||||||
{
|
{
|
||||||
using namespace Catch;
|
using namespace Catch;
|
||||||
|
|
||||||
{
|
EmbeddedRunner runner;
|
||||||
EmbeddedRunner runner;
|
|
||||||
runner.runMatching( "./succeeding/*" );
|
|
||||||
CHECK( runner.getReporter().getSucceeded() == 53 );
|
|
||||||
CHECK( runner.getReporter().getFailed() == 0 );
|
|
||||||
}
|
|
||||||
{
|
|
||||||
EmbeddedRunner runner;
|
|
||||||
runner.runMatching( "./failing/*" );
|
|
||||||
|
|
||||||
CHECK( runner.getReporter().getSucceeded() == 0 );
|
|
||||||
CHECK( runner.getReporter().getFailed() == 53 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE( "selftest/succeeding", "Runs all Catch self tests that should succeed and checks their results" )
|
runner.runMatching( "./succeeding/*" );
|
||||||
{
|
CHECK( runner.getReporter().getSucceeded() == 53 );
|
||||||
using namespace Catch;
|
CHECK( runner.getReporter().getFailed() == 0 );
|
||||||
|
|
||||||
// Run a nested Runner - we scope it here so it restores our runner
|
|
||||||
// at the end of scope
|
|
||||||
{
|
|
||||||
SelfTestConfig config;
|
|
||||||
{
|
|
||||||
Runner runner( config );
|
|
||||||
runner.runMatching( "./succeeding/*" );
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK( config.getReporter().getSucceeded() == 53 );
|
|
||||||
CHECK( config.getReporter().getFailed() == 0 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE( "selftest/failing", "Runs all Catch self tests that should fail and checks their results" )
|
runner.runMatching( "./failing/*" );
|
||||||
{
|
|
||||||
using namespace Catch;
|
|
||||||
|
|
||||||
// Run a nested Runner - we scope it here so it restores our runner
|
|
||||||
// at the end of scope
|
|
||||||
{
|
|
||||||
SelfTestConfig config;
|
|
||||||
{
|
|
||||||
Runner runner( config );
|
|
||||||
runner.runMatching( "./failing/*" );
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK( config.getReporter().getSucceeded() == 0 );
|
CHECK( runner.getReporter().getSucceeded() == 0 );
|
||||||
CHECK( config.getReporter().getFailed() == 53 );
|
CHECK( runner.getReporter().getFailed() == 53 );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,13 @@ namespace Catch
|
|||||||
return m_failed;
|
return m_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
void reset()
|
||||||
|
{
|
||||||
|
m_succeeded = 0;
|
||||||
|
m_failed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
private: // IReporter
|
private: // IReporter
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
@ -75,6 +82,7 @@ namespace Catch
|
|||||||
class SelfTestConfig : public Config
|
class SelfTestConfig : public Config
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
SelfTestConfig()
|
SelfTestConfig()
|
||||||
: m_reporter( new SelfTestReporter() )
|
: m_reporter( new SelfTestReporter() )
|
||||||
{
|
{
|
||||||
@ -82,6 +90,8 @@ namespace Catch
|
|||||||
setReporter( m_reporter );
|
setReporter( m_reporter );
|
||||||
setStreamBuf( m_oss.rdbuf() );
|
setStreamBuf( m_oss.rdbuf() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
SelfTestReporter& getReporter()
|
SelfTestReporter& getReporter()
|
||||||
{
|
{
|
||||||
return *m_reporter;
|
return *m_reporter;
|
||||||
@ -96,20 +106,25 @@ namespace Catch
|
|||||||
class EmbeddedRunner
|
class EmbeddedRunner
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
EmbeddedRunner()
|
EmbeddedRunner()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
std::size_t runMatching
|
std::size_t runMatching
|
||||||
(
|
(
|
||||||
const std::string& rawTestSpec
|
const std::string& rawTestSpec
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
std::size_t result;
|
std::size_t result;
|
||||||
Runner runner( m_config );
|
Runner runner( m_config );
|
||||||
|
m_config.getReporter().reset();
|
||||||
result = runner.runMatching( rawTestSpec );
|
result = runner.runMatching( rawTestSpec );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
SelfTestReporter& getReporter()
|
SelfTestReporter& getReporter()
|
||||||
{
|
{
|
||||||
return m_config.getReporter();
|
return m_config.getReporter();
|
||||||
|
Loading…
Reference in New Issue
Block a user