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

#include <catch_reporter_xml.h>

Inheritance diagram for Catch::XmlReporter:
Collaboration diagram for Catch::XmlReporter:

Public Member Functions

 XmlReporter (ReporterConfig const &_config)
 
 ~XmlReporter () override
 
virtual std::string getStylesheetRef () const
 
void writeSourceInfo (SourceLineInfo const &sourceInfo)
 
void noMatchingTestCases (std::string const &s) override
 
void testRunStarting (TestRunInfo const &testInfo) override
 
void testGroupStarting (GroupInfo const &groupInfo) override
 
void testCaseStarting (TestCaseInfo const &testInfo) override
 
void sectionStarting (SectionInfo const &sectionInfo) override
 
void assertionStarting (AssertionInfo const &) override
 
bool assertionEnded (AssertionStats const &assertionStats) override
 
void sectionEnded (SectionStats const &sectionStats) override
 
void testCaseEnded (TestCaseStats const &testCaseStats) override
 
void testGroupEnded (TestGroupStats const &testGroupStats) override
 
void testRunEnded (TestRunStats const &testRunStats) override
 
- Public Member Functions inherited from Catch::StreamingReporterBase< XmlReporter >
 StreamingReporterBase (ReporterConfig const &_config)
 
ReporterPreferences getPreferences () const override
 
 ~StreamingReporterBase () override=default
 
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::StreamingReporterBase< XmlReporter >
static std::set< VerbositygetSupportedVerbosities ()
 

Additional Inherited Members

- Public Attributes inherited from Catch::StreamingReporterBase< XmlReporter >
IConfigPtr m_config
 
std::ostream & stream
 
LazyStat< TestRunInfocurrentTestRunInfo
 
LazyStat< GroupInfocurrentGroupInfo
 
LazyStat< TestCaseInfocurrentTestCaseInfo
 
std::vector< SectionInfom_sectionStack
 
ReporterPreferences m_reporterPrefs
 

Detailed Description

Definition at line 17 of file catch_reporter_xml.h.

Constructor & Destructor Documentation

◆ XmlReporter()

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

◆ ~XmlReporter()

Catch::XmlReporter::~XmlReporter ( )
overridedefault

Member Function Documentation

◆ assertionEnded()

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

Implements Catch::IStreamingReporter.

Definition at line 97 of file catch_reporter_xml.cpp.

97 {
98
99 AssertionResult const& result = assertionStats.assertionResult;
100
101 bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
102
103 if( includeResults || result.getResultType() == ResultWas::Warning ) {
104 // Print any info messages in <Info> tags.
105 for( auto const& msg : assertionStats.infoMessages ) {
106 if( msg.type == ResultWas::Info && includeResults ) {
107 m_xml.scopedElement( "Info" )
108 .writeText( msg.message );
109 } else if ( msg.type == ResultWas::Warning ) {
110 m_xml.scopedElement( "Warning" )
111 .writeText( msg.message );
112 }
113 }
114 }
115
116 // Drop out if result was successful but we're not printing them.
117 if( !includeResults && result.getResultType() != ResultWas::Warning )
118 return true;
119
120
121 // Print the expression if there is one.
122 if( result.hasExpression() ) {
123 m_xml.startElement( "Expression" )
124 .writeAttribute( "success", result.succeeded() )
125 .writeAttribute( "type", result.getTestMacroName() );
126
127 writeSourceInfo( result.getSourceInfo() );
128
129 m_xml.scopedElement( "Original" )
130 .writeText( result.getExpression() );
131 m_xml.scopedElement( "Expanded" )
132 .writeText( result.getExpandedExpression() );
133 }
134
135 // And... Print a result applicable to each result type.
136 switch( result.getResultType() ) {
138 m_xml.startElement( "Exception" );
139 writeSourceInfo( result.getSourceInfo() );
140 m_xml.writeText( result.getMessage() );
141 m_xml.endElement();
142 break;
144 m_xml.startElement( "FatalErrorCondition" );
145 writeSourceInfo( result.getSourceInfo() );
146 m_xml.writeText( result.getMessage() );
147 m_xml.endElement();
148 break;
149 case ResultWas::Info:
150 m_xml.scopedElement( "Info" )
151 .writeText( result.getMessage() );
152 break;
154 // Warning will already have been written
155 break;
157 m_xml.startElement( "Failure" );
158 writeSourceInfo( result.getSourceInfo() );
159 m_xml.writeText( result.getMessage() );
160 m_xml.endElement();
161 break;
162 default:
163 break;
164 }
165
166 if( result.hasExpression() )
167 m_xml.endElement();
168
169 return true;
170 }
void writeSourceInfo(SourceLineInfo const &sourceInfo)
ScopedElement & writeText(std::string const &text, bool indent=true)
ScopedElement scopedElement(std::string const &name)
XmlWriter & writeText(std::string const &text, bool indent=true)
XmlWriter & startElement(std::string const &name)
XmlWriter & endElement()
XmlWriter & writeAttribute(std::string const &name, std::string const &attribute)
Here is the call graph for this function:

◆ assertionStarting()

void Catch::XmlReporter::assertionStarting ( AssertionInfo const & )
overridevirtual

Implements Catch::IStreamingReporter.

Definition at line 95 of file catch_reporter_xml.cpp.

95{ }

◆ getDescription()

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

Definition at line 32 of file catch_reporter_xml.cpp.

32 {
33 return "Reports test results as an XML document";
34 }

◆ getStylesheetRef()

std::string Catch::XmlReporter::getStylesheetRef ( ) const
virtual

Definition at line 36 of file catch_reporter_xml.cpp.

36 {
37 return std::string();
38 }
Here is the caller graph for this function:

◆ noMatchingTestCases()

void Catch::XmlReporter::noMatchingTestCases ( std::string const & s)
overridevirtual

Reimplemented from Catch::StreamingReporterBase< XmlReporter >.

Definition at line 46 of file catch_reporter_xml.cpp.

46 {
48 }
void noMatchingTestCases(std::string const &) override
char * s
Here is the call graph for this function:

◆ sectionEnded()

void Catch::XmlReporter::sectionEnded ( SectionStats const & sectionStats)
overridevirtual

Reimplemented from Catch::StreamingReporterBase< XmlReporter >.

Definition at line 172 of file catch_reporter_xml.cpp.

172 {
174 if( --m_sectionDepth > 0 ) {
175 XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" );
176 e.writeAttribute( "successes", sectionStats.assertions.passed );
177 e.writeAttribute( "failures", sectionStats.assertions.failed );
178 e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk );
179
180 if ( m_config->showDurations() == ShowDurations::Always )
181 e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds );
182
183 m_xml.endElement();
184 }
185 }
ScopedElement & writeAttribute(std::string const &name, T const &attribute)
void sectionEnded(SectionStats const &) override
Here is the call graph for this function:

◆ sectionStarting()

void Catch::XmlReporter::sectionStarting ( SectionInfo const & sectionInfo)
overridevirtual

Reimplemented from Catch::StreamingReporterBase< XmlReporter >.

Definition at line 85 of file catch_reporter_xml.cpp.

85 {
87 if( m_sectionDepth++ > 0 ) {
88 m_xml.startElement( "Section" )
89 .writeAttribute( "name", trim( sectionInfo.name ) );
90 writeSourceInfo( sectionInfo.lineInfo );
91 m_xml.ensureTagClosed();
92 }
93 }
std::string trim(std::string const &str)
void sectionStarting(SectionInfo const &_sectionInfo) override
Here is the call graph for this function:

◆ testCaseEnded()

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

Reimplemented from Catch::StreamingReporterBase< XmlReporter >.

Definition at line 187 of file catch_reporter_xml.cpp.

187 {
189 XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" );
190 e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() );
191
192 if ( m_config->showDurations() == ShowDurations::Always )
193 e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() );
194
195 if( !testCaseStats.stdOut.empty() )
196 m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), false );
197 if( !testCaseStats.stdErr.empty() )
198 m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), false );
199
200 m_xml.endElement();
201 }
auto getElapsedSeconds() const -> double
void testCaseEnded(TestCaseStats const &) override
Here is the call graph for this function:

