Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
Catch::JunitReporter Class Reference

#include <catch_reporter_junit.h>

Inheritance diagram for Catch::JunitReporter:
Collaboration diagram for Catch::JunitReporter:

Public Member Functions

 JunitReporter (ReporterConfig const &_config)
 
 ~JunitReporter () override
 
void noMatchingTestCases (std::string const &) override
 
void testRunStarting (TestRunInfo const &runInfo) override
 
void testGroupStarting (GroupInfo const &groupInfo) override
 
void testCaseStarting (TestCaseInfo const &testCaseInfo) override
 
bool assertionEnded (AssertionStats const &assertionStats) override
 
void testCaseEnded (TestCaseStats const &testCaseStats) override
 
void testGroupEnded (TestGroupStats const &testGroupStats) override
 
void testRunEndedCumulative () override
 
void writeGroup (TestGroupNode const &groupNode, double suiteTime)
 
void writeTestCase (TestCaseNode const &testCaseNode)
 
void writeSection (std::string const &className, std::string const &rootName, SectionNode const &sectionNode)
 
void writeAssertions (SectionNode const &sectionNode)
 
void writeAssertion (AssertionStats const &stats)
 
- Public Member Functions inherited from Catch::CumulativeReporterBase< JunitReporter >
 CumulativeReporterBase (ReporterConfig const &_config)
 
 ~CumulativeReporterBase () override=default
 
ReporterPreferences getPreferences () const override
 
void sectionStarting (SectionInfo const &sectionInfo) override
 
void assertionStarting (AssertionInfo const &) override
 
void sectionEnded (SectionStats const &sectionStats) override
 
void testRunEnded (TestRunStats const &testRunStats) override
 
void skipTest (TestCaseInfo const &) override
 
- Public Member Functions inherited from Catch::IStreamingReporter
virtual ~IStreamingReporter ()=default
 
virtual void benchmarkStarting (BenchmarkInfo const &)
 
virtual void benchmarkEnded (BenchmarkStats const &)
 
virtual void fatalErrorEncountered (StringRef name)
 
virtual bool isMulti () const
 

Static Public Member Functions

static std::string getDescription ()
 
- Static Public Member Functions inherited from Catch::CumulativeReporterBase< JunitReporter >
static std::set< VerbositygetSupportedVerbosities ()
 

Public Attributes

XmlWriter xml
 
Timer suiteTimer
 
std::string stdOutForSuite
 
std::string stdErrForSuite
 
unsigned int unexpectedExceptions = 0
 
bool m_okToFail = false
 
- Public Attributes inherited from Catch::CumulativeReporterBase< JunitReporter >
IConfigPtr m_config
 
std::ostream & stream
 
std::vector< AssertionStatsm_assertions
 
std::vector< std::vector< std::shared_ptr< SectionNode > > > m_sections
 
std::vector< std::shared_ptr< TestCaseNode > > m_testCases
 
std::vector< std::shared_ptr< TestGroupNode > > m_testGroups
 
std::vector< std::shared_ptr< TestRunNode > > m_testRuns
 
std::shared_ptr< SectionNode > m_rootSection
 
std::shared_ptr< SectionNode > m_deepestSection
 
std::vector< std::shared_ptr< SectionNode > > m_sectionStack
 
ReporterPreferences m_reporterPrefs
 

Additional Inherited Members

- Public Types inherited from Catch::CumulativeReporterBase< JunitReporter >
using TestCaseNode
 
using TestGroupNode
 
using TestRunNode
 

Detailed Description

Definition at line 17 of file catch_reporter_junit.h.

Constructor & Destructor Documentation

◆ JunitReporter()

Catch::JunitReporter::JunitReporter ( ReporterConfig const & _config)

◆ ~JunitReporter()

Catch::JunitReporter::~JunitReporter ( )
override

Definition at line 68 of file catch_reporter_junit.cpp.

68{}

Member Function Documentation

◆ assertionEnded()

bool Catch::JunitReporter::assertionEnded ( AssertionStats const & assertionStats)
overridevirtual

Reimplemented from Catch::CumulativeReporterBase< JunitReporter >.

Definition at line 93 of file catch_reporter_junit.cpp.

93 {
94 if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException && !m_okToFail )
96 return CumulativeReporterBase::assertionEnded( assertionStats );
97 }
bool assertionEnded(AssertionStats const &assertionStats) override
Here is the call graph for this function:

◆ getDescription()

std::string Catch::JunitReporter::getDescription ( )
static

Definition at line 70 of file catch_reporter_junit.cpp.

70 {
71 return "Reports test results in an XML format that looks like Ant's junitreport target";
72 }

◆ noMatchingTestCases()

void Catch::JunitReporter::noMatchingTestCases ( std::string const & )
overridevirtual

Implements Catch::IStreamingReporter.

Definition at line 74 of file catch_reporter_junit.cpp.

74{}

◆ testCaseEnded()

