Specialize XML reporter's listener listing

This commit is contained in:
Martin Hořeňovský 2022-05-10 20:52:53 +02:00
parent 5a49285e9c
commit ed6b38b096
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
3 changed files with 25 additions and 1 deletions

View File

@ -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) { void XmlReporter::listTests(std::vector<TestCaseHandle> const& tests) {
auto outerTag = m_xml.scopedElement("MatchingTests"); auto outerTag = m_xml.scopedElement("MatchingTests");
for (auto const& test : tests) { for (auto const& test : tests) {

View File

@ -51,6 +51,7 @@ namespace Catch {
void benchmarkFailed( StringRef error ) override; void benchmarkFailed( StringRef error ) override;
void listReporters(std::vector<ReporterDescription> const& descriptions) 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 listTests(std::vector<TestCaseHandle> const& tests) override;
void listTags(std::vector<TagInfo> const& tags) override; void listTags(std::vector<TagInfo> const& tags) override;

View File

@ -219,7 +219,17 @@ add_test(NAME List::Listeners::ExitCode
COMMAND COMMAND
$<TARGET_FILE:SelfTest> --list-listeners $<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") 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") set_tests_properties(NoAssertions PROPERTIES PASS_REGULAR_EXPRESSION "No assertions in test case")