◆ testCaseStarting()

void Catch::XmlReporter::testCaseStarting ( TestCaseInfo const & testInfo)
overridevirtual

Reimplemented from Catch::StreamingReporterBase< XmlReporter >.

Definition at line 71 of file catch_reporter_xml.cpp.

71 {
73 m_xml.startElement( "TestCase" )
74 .writeAttribute( "name", trim( testInfo.name ) )
75 .writeAttribute( "description", testInfo.description )
76 .writeAttribute( "tags", testInfo.tagsAsString() );
77
78 writeSourceInfo( testInfo.lineInfo );
79
80 if ( m_config->showDurations() == ShowDurations::Always )
81 m_testCaseTimer.start();
82 m_xml.ensureTagClosed();
83 }
void testCaseStarting(TestCaseInfo const &_testInfo) override
Here is the call graph for this function:

◆ testGroupEnded()

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

Reimplemented from Catch::StreamingReporterBase< XmlReporter >.

Definition at line 203 of file catch_reporter_xml.cpp.

203 {
205 // TODO: Check testGroupStats.aborting and act accordingly.
206 m_xml.scopedElement( "OverallResults" )
207 .writeAttribute( "successes", testGroupStats.totals.assertions.passed )
208 .writeAttribute( "failures", testGroupStats.totals.assertions.failed )
209 .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk );
210 m_xml.endElement();
211 }
void testGroupEnded(TestGroupStats const &) override
Here is the call graph for this function:

◆ testGroupStarting()

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

Reimplemented from Catch::StreamingReporterBase< XmlReporter >.

Definition at line 65 of file catch_reporter_xml.cpp.

65 {
67 m_xml.startElement( "Group" )
68 .writeAttribute( "name", groupInfo.name );
69 }
void testGroupStarting(GroupInfo const &_groupInfo) override
Here is the call graph for this function:

◆ testRunEnded()

void Catch::XmlReporter::testRunEnded ( TestRunStats const & testRunStats)
overridevirtual

Reimplemented from Catch::StreamingReporterBase< XmlReporter >.

Definition at line 213 of file catch_reporter_xml.cpp.

213 {
215 m_xml.scopedElement( "OverallResults" )
216 .writeAttribute( "successes", testRunStats.totals.assertions.passed )
217 .writeAttribute( "failures", testRunStats.totals.assertions.failed )
218 .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk );
219 m_xml.endElement();
220 }
void testRunEnded(TestRunStats const &) override
Here is the call graph for this function:

◆ testRunStarting()

void Catch::XmlReporter::testRunStarting ( TestRunInfo const & testInfo)
overridevirtual

Reimplemented from Catch::StreamingReporterBase< XmlReporter >.

Definition at line 50 of file catch_reporter_xml.cpp.

50 {
52 std::string stylesheetRef = getStylesheetRef();
53 if( !stylesheetRef.empty() )
54 m_xml.writeStylesheetRef( stylesheetRef );
55 m_xml.startElement( "Catch" );
56 if( !m_config->name().empty() )
57 m_xml.writeAttribute( "name", m_config->name() );
58 if (m_config->testSpec().hasFilters())
59 m_xml.writeAttribute( "filters", serializeFilters( m_config->getTestsOrTags() ) );
60 if( m_config->rngSeed() != 0 )
61 m_xml.scopedElement( "Randomness" )
62 .writeAttribute( "seed", m_config->rngSeed() );
63 }
virtual std::string getStylesheetRef() const
void writeStylesheetRef(std::string const &url)
std::string serializeFilters(std::vector< std::string > const &container)
void testRunStarting(TestRunInfo const &_testRunInfo) override
Here is the call graph for this function:

◆ writeSourceInfo()

void Catch::XmlReporter::writeSourceInfo ( SourceLineInfo const & sourceInfo)

Definition at line 40 of file catch_reporter_xml.cpp.

40 {
41 m_xml
42 .writeAttribute( "filename", sourceInfo.file )
43 .writeAttribute( "line", sourceInfo.line );
44 }
Here is the call graph for this function:
Here is the caller graph for this function:

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