Fixed lazy reporting for nested sections

This commit is contained in:
Phil Nash 2011-02-28 08:18:52 +00:00
parent 7fe330f078
commit 088d700315
3 changed files with 29 additions and 18 deletions

View File

@ -54,9 +54,6 @@ TEST_CASE( "./mixed/Misc/Sections/nested2", "nested SECTION tests" )
SECTION( "s1", "doesn't equal" ) SECTION( "s1", "doesn't equal" )
{ {
REQUIRE( a != b );
REQUIRE( b != a );
SECTION( "s2", "equal" ) SECTION( "s2", "equal" )
{ {
REQUIRE( a == b ); REQUIRE( a == b );
@ -68,7 +65,7 @@ TEST_CASE( "./mixed/Misc/Sections/nested2", "nested SECTION tests" )
} }
SECTION( "s4", "less than" ) SECTION( "s4", "less than" )
{ {
REQUIRE( b < a ); REQUIRE( a < b );
} }
} }
} }

View File

@ -20,7 +20,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
runner.runMatching( "./succeeding/*" ); runner.runMatching( "./succeeding/*" );
INFO( runner.getOutput() ); INFO( runner.getOutput() );
CHECK( runner.getSuccessCount() == 197 ); CHECK( runner.getSuccessCount() == 199 );
CHECK( runner.getFailureCount() == 0 ); CHECK( runner.getFailureCount() == 0 );
runner.runMatching( "./failing/*" ); runner.runMatching( "./failing/*" );
@ -34,7 +34,7 @@ TEST_CASE( "meta/Misc/Sections", "looped tests" )
Catch::EmbeddedRunner runner; Catch::EmbeddedRunner runner;
runner.runMatching( "./mixed/Misc/Sections/nested2" ); runner.runMatching( "./mixed/Misc/Sections/nested2" );
CHECK( runner.getSuccessCount() == 9 ); CHECK( runner.getSuccessCount() == 2 );
CHECK( runner.getFailureCount() == 2 ); CHECK( runner.getFailureCount() == 1 );
} }

View File

@ -142,7 +142,7 @@ namespace Catch
const std::string /*description*/ const std::string /*description*/
) )
{ {
m_sectionSpan = sectionName; m_sectionSpans.push_back( SpanInfo( sectionName ) );
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@ -153,13 +153,14 @@ namespace Catch
std::size_t failed std::size_t failed
) )
{ {
if( m_sectionSpan.emitted && !m_sectionSpan.name.empty() ) SpanInfo& sectionSpan = m_sectionSpans.back();
if( sectionSpan.emitted && !sectionSpan.name.empty() )
{ {
m_config.stream() << "[End of section: '" << sectionName << "'. "; m_config.stream() << "[End of section: '" << sectionName << "'. ";
ReportCounts( succeeded, failed ); ReportCounts( succeeded, failed );
m_config.stream() << "]\n" << std::endl; m_config.stream() << "]\n" << std::endl;
m_sectionSpan = SpanInfo();
} }
m_sectionSpans.pop_back();
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@ -260,15 +261,28 @@ namespace Catch
m_testSpan.emitted = true; m_testSpan.emitted = true;
} }
if( !m_sectionSpan.emitted && !m_sectionSpan.name.empty() ) if( !m_sectionSpans.empty() )
{ {
if( m_firstSectionInTestCase ) SpanInfo& sectionSpan = m_sectionSpans.back();
if( !sectionSpan.emitted && !sectionSpan.name.empty() )
{ {
m_config.stream() << "\n"; if( m_firstSectionInTestCase )
m_firstSectionInTestCase = false; {
m_config.stream() << "\n";
m_firstSectionInTestCase = false;
}
std::vector<SpanInfo>::iterator it = m_sectionSpans.begin();
std::vector<SpanInfo>::iterator itEnd = m_sectionSpans.end();
for(; it != itEnd; ++it )
{
SpanInfo& prevSpan = *it;
if( !prevSpan.emitted && !prevSpan.name.empty() )
{
m_config.stream() << "[Started section: '" << prevSpan.name << "']" << std::endl;
prevSpan.emitted = true;
}
}
} }
m_config.stream() << "[Started section: '" << m_sectionSpan.name << "']" << std::endl;
m_sectionSpan.emitted = true;
} }
} }
@ -278,8 +292,8 @@ namespace Catch
SpanInfo m_testingSpan; SpanInfo m_testingSpan;
SpanInfo m_groupSpan; SpanInfo m_groupSpan;
SpanInfo m_sectionSpan;
SpanInfo m_testSpan; SpanInfo m_testSpan;
std::vector<SpanInfo> m_sectionSpans;
}; };
INTERNAL_CATCH_REGISTER_REPORTER( "basic", BasicReporter ) INTERNAL_CATCH_REGISTER_REPORTER( "basic", BasicReporter )