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:
Phil Nash 2011-01-14 16:21:11 +00:00
parent 684baf1053
commit 6c010e25d9
2 changed files with 24 additions and 48 deletions

View File

@ -17,53 +17,14 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
{
using namespace Catch;
{
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 );
}
}
EmbeddedRunner runner;
TEST_CASE( "selftest/succeeding", "Runs all Catch self tests that should succeed and checks their results" )
{
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( "./succeeding/*" );
}
CHECK( config.getReporter().getSucceeded() == 53 );
CHECK( config.getReporter().getFailed() == 0 );
}
}
runner.runMatching( "./succeeding/*" );
CHECK( runner.getReporter().getSucceeded() == 53 );
CHECK( runner.getReporter().getFailed() == 0 );
TEST_CASE( "selftest/failing", "Runs all Catch self tests that should fail and checks their results" )
{
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/*" );
}
runner.runMatching( "./failing/*" );
CHECK( config.getReporter().getSucceeded() == 0 );
CHECK( config.getReporter().getFailed() == 53 );
}
CHECK( runner.getReporter().getSucceeded() == 0 );
CHECK( runner.getReporter().getFailed() == 53 );
}

View File

@ -45,6 +45,13 @@ namespace Catch
return m_failed;
}
///////////////////////////////////////////////////////////////////////////
void reset()
{
m_succeeded = 0;
m_failed = 0;
}
private: // IReporter
///////////////////////////////////////////////////////////////////////////
@ -75,6 +82,7 @@ namespace Catch
class SelfTestConfig : public Config
{
public:
///////////////////////////////////////////////////////////////////////////
SelfTestConfig()
: m_reporter( new SelfTestReporter() )
{
@ -82,6 +90,8 @@ namespace Catch
setReporter( m_reporter );
setStreamBuf( m_oss.rdbuf() );
}
///////////////////////////////////////////////////////////////////////////
SelfTestReporter& getReporter()
{
return *m_reporter;
@ -96,20 +106,25 @@ namespace Catch
class EmbeddedRunner
{
public:
///////////////////////////////////////////////////////////////////////////
EmbeddedRunner()
{
}
///////////////////////////////////////////////////////////////////////////
std::size_t runMatching
(
const std::string& rawTestSpec
)
const std::string& rawTestSpec
)
{
std::size_t result;
Runner runner( m_config );
m_config.getReporter().reset();
result = runner.runMatching( rawTestSpec );
return result;
}
///////////////////////////////////////////////////////////////////////////
SelfTestReporter& getReporter()
{
return m_config.getReporter();