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

XML Reporter closes tag and flushes stream at end of TestCase and Section tags.

This fixes an issue where XML reports on stdout are broken by printf statements
Commit
873ef276b6be03f0cdc7c95a76e98b8942b32cbc
Author
Phil Nash ·
Parents
bc68b9f45402

Files · Download .tar.gz

Changes

 include/internal/catch_xmlwriter.hpp                 | 14 +++++++-------
 include/reporters/catch_reporter_xml.hpp             |  2 ++
 projects/SelfTest/Baselines/console.std.approved.txt |  4 ++--
 projects/SelfTest/Baselines/console.sw.approved.txt  |  4 ++--
 projects/SelfTest/Baselines/junit.sw.approved.txt    |  2 +-
 projects/SelfTest/Baselines/xml.sw.approved.txt      |  3 +++
 projects/SelfTest/TrickyTests.cpp                    |  6 ++++++
 7 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/include/internal/catch_xmlwriter.hpp b/include/internal/catch_xmlwriter.hpp
index e29b1b41..ae59627c 100644
--- a/include/internal/catch_xmlwriter.hpp
+++ b/include/internal/catch_xmlwriter.hpp
@@ -211,6 +211,13 @@ namespace Catch {
             return *this;
         }
 
+        void ensureTagClosed() {
+            if( m_tagIsOpen ) {
+                m_os << ">" << std::endl;
+                m_tagIsOpen = false;
+            }
+        }
+
     private:
         XmlWriter( XmlWriter const& );
         void operator=( XmlWriter const& );
@@ -219,13 +226,6 @@ namespace Catch {
             m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
         }
 
-        void ensureTagClosed() {
-            if( m_tagIsOpen ) {
-                m_os << ">" << std::endl;
-                m_tagIsOpen = false;
-            }
-        }
-
         void newlineIfNecessary() {
             if( m_needsNewline ) {
                 m_os << std::endl;
diff --git a/include/reporters/catch_reporter_xml.hpp b/include/reporters/catch_reporter_xml.hpp
index 00baff93..d0a6689d 100644
--- a/include/reporters/catch_reporter_xml.hpp
+++ b/include/reporters/catch_reporter_xml.hpp
@@ -67,6 +67,7 @@ namespace Catch {
 
             if ( m_config->showDurations() == ShowDurations::Always )
                 m_testCaseTimer.start();
+            m_xml.ensureTagClosed();
         }
 
         virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
@@ -75,6 +76,7 @@ namespace Catch {
                 m_xml.startElement( "Section" )
                     .writeAttribute( "name", trim( sectionInfo.name ) )
                     .writeAttribute( "description", sectionInfo.description );
+                m_xml.ensureTagClosed();
             }
         }
 
diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt
index 42b01d02..bec5712c 100644
--- a/projects/SelfTest/Baselines/console.std.approved.txt
+++ b/projects/SelfTest/Baselines/console.std.approved.txt
@@ -711,7 +711,7 @@ MiscTests.cpp:<line number>: FAILED:
 with expansion:
   false
 
--------------------------------------------------------------------------------
+spanner-------------------------------------------------------------------------------
 just failure
 -------------------------------------------------------------------------------
 MessageTests.cpp:<line number>
@@ -829,6 +829,6 @@ with expansion:
   "first" == "second"
 
 ===============================================================================
-test cases: 160 | 116 passed | 42 failed |  2 failed as expected
+test cases: 161 | 117 passed | 42 failed |  2 failed as expected
 assertions: 932 | 836 passed | 78 failed | 18 failed as expected
 
diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt
index d48a03ff..4a4d9a38 100644
--- a/projects/SelfTest/Baselines/console.sw.approved.txt
+++ b/projects/SelfTest/Baselines/console.sw.approved.txt
@@ -8329,7 +8329,7 @@ MiscTests.cpp:<line number>
 MiscTests.cpp:<line number>:
 PASSED:
 
--------------------------------------------------------------------------------
+spanner-------------------------------------------------------------------------------
 just failure
 -------------------------------------------------------------------------------
 MessageTests.cpp:<line number>
@@ -9164,6 +9164,6 @@ MiscTests.cpp:<line number>:
 PASSED:
 
 ===============================================================================
-test cases: 160 | 115 passed | 43 failed |  2 failed as expected
+test cases: 161 | 116 passed | 43 failed |  2 failed as expected
 assertions: 934 | 836 passed | 80 failed | 18 failed as expected
 
diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt
index ad92d78a..4a1cb048 100644
--- a/projects/SelfTest/Baselines/junit.sw.approved.txt
+++ b/projects/SelfTest/Baselines/junit.sw.approved.txt
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<testsuites>
+<testsuitesspanner>
   <testsuite name="<exe-name>" errors="13" failures="68" tests="935" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <testcase classname="global" name="# A test name that starts with a #" time="{duration}"/>
     <testcase classname="global" name="#542" time="{duration}"/>
diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt
index c4a78b79..cfa7b1c5 100644
--- a/projects/SelfTest/Baselines/xml.sw.approved.txt
+++ b/projects/SelfTest/Baselines/xml.sw.approved.txt
@@ -8845,6 +8845,9 @@ there"
     <TestCase name="first tag" tags="[tag1]">
       <OverallResult success="true"/>
     </TestCase>
+    <TestCase name="has printf">
+spanner      <OverallResult success="true"/>
+    </TestCase>
     <TestCase name="just failure" tags="[.][fail][hide][isolated info][messages]">
       <Failure>
         Previous info should not be seen
diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp
index 90a4f2fa..f0311158 100644
--- a/projects/SelfTest/TrickyTests.cpp
+++ b/projects/SelfTest/TrickyTests.cpp
@@ -399,3 +399,9 @@ TEST_CASE( "X/level/0/a", "[Tricky]" )      { SUCCEED(""); }
 TEST_CASE( "X/level/0/b", "[Tricky][fizz]" ){ SUCCEED(""); }
 TEST_CASE( "X/level/1/a", "[Tricky]" )      { SUCCEED(""); }
 TEST_CASE( "X/level/1/b", "[Tricky]" )      { SUCCEED(""); }
+
+TEST_CASE( "has printf", "" ) {
+
+    // This can cause problems as, currently, stdout itself is not redirect - only the cout (and cerr) buffer
+    printf( "spanner" );
+}