void Catch::JunitReporter::testCaseEnded ( TestCaseStats const & testCaseStats)
overridevirtual

Reimplemented from Catch::CumulativeReporterBase< JunitReporter >.

Definition at line 99 of file catch_reporter_junit.cpp.

99 {
100 stdOutForSuite += testCaseStats.stdOut;
101 stdErrForSuite += testCaseStats.stdErr;
103 }
void testCaseEnded(TestCaseStats const &testCaseStats) override
Here is the call graph for this function:

◆ testCaseStarting()

void Catch::JunitReporter::testCaseStarting ( TestCaseInfo const & testCaseInfo)
overridevirtual

Reimplemented from Catch::CumulativeReporterBase< JunitReporter >.

Definition at line 89 of file catch_reporter_junit.cpp.

89 {
90 m_okToFail = testCaseInfo.okToFail();
91 }
Here is the call graph for this function:

◆ testGroupEnded()

void Catch::JunitReporter::testGroupEnded ( TestGroupStats const & testGroupStats)
overridevirtual

Reimplemented from Catch::CumulativeReporterBase< JunitReporter >.

Definition at line 105 of file catch_reporter_junit.cpp.

105 {
106 double suiteTime = suiteTimer.getElapsedSeconds();
108 writeGroup( *m_testGroups.back(), suiteTime );
109 }
void writeGroup(TestGroupNode const &groupNode, double suiteTime)
auto getElapsedSeconds() const -> double
void testGroupEnded(TestGroupStats const &testGroupStats) override
std::vector< std::shared_ptr< TestGroupNode > > m_testGroups
Here is the call graph for this function:

◆ testGroupStarting()

void Catch::JunitReporter::testGroupStarting ( GroupInfo const & groupInfo)
overridevirtual

Reimplemented from Catch::CumulativeReporterBase< JunitReporter >.

Definition at line 81 of file catch_reporter_junit.cpp.

81 {
83 stdOutForSuite.clear();
84 stdErrForSuite.clear();
87 }
void testGroupStarting(GroupInfo const &) override
Here is the call graph for this function:

◆ testRunEndedCumulative()

void Catch::JunitReporter::testRunEndedCumulative ( )
overridevirtual

Implements Catch::CumulativeReporterBase< JunitReporter >.

Definition at line 111 of file catch_reporter_junit.cpp.

111 {
112 xml.endElement();
113 }
XmlWriter & endElement()
Here is the call graph for this function:

◆ testRunStarting()

void Catch::JunitReporter::testRunStarting ( TestRunInfo const & runInfo)
overridevirtual

Reimplemented from Catch::CumulativeReporterBase< JunitReporter >.

Definition at line 76 of file catch_reporter_junit.cpp.

76 {
78 xml.startElement( "testsuites" );
79 }
XmlWriter & startElement(std::string const &name)
void testRunStarting(TestRunInfo const &) override
Here is the call graph for this function:

◆ writeAssertion()

void Catch::JunitReporter::writeAssertion ( AssertionStats const & stats)

Definition at line 215 of file catch_reporter_junit.cpp.

215 {
216 AssertionResult const& result = stats.assertionResult;
217 if( !result.isOk() ) {
218 std::string elementName;
219 switch( result.getResultType() ) {
222 elementName = "error";
223 break;
225 elementName = "failure";
226 break;
228 elementName = "failure";
229 break;
231 elementName = "failure";
232 break;
233
234 // We should never see these here:
235 case ResultWas::Info:
237 case ResultWas::Ok:
241 elementName = "internalError";
242 break;
243 }
244
245 XmlWriter::ScopedElement e = xml.scopedElement( elementName );
246
247 xml.writeAttribute( "message", result.getExpandedExpression() );
248 xml.writeAttribute( "type", result.getTestMacroName() );
249
250 ReusableStringStream rss;
251 if( !result.getMessage().empty() )
252 rss << result.getMessage() << '\n';
253 for( auto const& msg : stats.infoMessages )
254 if( msg.type == ResultWas::Info )
255 rss << msg.message << '\n';
256
257 rss << "at " << result.getSourceInfo();
258 xml.writeText( rss.str(), false );
259 }
260 }
ScopedElement scopedElement(std::string const &name)
XmlWriter & writeText(std::string const &text, bool indent=true)
XmlWriter & writeAttribute(std::string const &name, std::string const &attribute)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeAssertions()

void Catch::JunitReporter::writeAssertions ( SectionNode const & sectionNode)

Definition at line 210 of file catch_reporter_junit.cpp.

210 {
211 for( auto const& assertion : sectionNode.assertions )
212 writeAssertion( assertion );
213 }
void writeAssertion(AssertionStats const &stats)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeGroup()

void Catch::JunitReporter::writeGroup ( TestGroupNode const & groupNode,
double suiteTime )

Definition at line 115 of file catch_reporter_junit.cpp.

