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

Specialize XML reporter's listener listing

Commit
ed6b38b096eac9a976e1fdeee5320fa913146af7
Author
Martin Hořeňovský ·
Parents
5a49285e9cf2

Files · Download .tar.gz

Changes

 src/catch2/reporters/catch_reporter_xml.cpp | 13 +++++++++++++
 src/catch2/reporters/catch_reporter_xml.hpp |  1 +
 tests/CMakeLists.txt                        | 12 +++++++++++-
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/catch2/reporters/catch_reporter_xml.cpp b/src/catch2/reporters/catch_reporter_xml.cpp
index b8b93235..1e5def41 100644
--- a/src/catch2/reporters/catch_reporter_xml.cpp
+++ b/src/catch2/reporters/catch_reporter_xml.cpp
@@ -259,6 +259,19 @@ namespace Catch {
         }
     }
 
+    void XmlReporter::listListeners(std::vector<ListenerDescription> const& descriptions) {
+        auto outerTag = m_xml.scopedElement( "RegisteredListeners" );
+        for ( auto const& listener : descriptions ) {
+            auto inner = m_xml.scopedElement( "Listener" );
+            m_xml.startElement( "Name", XmlFormatting::Indent )
+                .writeText( listener.name, XmlFormatting::None )
+                .endElement( XmlFormatting::Newline );
+            m_xml.startElement( "Description", XmlFormatting::Indent )
+                .writeText( listener.description, XmlFormatting::None )
+                .endElement( XmlFormatting::Newline );
+        }
+    }
+
     void XmlReporter::listTests(std::vector<TestCaseHandle> const& tests) {
         auto outerTag = m_xml.scopedElement("MatchingTests");
         for (auto const& test : tests) {
diff --git a/src/catch2/reporters/catch_reporter_xml.hpp b/src/catch2/reporters/catch_reporter_xml.hpp
index b557bfba..573f9321 100644
--- a/src/catch2/reporters/catch_reporter_xml.hpp
+++ b/src/catch2/reporters/catch_reporter_xml.hpp
@@ -51,6 +51,7 @@ namespace Catch {
         void benchmarkFailed( StringRef error ) override;
 
         void listReporters(std::vector<ReporterDescription> const& descriptions) override;
+        void listListeners(std::vector<ListenerDescription> const& descriptions) override;
         void listTests(std::vector<TestCaseHandle> const& tests) override;
         void listTags(std::vector<TagInfo> const& tags) override;
 
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index fa63e7c0..af4ca28e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -219,7 +219,17 @@ add_test(NAME List::Listeners::ExitCode
   COMMAND
     $<TARGET_FILE:SelfTest> --list-listeners
 )
-
+add_test(NAME List::Listeners::XmlOutput
+  COMMAND
+    $<TARGET_FILE:SelfTest>
+      --list-listeners
+      --reporter xml
+)
+set_tests_properties(List::Listeners::XmlOutput
+  PROPERTIES
+    PASS_REGULAR_EXPRESSION "<RegisteredListeners>"
+    FAIL_REGULAR_EXPRESSION "Registered listeners:"
+)
 
 add_test(NAME NoAssertions COMMAND $<TARGET_FILE:SelfTest> -w NoAssertions "An empty test with no assertions")
 set_tests_properties(NoAssertions PROPERTIES PASS_REGULAR_EXPRESSION "No assertions in test case")