Fairly major reworking of console reporter (still in progress).

Changed reporter interface a bit.
This commit is contained in:
Phil Nash
2013-01-13 21:51:44 +00:00
parent e9305ecd65
commit 42aef1d99c
17 changed files with 306 additions and 259 deletions

View File

@@ -26,3 +26,17 @@ CATCH_TEST_CASE( "./succeeding/generators/1", "Generators over two ranges" )
CATCH_REQUIRE( multiply( i, 2 ) == i*2 );
CATCH_REQUIRE( multiply( j, 2 ) == j*2 );
}
struct IntPair { int first, second; };
CATCH_TEST_CASE( "./succeeding/generators/2", "Generator over a range of pairs" )
{
using namespace Catch::Generators;
IntPair p[] = { { 0, 1 }, { 2, 3 } };
IntPair* i = CATCH_GENERATE( between( p, &p[1] ) );
CATCH_REQUIRE( i->first == i->second-1 );
}

View File

@@ -20,12 +20,12 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
SECTION( "selftest/expected result/failing tests",
"Tests in the 'failing' branch fail" ) {
MetaTestRunner::runMatching( "./failing/*", MetaTestRunner::Expected::ToFail );
MetaTestRunner::runMatching( "./failing/*", MetaTestRunner::Expected::ToFail, 0, 2 );
}
SECTION( "selftest/expected result/succeeding tests",
"Tests in the 'succeeding' branch succeed" ) {
MetaTestRunner::runMatching( "./succeeding/*", MetaTestRunner::Expected::ToSucceed );
MetaTestRunner::runMatching( "./succeeding/*", MetaTestRunner::Expected::ToSucceed, 1, 2 );
}
}
@@ -36,14 +36,14 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
SECTION( "selftest/test counts/succeeding tests",
"Number of 'succeeding' tests is fixed" ) {
Totals totals = runner.runMatching( "./succeeding/*" );
Totals totals = runner.runMatching( "./succeeding/*", 0, 2 );
CHECK( totals.assertions.passed == 291 );
CHECK( totals.assertions.failed == 0 );
}
SECTION( "selftest/test counts/failing tests",
"Number of 'failing' tests is fixed" ) {
Totals totals = runner.runMatching( "./failing/*" );
Totals totals = runner.runMatching( "./failing/*", 1, 2 );
CHECK( totals.assertions.passed == 1 );
CHECK( totals.assertions.failed == 72 );
}
@@ -53,7 +53,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
TEST_CASE( "meta/Misc/Sections", "looped tests" ) {
Catch::EmbeddedRunner runner;
Catch::Totals totals = runner.runMatching( "./mixed/Misc/Sections/nested2" );
Catch::Totals totals = runner.runMatching( "./mixed/Misc/Sections/nested2", 0, 1 );
CHECK( totals.assertions.passed == 2 );
CHECK( totals.assertions.failed == 1 );
}

View File

@@ -17,7 +17,7 @@ namespace Catch{
NullStreamingReporter::~NullStreamingReporter() {}
Totals EmbeddedRunner::runMatching( const std::string& rawTestSpec, const std::string& ) {
Totals EmbeddedRunner::runMatching( const std::string& rawTestSpec, std::size_t groupIndex, std::size_t groupsCount, const std::string& ) {
std::ostringstream oss;
Config config;
config.setStreamBuf( oss.rdbuf() );
@@ -27,7 +27,7 @@ namespace Catch{
// Scoped because Runner doesn't report EndTesting until its destructor
{
Runner runner( config, m_reporter.get() );
totals = runner.runMatching( rawTestSpec );
totals = runner.runMatching( rawTestSpec, groupIndex, groupsCount );
}
return totals;
}

View File

@@ -53,6 +53,8 @@ namespace Catch {
EmbeddedRunner() : m_reporter( new NullStreamingReporter() ) {}
Totals runMatching( const std::string& rawTestSpec,
std::size_t groupIndex,
std::size_t groupsCount,
const std::string& reporter = "console" );
private:
@@ -67,12 +69,18 @@ namespace Catch {
ToFail
}; };
MetaTestRunner( Expected::Result expectedResult ) : m_expectedResult( expectedResult ) {}
MetaTestRunner( Expected::Result expectedResult, std::size_t groupIndex, std::size_t groupsCount )
: m_expectedResult( expectedResult ),
m_groupIndex( groupIndex ),
m_groupsCount( groupsCount )
{}
static void runMatching( const std::string& testSpec,
Expected::Result expectedResult ) {
Expected::Result expectedResult,
std::size_t groupIndex,
std::size_t groupsCount ) {
forEach( getRegistryHub().getTestCaseRegistry().getMatchingTestCases( testSpec ),
MetaTestRunner( expectedResult ) );
MetaTestRunner( expectedResult, groupIndex, groupsCount ) );
}
void operator()( const TestCase& testCase ) {
@@ -81,7 +89,7 @@ namespace Catch {
{
EmbeddedRunner runner;
name = testCase.getTestCaseInfo().name;
totals = runner.runMatching( name );
totals = runner.runMatching( name, m_groupIndex, m_groupsCount );
}
switch( m_expectedResult ) {
case Expected::ToSucceed:
@@ -111,6 +119,8 @@ namespace Catch {
private:
Expected::Result m_expectedResult;
std::size_t m_groupIndex;
std::size_t m_groupsCount;
};