115 {
116 XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" );
117
118 TestGroupStats const& stats = groupNode.value;
119 xml.writeAttribute( "name", stats.groupInfo.name );
121 xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions );
122 xml.writeAttribute( "tests", stats.totals.assertions.total() );
123 xml.writeAttribute( "hostname", "tbd" ); // !TBD
124 if( m_config->showDurations() == ShowDurations::Never )
125 xml.writeAttribute( "time", "" );
126 else
127 xml.writeAttribute( "time", suiteTime );
128 xml.writeAttribute( "timestamp", getCurrentTimestamp() );
129
130 // Write properties if there are any
131 if (m_config->hasTestFilters() || m_config->rngSeed() != 0) {
132 auto properties = xml.scopedElement("properties");
133 if (m_config->hasTestFilters()) {
134 xml.scopedElement("property")
135 .writeAttribute("name", "filters")
136 .writeAttribute("value", serializeFilters(m_config->getTestsOrTags()));
137 }
138 if (m_config->rngSeed() != 0) {
139 xml.scopedElement("property")
140 .writeAttribute("name", "random-seed")
141 .writeAttribute("value", m_config->rngSeed());
142 }
143 }
144
145 // Write test cases
146 for( auto const& child : groupNode.children )
147 writeTestCase( *child );
148
149 xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite ), false );
150 xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite ), false );
151 }
void writeTestCase(TestCaseNode const &testCaseNode)
ScopedElement & writeText(std::string const &text, bool indent=true)
ScopedElement & writeAttribute(std::string const &name, T const &attribute)
std::string trim(std::string const &str)
std::string serializeFilters(std::vector< std::string > const &container)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeSection()

void Catch::JunitReporter::writeSection ( std::string const & className,
std::string const & rootName,
SectionNode const & sectionNode )

Definition at line 175 of file catch_reporter_junit.cpp.

177 {
178 std::string name = trim( sectionNode.stats.sectionInfo.name );
179 if( !rootName.empty() )
180 name = rootName + '/' + name;
181
182 if( !sectionNode.assertions.empty() ||
183 !sectionNode.stdOut.empty() ||
184 !sectionNode.stdErr.empty() ) {
185 XmlWriter::ScopedElement e = xml.scopedElement( "testcase" );
186 if( className.empty() ) {
187 xml.writeAttribute( "classname", name );
188 xml.writeAttribute( "name", "root" );
189 }
190 else {
191 xml.writeAttribute( "classname", className );
192 xml.writeAttribute( "name", name );
193 }
194 xml.writeAttribute( "time", ::Catch::Detail::stringify( sectionNode.stats.durationInSeconds ) );
195
196 writeAssertions( sectionNode );
197
198 if( !sectionNode.stdOut.empty() )
199 xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false );
200 if( !sectionNode.stdErr.empty() )
201 xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false );
202 }
203 for( auto const& childNode : sectionNode.childSections )
204 if( className.empty() )
205 writeSection( name, "", *childNode );
206 else
207 writeSection( className, name, *childNode );
208 }
std::string name
void writeSection(std::string const &className, std::string const &rootName, SectionNode const &sectionNode)
void writeAssertions(SectionNode const &sectionNode)
std::string stringify(const T &e)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeTestCase()

void Catch::JunitReporter::writeTestCase ( TestCaseNode const & testCaseNode)

Definition at line 153 of file catch_reporter_junit.cpp.

153 {
154 TestCaseStats const& stats = testCaseNode.value;
155
156 // All test cases have exactly one section - which represents the
157 // test case itself. That section may have 0-n nested sections
158 assert( testCaseNode.children.size() == 1 );
159 SectionNode const& rootSection = *testCaseNode.children.front();
160
161 std::string className = stats.testInfo.className;
162
163 if( className.empty() ) {
164 className = fileNameTag(stats.testInfo.tags);
165 if ( className.empty() )
166 className = "global";
167 }
168
169 if ( !m_config->name().empty() )
170 className = m_config->name() + "." + className;
171
172 writeSection( className, "", rootSection );
173 }
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_okToFail

bool Catch::JunitReporter::m_okToFail = false

Definition at line 56 of file catch_reporter_junit.h.

◆ stdErrForSuite

std::string Catch::JunitReporter::stdErrForSuite

Definition at line 54 of file catch_reporter_junit.h.

◆ stdOutForSuite

std::string Catch::JunitReporter::stdOutForSuite

Definition at line 53 of file catch_reporter_junit.h.

◆ suiteTimer

Timer Catch::JunitReporter::suiteTimer

Definition at line 52 of file catch_reporter_junit.h.

◆ unexpectedExceptions

unsigned int Catch::JunitReporter::unexpectedExceptions = 0

Definition at line 55 of file catch_reporter_junit.h.

◆ xml

XmlWriter Catch::JunitReporter::xml

Definition at line 51 of file catch_reporter_junit.h.


The documentation for this class was generated from the following files: