mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Specialize XML reporter's --list output
This commit is contained in:
parent
85b129c741
commit
be44cfa63b
@ -29,13 +29,6 @@ method will be removed.
|
||||
|
||||
## Planned changes
|
||||
|
||||
### Output format of `--list-*` command line parameters
|
||||
|
||||
The various list operations will be piped through reporters. This means
|
||||
that e.g. XML reporter will write the output as machine-parseable XML,
|
||||
while the Console reporter will keep the current, human-oriented output.
|
||||
|
||||
|
||||
### `CHECKED_IF` and `CHECKED_ELSE`
|
||||
|
||||
To make the `CHECKED_IF` and `CHECKED_ELSE` macros more useful, they will
|
||||
|
@ -37,6 +37,9 @@
|
||||
* `--list*` commands no longer have non-zero return code (#1410)
|
||||
* `--list-test-names-only` has been removed (#1190)
|
||||
* You should use verbosity-modifiers for `--list-tests` instead
|
||||
* `--list*` commands are now piped through the reporters
|
||||
* The top-level reporter interface provides default implementation that works just as the old one
|
||||
* XmlReporter outputs a machine-parseable XML
|
||||
|
||||
### Fixes
|
||||
* The `INFO` macro no longer contains superfluous semicolon (#1456)
|
||||
|
@ -261,6 +261,11 @@ namespace Catch {
|
||||
|
||||
void assertionStarting(AssertionInfo const&) override;
|
||||
bool assertionEnded(AssertionStats const&) override;
|
||||
|
||||
// Event listeners should not use the default listing impl
|
||||
void listReporters(std::vector<ReporterDescription> const&, Config const&) override {}
|
||||
void listTests(std::vector<TestCase> const&, Config const&) override {}
|
||||
void listTags(std::vector<TagInfo> const&, Config const&) override {}
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
@ -36,13 +36,13 @@ namespace Catch {
|
||||
}
|
||||
m_reporter->noMatchingTestCases( spec );
|
||||
}
|
||||
|
||||
|
||||
void ListeningReporter::reportInvalidArguments(std::string const&arg){
|
||||
for ( auto const& listener : m_listeners ) {
|
||||
listener->reportInvalidArguments( arg );
|
||||
}
|
||||
m_reporter->reportInvalidArguments( arg );
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
|
||||
void ListeningReporter::benchmarkPreparing( std::string const& name ) {
|
||||
@ -156,4 +156,25 @@ namespace Catch {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
void ListeningReporter::listReporters(std::vector<ReporterDescription> const& descriptions, Config const& config) {
|
||||
for (auto const& listener : m_listeners) {
|
||||
listener->listReporters(descriptions, config);
|
||||
}
|
||||
m_reporter->listReporters(descriptions, config);
|
||||
}
|
||||
|
||||
void ListeningReporter::listTests(std::vector<TestCase> const& tests, Config const& config) {
|
||||
for (auto const& listener : m_listeners) {
|
||||
listener->listTests(tests, config);
|
||||
}
|
||||
m_reporter->listTests(tests, config);
|
||||
}
|
||||
|
||||
void ListeningReporter::listTags(std::vector<TagInfo> const& tags, Config const& config) {
|
||||
for (auto const& listener : m_listeners) {
|
||||
listener->listTags(tags, config);
|
||||
}
|
||||
m_reporter->listTags(tags, config);
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
@ -54,6 +54,11 @@ namespace Catch {
|
||||
void skipTest( TestCaseInfo const& testInfo ) override;
|
||||
bool isMulti() const override;
|
||||
|
||||
void listReporters(std::vector<ReporterDescription> const& descriptions, Config const& config) override;
|
||||
void listTests(std::vector<TestCase> const& tests, Config const& config) override;
|
||||
void listTags(std::vector<TagInfo> const& tags, Config const& config) override;
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "../internal/catch_capture.hpp"
|
||||
#include "../internal/catch_reporter_registrars.hpp"
|
||||
#include "../internal/catch_list.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
@ -264,6 +265,64 @@ namespace Catch {
|
||||
}
|
||||
#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
|
||||
|
||||
void XmlReporter::listReporters(std::vector<ReporterDescription> const& descriptions, Config const&) {
|
||||
auto outerTag = m_xml.scopedElement("AvailableReporters");
|
||||
for (auto const& reporter : descriptions) {
|
||||
auto inner = m_xml.scopedElement("Reporter");
|
||||
m_xml.startElement("Name", XmlFormatting::Indent)
|
||||
.writeText(reporter.name, XmlFormatting::None)
|
||||
.endElement(XmlFormatting::Newline);
|
||||
m_xml.startElement("Description", XmlFormatting::Indent)
|
||||
.writeText(reporter.description, XmlFormatting::None)
|
||||
.endElement(XmlFormatting::Newline);
|
||||
}
|
||||
}
|
||||
|
||||
void XmlReporter::listTests(std::vector<TestCase> const& tests, Config const&) {
|
||||
auto outerTag = m_xml.scopedElement("MatchingTests");
|
||||
for (auto const& test : tests) {
|
||||
auto innerTag = m_xml.scopedElement("TestCase");
|
||||
auto const& testInfo = test.getTestCaseInfo();
|
||||
m_xml.startElement("Name", XmlFormatting::Indent)
|
||||
.writeText(testInfo.name, XmlFormatting::None)
|
||||
.endElement(XmlFormatting::Newline);
|
||||
m_xml.startElement("ClassName", XmlFormatting::Indent)
|
||||
.writeText(testInfo.className, XmlFormatting::None)
|
||||
.endElement(XmlFormatting::Newline);
|
||||
m_xml.startElement("Description", XmlFormatting::Indent)
|
||||
.writeText(testInfo.description, XmlFormatting::None)
|
||||
.endElement(XmlFormatting::Newline);
|
||||
m_xml.startElement("Tags", XmlFormatting::Indent)
|
||||
.writeText(testInfo.tagsAsString(), XmlFormatting::None)
|
||||
.endElement(XmlFormatting::Newline);
|
||||
|
||||
auto sourceTag = m_xml.scopedElement("SourceInfo");
|
||||
m_xml.startElement("File", XmlFormatting::Indent)
|
||||
.writeText(testInfo.lineInfo.file, XmlFormatting::None)
|
||||
.endElement(XmlFormatting::Newline);
|
||||
m_xml.startElement("Line", XmlFormatting::Indent)
|
||||
.writeText(std::to_string(testInfo.lineInfo.line), XmlFormatting::None)
|
||||
.endElement(XmlFormatting::Newline);
|
||||
}
|
||||
}
|
||||
|
||||
void XmlReporter::listTags(std::vector<TagInfo> const& tags, Config const&) {
|
||||
auto outerTag = m_xml.scopedElement("TagsFromMatchingTests");
|
||||
for (auto const& tag : tags) {
|
||||
auto innerTag = m_xml.scopedElement("Tag");
|
||||
m_xml.startElement("Count", XmlFormatting::Indent)
|
||||
.writeText(std::to_string(tag.count), XmlFormatting::None)
|
||||
.endElement(XmlFormatting::Newline);
|
||||
auto aliasTag = m_xml.scopedElement("Aliases");
|
||||
for (auto const& alias : tag.spellings) {
|
||||
m_xml.startElement("Alias", XmlFormatting::Indent)
|
||||
.writeText(alias, XmlFormatting::None)
|
||||
.endElement(XmlFormatting::Newline);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CATCH_REGISTER_REPORTER( "xml", XmlReporter )
|
||||
|
||||
} // end namespace Catch
|
||||
|
@ -57,6 +57,10 @@ namespace Catch {
|
||||
void benchmarkFailed(std::string const&) override;
|
||||
#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
|
||||
|
||||
void listReporters(std::vector<ReporterDescription> const& descriptions, Config const& config) override;
|
||||
void listTests(std::vector<TestCase> const& tests, Config const& config) override;
|
||||
void listTags(std::vector<TagInfo> const& tags, Config const& config) override;
|
||||
|
||||
private:
|
||||
Timer m_testCaseTimer;
|
||||
XmlWriter m_xml;
|
||||
|
@ -385,16 +385,32 @@ set_tests_properties(List::Tests::Output PROPERTIES
|
||||
FAIL_REGULAR_EXPRESSION "Hidden Test"
|
||||
)
|
||||
add_test(NAME List::Tests::ExitCode COMMAND $<TARGET_FILE:SelfTest> --list-tests --verbosity high)
|
||||
add_test(NAME List::Tests::XmlOutput COMMAND $<TARGET_FILE:SelfTest> --list-tests --verbosity high -r xml)
|
||||
set_tests_properties(List::Tests::XmlOutput PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "<Line>[0-9]+</Line>"
|
||||
FAIL_REGULAR_EXPRESSION "[0-9]+ test cases"
|
||||
)
|
||||
|
||||
add_test(NAME List::Tags::Output COMMAND $<TARGET_FILE:SelfTest> --list-tags)
|
||||
set_tests_properties(List::Tags::Output PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "[0-9]+ tags"
|
||||
FAIL_REGULAR_EXPRESSION "\\[\\.\\]")
|
||||
add_test(NAME List::Tags::ExitCode COMMAND $<TARGET_FILE:SelfTest> --list-tags)
|
||||
add_test(NAME List::Tags::XmlOutput COMMAND $<TARGET_FILE:SelfTest> --list-tags -r xml)
|
||||
set_tests_properties(List::Tags::XmlOutput PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "<Count>18</Count>"
|
||||
FAIL_REGULAR_EXPRESSION "[0-9]+ tags"
|
||||
)
|
||||
|
||||
|
||||
add_test(NAME List::Reporters::Output COMMAND $<TARGET_FILE:SelfTest> --list-reporters)
|
||||
set_tests_properties(List::Reporters::Output PROPERTIES PASS_REGULAR_EXPRESSION "Available reporters:")
|
||||
add_test(NAME List::Reporters::ExitCode COMMAND $<TARGET_FILE:SelfTest> --list-reporters)
|
||||
add_test(NAME List::Reporters::XmlOutput COMMAND $<TARGET_FILE:SelfTest> --list-reporters -r xml)
|
||||
set_tests_properties(List::Reporters::XmlOutput PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "<Name>compact</Name>"
|
||||
FAIL_REGULAR_EXPRESSION "Available reporters:"
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user