INFOs only reset at assertion if consumed

This commit is contained in:
Phil Nash 2013-06-28 16:25:49 +01:00
parent 239fa28e46
commit 0d357302a0
8 changed files with 18 additions and 13 deletions

View File

@ -208,7 +208,7 @@ namespace Catch
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
virtual void assertionEnded( AssertionStats const& assertionStats ) = 0; virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
virtual void sectionEnded( SectionStats const& sectionStats ) = 0; virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0; virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;

View File

@ -25,7 +25,7 @@ namespace Catch
virtual void testCaseStarting( TestCaseInfo const& testInfo ); virtual void testCaseStarting( TestCaseInfo const& testInfo );
virtual void sectionStarting( SectionInfo const& sectionInfo ); virtual void sectionStarting( SectionInfo const& sectionInfo );
virtual void assertionStarting( AssertionInfo const& ); virtual void assertionStarting( AssertionInfo const& );
virtual void assertionEnded( AssertionStats const& assertionStats ); virtual bool assertionEnded( AssertionStats const& assertionStats );
virtual void sectionEnded( SectionStats const& sectionStats ); virtual void sectionEnded( SectionStats const& sectionStats );
virtual void testCaseEnded( TestCaseStats const& testCaseStats ); virtual void testCaseEnded( TestCaseStats const& testCaseStats );
virtual void testGroupEnded( TestGroupStats const& testGroupStats ); virtual void testGroupEnded( TestGroupStats const& testGroupStats );

View File

@ -40,7 +40,7 @@ namespace Catch
// Not on legacy interface // Not on legacy interface
} }
void LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) { bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) {
if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
it != itEnd; it != itEnd;
@ -55,6 +55,7 @@ namespace Catch
} }
} }
m_legacyReporter->Result( assertionStats.assertionResult ); m_legacyReporter->Result( assertionStats.assertionResult );
return true;
} }
void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) { void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) {
if( sectionStats.missingAssertions ) if( sectionStats.missingAssertions )

View File

@ -171,11 +171,11 @@ namespace Catch {
m_totals.assertions.failed++; m_totals.assertions.failed++;
} }
m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) ); if( m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) ) )
m_messages.clear();
// Reset working state // Reset working state
m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition ); m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition );
m_messages.clear();
} }
virtual bool sectionStarted ( virtual bool sectionStarted (

View File

@ -39,18 +39,19 @@ namespace Catch {
virtual void assertionStarting( AssertionInfo const& ) { virtual void assertionStarting( AssertionInfo const& ) {
} }
virtual void assertionEnded( AssertionStats const& _assertionStats ) { virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
AssertionResult const& result = _assertionStats.assertionResult; AssertionResult const& result = _assertionStats.assertionResult;
// Drop out if result was successful and we're not printing those // Drop out if result was successful and we're not printing those
if( !m_config->includeSuccessfulResults() && result.isOk() ) if( !m_config->includeSuccessfulResults() && result.isOk() )
return; return false;
lazyPrint(); lazyPrint();
AssertionPrinter printer( stream, _assertionStats ); AssertionPrinter printer( stream, _assertionStats );
printer.print(); printer.print();
stream << std::endl; stream << std::endl;
return true;
} }
virtual void sectionStarting( SectionInfo const& _sectionInfo ) { virtual void sectionStarting( SectionInfo const& _sectionInfo ) {

View File

@ -397,7 +397,8 @@ MessageTests.cpp:37: FAILED:
CHECK( a == 1 ) CHECK( a == 1 )
with expansion: with expansion:
2 == 1 2 == 1
with message: with messages:
this message may be logged later
this message should be logged this message should be logged
MessageTests.cpp:41: FAILED: MessageTests.cpp:41: FAILED:
@ -514,7 +515,8 @@ MiscTests.cpp:111: FAILED:
CHECK( ( fib[i] % 2 ) == 0 ) CHECK( ( fib[i] % 2 ) == 0 )
with expansion: with expansion:
1 == 0 1 == 0
with message: with messages:
Testing if fib[2] (2) is even
Testing if fib[3] (3) is even Testing if fib[3] (3) is even
MiscTests.cpp:111: FAILED: MiscTests.cpp:111: FAILED:
@ -528,7 +530,8 @@ MiscTests.cpp:111: FAILED:
CHECK( ( fib[i] % 2 ) == 0 ) CHECK( ( fib[i] % 2 ) == 0 )
with expansion: with expansion:
1 == 0 1 == 0
with message: with messages:
Testing if fib[5] (8) is even
Testing if fib[6] (13) is even Testing if fib[6] (13) is even
MiscTests.cpp:111: FAILED: MiscTests.cpp:111: FAILED:
@ -2786,7 +2789,7 @@ PASSED:
with expansion: with expansion:
2 == 2 2 == 2
with message: with message:
this message should not be logged this message may be logged later
MessageTests.cpp:37: FAILED: MessageTests.cpp:37: FAILED:
CHECK( a == 1 ) CHECK( a == 1 )

View File

@ -28,7 +28,7 @@ TEST_CASE( "./failing/message/info/1", "INFO gets logged on failure" )
TEST_CASE( "./mixed/message/info/2", "INFO gets logged on failure" ) TEST_CASE( "./mixed/message/info/2", "INFO gets logged on failure" )
{ {
INFO( "this message should not be logged" ); INFO( "this message may be logged later" );
int a = 2; int a = 2;
CHECK( a == 2 ); CHECK( a == 2 );

View File

@ -46,7 +46,7 @@ namespace Catch {
virtual void testCaseStarting( TestCaseInfo const& ) {} virtual void testCaseStarting( TestCaseInfo const& ) {}
virtual void sectionStarting( SectionInfo const& ) {} virtual void sectionStarting( SectionInfo const& ) {}
virtual void assertionStarting( AssertionInfo const& ) {} virtual void assertionStarting( AssertionInfo const& ) {}
virtual void assertionEnded( AssertionStats const& ) {} virtual bool assertionEnded( AssertionStats const& ) { return false; }
virtual void sectionEnded( SectionStats const& ) {} virtual void sectionEnded( SectionStats const& ) {}
virtual void testCaseEnded( TestCaseStats const& ) {} virtual void testCaseEnded( TestCaseStats const& ) {}
virtual void testGroupEnded( TestGroupStats const& ) {} virtual void testGroupEnded( TestGroupStats const& ) {}