24 std::string getCurrentTimestamp() {
29 auto const timeStampSize =
sizeof(
"2017-01-16T17:06:45Z");
32 std::tm timeInfo = {};
33 gmtime_s(&timeInfo, &rawtime);
36 timeInfo = std::gmtime(&rawtime);
39 char timeStamp[timeStampSize];
40 const char *
const fmt =
"%Y-%m-%dT%H:%M:%SZ";
43 std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
45 std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
47 return std::string(timeStamp);
50 std::string fileNameTag(
const std::vector<std::string> &tags) {
51 auto it = std::find_if(
begin(tags),
53 [] (std::string
const& tag) {
return tag.front() ==
'#'; });
62 xml( _config.stream() )
71 return "Reports test results in an XML format that looks like Ant's junitreport target";
146 for(
auto const& child : groupNode.children )
158 assert( testCaseNode.children.size() == 1 );
159 SectionNode
const& rootSection = *testCaseNode.children.front();
161 std::string className = stats.testInfo.className;
163 if( className.empty() ) {
164 className = fileNameTag(stats.testInfo.tags);
165 if ( className.empty() )
166 className =
"global";
170 className =
m_config->name() +
"." + className;
176 std::string
const& rootName,
177 SectionNode
const& sectionNode ) {
179 if( !rootName.empty() )
182 if( !sectionNode.assertions.empty() ||
183 !sectionNode.stdOut.empty() ||
184 !sectionNode.stdErr.empty() ) {
186 if( className.empty() ) {
198 if( !sectionNode.stdOut.empty() )
200 if( !sectionNode.stdErr.empty() )
203 for(
auto const& childNode : sectionNode.childSections )
204 if( className.empty() )
211 for(
auto const& assertion : sectionNode.assertions )
217 if( !result.isOk() ) {
218 std::string elementName;
219 switch( result.getResultType() ) {
222 elementName =
"error";
225 elementName =
"failure";
228 elementName =
"failure";
231 elementName =
"failure";
241 elementName =
"internalError";
251 if( !result.getMessage().empty() )
252 rss << result.getMessage() <<
'\n';
253 for(
auto const& msg : stats.infoMessages )
255 rss << msg.message <<
'\n';
257 rss <<
"at " << result.getSourceInfo();
#define CATCH_REGISTER_REPORTER(name, reporterType)
ResultWas::OfType getResultType() const
void writeGroup(TestGroupNode const &groupNode, double suiteTime)
void testCaseStarting(TestCaseInfo const &testCaseInfo) override
std::string stdErrForSuite
std::string stdOutForSuite
JunitReporter(ReporterConfig const &_config)
void testGroupStarting(GroupInfo const &groupInfo) override
void testRunStarting(TestRunInfo const &runInfo) override
void testRunEndedCumulative() override
void writeAssertion(AssertionStats const &stats)
~JunitReporter() override
void writeSection(std::string const &className, std::string const &rootName, SectionNode const §ionNode)
void testGroupEnded(TestGroupStats const &testGroupStats) override
void writeAssertions(SectionNode const §ionNode)
void testCaseEnded(TestCaseStats const &testCaseStats) override
void noMatchingTestCases(std::string const &) override
void writeTestCase(TestCaseNode const &testCaseNode)
static std::string getDescription()
unsigned int unexpectedExceptions
bool assertionEnded(AssertionStats const &assertionStats) override
auto str() const -> std::string
auto getElapsedSeconds() const -> double
ScopedElement & writeText(std::string const &text, bool indent=true)
ScopedElement & writeAttribute(std::string const &name, T const &attribute)
ScopedElement scopedElement(std::string const &name)
XmlWriter & writeText(std::string const &text, bool indent=true)
XmlWriter & startElement(std::string const &name)
XmlWriter & writeAttribute(std::string const &name, std::string const &attribute)
std::string stringify(const T &e)
std::string trim(std::string const &str)
std::string serializeFilters(std::vector< std::string > const &container)
AssertionResult assertionResult
Node< TestGroupStats, TestCaseNode > TestGroupNode
void testGroupStarting(GroupInfo const &) override
ReporterPreferences m_reporterPrefs
void testCaseEnded(TestCaseStats const &testCaseStats) override
void testGroupEnded(TestGroupStats const &testGroupStats) override
std::vector< std::shared_ptr< TestGroupNode > > m_testGroups
void testRunStarting(TestRunInfo const &) override
Node< TestCaseStats, SectionNode > TestCaseNode
bool assertionEnded(AssertionStats const &assertionStats) override
bool shouldReportAllAssertions
bool shouldRedirectStdOut