diff --git a/include/reporters/catch_reporter_xml.hpp b/include/reporters/catch_reporter_xml.hpp index f345ae27..412a5184 100644 --- a/include/reporters/catch_reporter_xml.hpp +++ b/include/reporters/catch_reporter_xml.hpp @@ -92,73 +92,77 @@ namespace Catch { virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { } virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE { - const AssertionResult& assertionResult = assertionStats.assertionResult; - // Print any info messages in tags. - if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { + AssertionResult const& result = assertionStats.assertionResult; + + bool includeResults = m_config->includeSuccessfulResults() || result.isOk(); + + if( includeResults ) { + // Print any info messages in tags. for( std::vector::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); - it != itEnd; - ++it ) { + it != itEnd; + ++it ) { if( it->type == ResultWas::Info ) { m_xml.scopedElement( "Info" ) - .writeText( it->message ); + .writeText( it->message ); } else if ( it->type == ResultWas::Warning ) { m_xml.scopedElement( "Warning" ) - .writeText( it->message ); + .writeText( it->message ); } } } // Drop out if result was successful but we're not printing them. - if( !m_config->includeSuccessfulResults() && isOk(assertionResult.getResultType()) ) + if( !includeResults && result.getResultType() != ResultWas::Warning ) return true; - // Print the expression if there is one. - if( assertionResult.hasExpression() ) { - m_xml.startElement( "Expression" ) - .writeAttribute( "success", assertionResult.succeeded() ) - .writeAttribute( "type", assertionResult.getTestMacroName() ); - writeSourceInfo( assertionResult.getSourceInfo() ); + // Print the expression if there is one. + if( result.hasExpression() ) { + m_xml.startElement( "Expression" ) + .writeAttribute( "success", result.succeeded() ) + .writeAttribute( "type", result.getTestMacroName() ); + + writeSourceInfo( result.getSourceInfo() ); m_xml.scopedElement( "Original" ) - .writeText( assertionResult.getExpression() ); + .writeText( result.getExpression() ); m_xml.scopedElement( "Expanded" ) - .writeText( assertionResult.getExpandedExpression() ); + .writeText( result.getExpandedExpression() ); } // And... Print a result applicable to each result type. - switch( assertionResult.getResultType() ) { + switch( result.getResultType() ) { case ResultWas::ThrewException: m_xml.startElement( "Exception" ); - writeSourceInfo( assertionResult.getSourceInfo() ); - m_xml.writeText( assertionResult.getMessage() ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); m_xml.endElement(); break; case ResultWas::FatalErrorCondition: m_xml.startElement( "FatalErrorCondition" ); - writeSourceInfo( assertionResult.getSourceInfo() ); - m_xml.writeText( assertionResult.getMessage() ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); m_xml.endElement(); break; case ResultWas::Info: m_xml.scopedElement( "Info" ) - .writeText( assertionResult.getMessage() ); + .writeText( result.getMessage() ); break; case ResultWas::Warning: // Warning will already have been written break; case ResultWas::ExplicitFailure: m_xml.startElement( "Failure" ); - writeSourceInfo( assertionResult.getSourceInfo() ); - m_xml.writeText( assertionResult.getMessage() ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); m_xml.endElement(); break; default: break; } - if( assertionResult.hasExpression() ) + if( result.hasExpression() ) m_xml.endElement(); return true; diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index f242568b..ab6ab08b 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -645,6 +645,9 @@
+ + i := 2 + true @@ -656,6 +659,9 @@
+ + 3 + true @@ -2632,6 +2638,9 @@ + + this message may be logged later + a == 2 @@ -2662,6 +2671,9 @@ 2 == 0 + + but not this + a == 2 @@ -6761,6 +6773,12 @@ re>" + + current counter 0 + + + i := 0 + i < 10 @@ -6769,6 +6787,12 @@ re>" 0 < 10 + + current counter 1 + + + i := 1 + i < 10 @@ -6777,6 +6801,12 @@ re>" 1 < 10 + + current counter 2 + + + i := 2 + i < 10 @@ -6785,6 +6815,12 @@ re>" 2 < 10 + + current counter 3 + + + i := 3 + i < 10 @@ -6793,6 +6829,12 @@ re>" 3 < 10 + + current counter 4 + + + i := 4 + i < 10 @@ -6801,6 +6843,12 @@ re>" 4 < 10 + + current counter 5 + + + i := 5 + i < 10 @@ -6809,6 +6857,12 @@ re>" 5 < 10 + + current counter 6 + + + i := 6 + i < 10 @@ -6817,6 +6871,12 @@ re>" 6 < 10 + + current counter 7 + + + i := 7 + i < 10 @@ -6825,6 +6885,12 @@ re>" 7 < 10 + + current counter 8 + + + i := 8 + i < 10 @@ -6833,6 +6899,12 @@ re>" 8 < 10 + + current counter 9 + + + i := 9 + i < 10 @@ -9111,6 +9183,9 @@ spanner 1 == 0 + + Testing if fib[2] (2) is even + ( fib[i] % 2 ) == 0 @@ -9141,6 +9216,9 @@ spanner 1 == 0 + + Testing if fib[5] (8) is even + ( fib[i] % 2 ) == 0