Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Tweaked Xml Reporter to follow same success/ info behaviour as Console reporter

Commit
9bee606dd633586fdfc5365abd5b0c9ba923fd4a
Author
Phil Nash ·
Parents
be4f6ab8e19f

Files · Download .tar.gz

Changes

 include/reporters/catch_reporter_xml.hpp        | 50 ++++++++--------
 projects/SelfTest/Baselines/xml.sw.approved.txt | 78 +++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 23 deletions(-)

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 <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() ) {
+            if( result.hasExpression() ) {
                 m_xml.startElement( "Expression" )
-                    .writeAttribute( "success", assertionResult.succeeded() )
-                    .writeAttribute( "type", assertionResult.getTestMacroName() );
+                    .writeAttribute( "success", result.succeeded() )
+                    .writeAttribute( "type", result.getTestMacroName() );
 
-                writeSourceInfo( assertionResult.getSourceInfo() );
+                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 @@
     </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 &lt; 10
@@ -6769,6 +6787,12 @@ re>"
           0 &lt; 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 &lt; 10
@@ -6777,6 +6801,12 @@ re>"
           1 &lt; 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 &lt; 10
@@ -6785,6 +6815,12 @@ re>"
           2 &lt; 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 &lt; 10
@@ -6793,6 +6829,12 @@ re>"
           3 &lt; 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 &lt; 10
@@ -6801,6 +6843,12 @@ re>"
           4 &lt; 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 &lt; 10
@@ -6809,6 +6857,12 @@ re>"
           5 &lt; 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 &lt; 10
@@ -6817,6 +6871,12 @@ re>"
           6 &lt; 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 &lt; 10
@@ -6825,6 +6885,12 @@ re>"
           7 &lt; 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 &lt; 10
@@ -6833,6 +6899,12 @@ re>"
           8 &lt; 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 &lt; 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