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

XmlWriter can specify a stylesheet

Provide an extension point on XmlReporter to be able to supply a stylesheet url in a derived implementation
Commit
97d8003a713117df078208c55cd762e135396359
Author
Phil Nash ·
Parents
1f271c994470

Files · Download .tar.gz

Changes

 include/internal/catch_xmlwriter.hpp     | 8 ++++++--
 include/reporters/catch_reporter_xml.hpp | 7 +++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/include/internal/catch_xmlwriter.hpp b/include/internal/catch_xmlwriter.hpp
index 5ae7efd0..e29b1b41 100644
--- a/include/internal/catch_xmlwriter.hpp
+++ b/include/internal/catch_xmlwriter.hpp
@@ -201,6 +201,10 @@ namespace Catch {
             return *this;
         }
 
+        void writeStylesheetRef( std::string const& url ) {
+            m_os << "<?xml-stylesheet type=\"text/xsl\" href=\"" << url << "\"?>\n";
+        }
+
         XmlWriter& writeBlankLine() {
             ensureTagClosed();
             m_os << '\n';
@@ -217,14 +221,14 @@ namespace Catch {
 
         void ensureTagClosed() {
             if( m_tagIsOpen ) {
-                m_os << ">\n";
+                m_os << ">" << std::endl;
                 m_tagIsOpen = false;
             }
         }
 
         void newlineIfNecessary() {
             if( m_needsNewline ) {
-                m_os << '\n';
+                m_os << std::endl;
                 m_needsNewline = false;
             }
         }
diff --git a/include/reporters/catch_reporter_xml.hpp b/include/reporters/catch_reporter_xml.hpp
index df6eb07c..eb23224b 100644
--- a/include/reporters/catch_reporter_xml.hpp
+++ b/include/reporters/catch_reporter_xml.hpp
@@ -32,6 +32,10 @@ namespace Catch {
             return "Reports test results as an XML document";
         }
 
+        virtual std::string getStylesheetRef() const {
+            return std::string();
+        }
+
     public: // StreamingReporterBase
 
         virtual void noMatchingTestCases( std::string const& s ) CATCH_OVERRIDE {
@@ -40,6 +44,9 @@ namespace Catch {
 
         virtual void testRunStarting( TestRunInfo const& testInfo ) CATCH_OVERRIDE {
             StreamingReporterBase::testRunStarting( testInfo );
+            std::string stylesheetRef = getStylesheetRef();
+            if( !stylesheetRef.empty() )
+                m_xml.writeStylesheetRef( stylesheetRef );
             m_xml.startElement( "Catch" );
             if( !m_config->name().empty() )
                 m_xml.writeAttribute( "name", m_config->name() );