mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Tweaked Xml Reporter to follow same success/ info behaviour as Console reporter
This commit is contained in:
parent
be4f6ab8e1
commit
9bee606dd6
@ -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 <Info> 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 <Info> tags.
|
||||
for( std::vector<MessageInfo>::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;
|
||||
|
@ -645,6 +645,9 @@
|
||||
</TestCase>
|
||||
<TestCase name="Capture and info messages" filename="projects/<exe-name>/ToStringGeneralTests.cpp" >
|
||||
<Section name="Capture should stringify like assertions" filename="projects/<exe-name>/ToStringGeneralTests.cpp" >
|
||||
<Info>
|
||||
i := 2
|
||||
</Info>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringGeneralTests.cpp" >
|
||||
<Original>
|
||||
true
|
||||
@ -656,6 +659,9 @@
|
||||
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<Section name="Info should NOT stringify the way assertions do" filename="projects/<exe-name>/ToStringGeneralTests.cpp" >
|
||||
<Info>
|
||||
3
|
||||
</Info>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringGeneralTests.cpp" >
|
||||
<Original>
|
||||
true
|
||||
@ -2632,6 +2638,9 @@
|
||||
<OverallResult success="false"/>
|
||||
</TestCase>
|
||||
<TestCase name="INFO gets logged on failure, even if captured before successful assertions" tags="[.][failing][hide][messages]" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Info>
|
||||
this message may be logged later
|
||||
</Info>
|
||||
<Expression success="true" type="CHECK" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Original>
|
||||
a == 2
|
||||
@ -2662,6 +2671,9 @@
|
||||
2 == 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Info>
|
||||
but not this
|
||||
</Info>
|
||||
<Expression success="true" type="CHECK" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Original>
|
||||
a == 2
|
||||
@ -6761,6 +6773,12 @@ re>"
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="SCOPED_INFO is reset for each loop" tags="[.][failing][hide][messages]" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Info>
|
||||
current counter 0
|
||||
</Info>
|
||||
<Info>
|
||||
i := 0
|
||||
</Info>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Original>
|
||||
i < 10
|
||||
@ -6769,6 +6787,12 @@ re>"
|
||||
0 < 10
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Info>
|
||||
current counter 1
|
||||
</Info>
|
||||
<Info>
|
||||
i := 1
|
||||
</Info>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Original>
|
||||
i < 10
|
||||
@ -6777,6 +6801,12 @@ re>"
|
||||
1 < 10
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Info>
|
||||
current counter 2
|
||||
</Info>
|
||||
<Info>
|
||||
i := 2
|
||||
</Info>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Original>
|
||||
i < 10
|
||||
@ -6785,6 +6815,12 @@ re>"
|
||||
2 < 10
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Info>
|
||||
current counter 3
|
||||
</Info>
|
||||
<Info>
|
||||
i := 3
|
||||
</Info>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Original>
|
||||
i < 10
|
||||
@ -6793,6 +6829,12 @@ re>"
|
||||
3 < 10
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Info>
|
||||
current counter 4
|
||||
</Info>
|
||||
<Info>
|
||||
i := 4
|
||||
</Info>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Original>
|
||||
i < 10
|
||||
@ -6801,6 +6843,12 @@ re>"
|
||||
4 < 10
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Info>
|
||||
current counter 5
|
||||
</Info>
|
||||
<Info>
|
||||
i := 5
|
||||
</Info>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Original>
|
||||
i < 10
|
||||
@ -6809,6 +6857,12 @@ re>"
|
||||
5 < 10
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Info>
|
||||
current counter 6
|
||||
</Info>
|
||||
<Info>
|
||||
i := 6
|
||||
</Info>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Original>
|
||||
i < 10
|
||||
@ -6817,6 +6871,12 @@ re>"
|
||||
6 < 10
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Info>
|
||||
current counter 7
|
||||
</Info>
|
||||
<Info>
|
||||
i := 7
|
||||
</Info>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Original>
|
||||
i < 10
|
||||
@ -6825,6 +6885,12 @@ re>"
|
||||
7 < 10
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Info>
|
||||
current counter 8
|
||||
</Info>
|
||||
<Info>
|
||||
i := 8
|
||||
</Info>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Original>
|
||||
i < 10
|
||||
@ -6833,6 +6899,12 @@ re>"
|
||||
8 < 10
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Info>
|
||||
current counter 9
|
||||
</Info>
|
||||
<Info>
|
||||
i := 9
|
||||
</Info>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/MessageTests.cpp" >
|
||||
<Original>
|
||||
i < 10
|
||||
@ -9111,6 +9183,9 @@ spanner <OverallResult success="true"/>
|
||||
1 == 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Info>
|
||||
Testing if fib[2] (2) is even
|
||||
</Info>
|
||||
<Expression success="true" type="CHECK" filename="projects/<exe-name>/MiscTests.cpp" >
|
||||
<Original>
|
||||
( fib[i] % 2 ) == 0
|
||||
@ -9141,6 +9216,9 @@ spanner <OverallResult success="true"/>
|
||||
1 == 0
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Info>
|
||||
Testing if fib[5] (8) is even
|
||||
</Info>
|
||||
<Expression success="true" type="CHECK" filename="projects/<exe-name>/MiscTests.cpp" >
|
||||
<Original>
|
||||
( fib[i] % 2 ) == 0
|
||||
|
Loading…
Reference in New Issue
Block a user