Provide XmlReporter declaration with EXTERNAL_INTERFACES

Related to #991
This commit is contained in:
Martin Hořeňovský 2017-11-14 17:56:27 +01:00
parent 4b3730de8a
commit a096e4b3f2
4 changed files with 223 additions and 173 deletions

View File

@ -252,6 +252,7 @@ set(REPORTER_HEADERS
${HEADER_DIR}/reporters/catch_reporter_multi.h
${HEADER_DIR}/reporters/catch_reporter_tap.hpp
${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
${HEADER_DIR}/reporters/catch_reporter_xml.h
)
set(REPORTER_SOURCES
${HEADER_DIR}/reporters/catch_reporter_bases.cpp

View File

@ -14,5 +14,6 @@
// Allow users to base their work off existing reporters
#include "../reporters/catch_reporter_compact.h"
#include "../reporters/catch_reporter_junit.h"
#include "../reporters/catch_reporter_xml.h"
#endif // TWOBLUECUBES_CATCH_EXTERNAL_INTERFACES_H_INCLUDED

View File

@ -6,12 +6,10 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#include "catch_reporter_bases.hpp"
#include "catch_reporter_xml.h"
#include "../internal/catch_capture.hpp"
#include "../internal/catch_reporter_registrars.hpp"
#include "internal/catch_xmlwriter.h"
#include "../internal/catch_timer.h"
#if defined(_MSC_VER)
#pragma warning(push)
@ -21,38 +19,34 @@
#endif
namespace Catch {
class XmlReporter : public StreamingReporterBase<XmlReporter> {
public:
XmlReporter( ReporterConfig const& _config )
XmlReporter::XmlReporter( ReporterConfig const& _config )
: StreamingReporterBase( _config ),
m_xml(_config.stream())
{
m_reporterPrefs.shouldRedirectStdOut = true;
}
~XmlReporter() override;
XmlReporter::~XmlReporter() {};
static std::string getDescription() {
std::string XmlReporter::getDescription() {
return "Reports test results as an XML document";
}
virtual std::string getStylesheetRef() const {
std::string XmlReporter::getStylesheetRef() const {
return std::string();
}
void writeSourceInfo( SourceLineInfo const& sourceInfo ) {
void XmlReporter::writeSourceInfo( SourceLineInfo const& sourceInfo ) {
m_xml
.writeAttribute( "filename", sourceInfo.file )
.writeAttribute( "line", sourceInfo.line );
}
public: // StreamingReporterBase
void noMatchingTestCases( std::string const& s ) override {
void XmlReporter::noMatchingTestCases( std::string const& s ) {
StreamingReporterBase::noMatchingTestCases( s );
}
void testRunStarting( TestRunInfo const& testInfo ) override {
void XmlReporter::testRunStarting( TestRunInfo const& testInfo ) {
StreamingReporterBase::testRunStarting( testInfo );
std::string stylesheetRef = getStylesheetRef();
if( !stylesheetRef.empty() )
@ -62,13 +56,13 @@ namespace Catch {
m_xml.writeAttribute( "name", m_config->name() );
}
void testGroupStarting( GroupInfo const& groupInfo ) override {
void XmlReporter::testGroupStarting( GroupInfo const& groupInfo ) {
StreamingReporterBase::testGroupStarting( groupInfo );
m_xml.startElement( "Group" )
.writeAttribute( "name", groupInfo.name );
}
void testCaseStarting( TestCaseInfo const& testInfo ) override {
void XmlReporter::testCaseStarting( TestCaseInfo const& testInfo ) {
StreamingReporterBase::testCaseStarting(testInfo);
m_xml.startElement( "TestCase" )
.writeAttribute( "name", trim( testInfo.name ) )
@ -82,7 +76,7 @@ namespace Catch {
m_xml.ensureTagClosed();
}
void sectionStarting( SectionInfo const& sectionInfo ) override {
void XmlReporter::sectionStarting( SectionInfo const& sectionInfo ) {
StreamingReporterBase::sectionStarting( sectionInfo );
if( m_sectionDepth++ > 0 ) {
m_xml.startElement( "Section" )
@ -93,9 +87,9 @@ namespace Catch {
}
}
void assertionStarting( AssertionInfo const& ) override { }
void XmlReporter::assertionStarting( AssertionInfo const& ) { }
bool assertionEnded( AssertionStats const& assertionStats ) override {
bool XmlReporter::assertionEnded( AssertionStats const& assertionStats ) {
AssertionResult const& result = assertionStats.assertionResult;
@ -170,7 +164,7 @@ namespace Catch {
return true;
}
void sectionEnded( SectionStats const& sectionStats ) override {
void XmlReporter::sectionEnded( SectionStats const& sectionStats ) {
StreamingReporterBase::sectionEnded( sectionStats );
if( --m_sectionDepth > 0 ) {
XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" );
@ -185,7 +179,7 @@ namespace Catch {
}
}
void testCaseEnded( TestCaseStats const& testCaseStats ) override {
void XmlReporter::testCaseEnded( TestCaseStats const& testCaseStats ) {
StreamingReporterBase::testCaseEnded( testCaseStats );
XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" );
e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() );
@ -201,7 +195,7 @@ namespace Catch {
m_xml.endElement();
}
void testGroupEnded( TestGroupStats const& testGroupStats ) override {
void XmlReporter::testGroupEnded( TestGroupStats const& testGroupStats ) {
StreamingReporterBase::testGroupEnded( testGroupStats );
// TODO: Check testGroupStats.aborting and act accordingly.
m_xml.scopedElement( "OverallResults" )
@ -211,7 +205,7 @@ namespace Catch {
m_xml.endElement();
}
void testRunEnded( TestRunStats const& testRunStats ) override {
void XmlReporter::testRunEnded( TestRunStats const& testRunStats ) {
StreamingReporterBase::testRunEnded( testRunStats );
m_xml.scopedElement( "OverallResults" )
.writeAttribute( "successes", testRunStats.totals.assertions.passed )
@ -220,13 +214,6 @@ namespace Catch {
m_xml.endElement();
}
private:
Timer m_testCaseTimer;
XmlWriter m_xml;
int m_sectionDepth = 0;
};
XmlReporter::~XmlReporter() {}
CATCH_REGISTER_REPORTER( "xml", XmlReporter )
} // end namespace Catch

View File

@ -0,0 +1,61 @@
/*
* Created by Martin on 14/11/2017.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_REPORTER_XML_H_INCLUDED
#define TWOBLUECUBES_CATCH_REPORTER_XML_H_INCLUDED
#include "catch_reporter_bases.hpp"
#include "../internal/catch_xmlwriter.h"
#include "../internal/catch_timer.h"
namespace Catch {
class XmlReporter : public StreamingReporterBase<XmlReporter> {
public:
XmlReporter(ReporterConfig const& _config);
~XmlReporter() override;
static std::string getDescription();
virtual std::string getStylesheetRef() const;
void writeSourceInfo(SourceLineInfo const& sourceInfo);
public: // StreamingReporterBase
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;
private:
Timer m_testCaseTimer;
XmlWriter m_xml;
int m_sectionDepth = 0;
};
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_REPORTER_XML_H_INCLUDED