Made ReportConfig a value type

This commit is contained in:
Phil Nash 2012-07-20 19:07:42 +01:00
parent f606517376
commit d2553cdc64
10 changed files with 156 additions and 134 deletions

View File

@ -31,7 +31,10 @@ namespace Catch {
std::string reporterName = config.data().reporter.empty()
? "basic"
: config.data().reporter;
Ptr<IReporter> reporter = getCurrentContext().getReporterRegistry().create( reporterName, config );
ReporterConfig reporterConfig( config.getName(), config.stream(), config.includeSuccessfulResults() );
Ptr<IReporter> reporter = getCurrentContext().getReporterRegistry().create( reporterName, reporterConfig );
if( !config.data().stream.empty() ) {
if( config.data().stream[0] == '%' )

View File

@ -60,7 +60,7 @@ namespace Catch {
};
class Config : public IReporterConfig, public IConfig {
class Config : public IConfig {
private:
Config( const Config& other );
Config& operator = ( const Config& other );

View File

@ -18,11 +18,19 @@
namespace Catch
{
struct IReporterConfig {
virtual ~IReporterConfig() {}
virtual std::ostream& stream () const = 0;
virtual bool includeSuccessfulResults () const = 0;
virtual std::string getName () const = 0;
struct ReporterConfig
{
ReporterConfig( const std::string& _name,
std::ostream& _stream,
bool _includeSuccessfulResults = false )
: name( _name ),
stream( _stream ),
includeSuccessfulResults( _includeSuccessfulResults )
{}
std::string name;
std::ostream& stream;
bool includeSuccessfulResults;
};
class TestCaseInfo;
@ -45,7 +53,7 @@ namespace Catch
struct IReporterFactory {
virtual ~IReporterFactory() {}
virtual IReporter* create( const IReporterConfig& config ) const = 0;
virtual IReporter* create( const ReporterConfig& config ) const = 0;
virtual std::string getDescription() const = 0;
};
@ -53,7 +61,7 @@ namespace Catch
typedef std::map<std::string, IReporterFactory*> FactoryMap;
virtual ~IReporterRegistry() {}
virtual IReporter* create( const std::string& name, const IReporterConfig& config ) const = 0;
virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const = 0;
virtual void registerReporter( const std::string& name, IReporterFactory* factory ) = 0;
virtual const FactoryMap& getFactories() const = 0;
};

View File

@ -17,7 +17,7 @@ namespace Catch {
class ReporterFactory : public IReporterFactory {
virtual IReporter* create( const IReporterConfig& config ) const {
virtual IReporter* create( const ReporterConfig& config ) const {
return new T( config );
}

View File

@ -22,7 +22,7 @@ namespace Catch {
deleteAllValues( m_factories );
}
virtual IReporter* create( const std::string& name, const IReporterConfig& config ) const {
virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const {
FactoryMap::const_iterator it = m_factories.find( name );
if( it == m_factories.end() )
return NULL;

View File

@ -55,7 +55,7 @@ namespace Catch {
};
public:
BasicReporter( const IReporterConfig& config )
BasicReporter( const ReporterConfig& config )
: m_config( config ),
m_firstSectionInTestCase( true ),
m_aborted( false )
@ -69,27 +69,27 @@ namespace Catch {
void ReportCounts( const std::string& label, const Counts& counts, const std::string& allPrefix = "All " ) {
if( counts.passed )
m_config.stream() << counts.failed << " of " << counts.total() << " " << label << "s failed";
m_config.stream << counts.failed << " of " << counts.total() << " " << label << "s failed";
else
m_config.stream() << ( counts.failed > 1 ? allPrefix : "" ) << pluralise( counts.failed, label ) << " failed";
m_config.stream << ( counts.failed > 1 ? allPrefix : "" ) << pluralise( counts.failed, label ) << " failed";
}
void ReportCounts( const Totals& totals, const std::string& allPrefix = "All " ) {
if( totals.assertions.total() == 0 ) {
m_config.stream() << "No tests ran";
m_config.stream << "No tests ran";
}
else if( totals.assertions.failed ) {
TextColour colour( TextColour::ResultError );
ReportCounts( "test case", totals.testCases, allPrefix );
if( totals.testCases.failed > 0 ) {
m_config.stream() << " (";
m_config.stream << " (";
ReportCounts( "assertion", totals.assertions, allPrefix );
m_config.stream() << ")";
m_config.stream << ")";
}
}
else {
TextColour colour( TextColour::ResultSuccess );
m_config.stream() << allPrefix << "tests passed ("
m_config.stream << allPrefix << "tests passed ("
<< pluralise( totals.assertions.passed, "assertion" ) << " in "
<< pluralise( totals.testCases.passed, "test case" ) << ")";
}
@ -112,14 +112,14 @@ namespace Catch {
virtual void EndTesting( const Totals& totals ) {
// Output the overall test results even if "Started Testing" was not emitted
if( m_aborted ) {
m_config.stream() << "\n[Testing aborted. ";
m_config.stream << "\n[Testing aborted. ";
ReportCounts( totals, "The first " );
}
else {
m_config.stream() << "\n[Testing completed. ";
m_config.stream << "\n[Testing completed. ";
ReportCounts( totals );
}
m_config.stream() << "]\n" << std::endl;
m_config.stream << "]\n" << std::endl;
}
virtual void StartGroup( const std::string& groupName ) {
@ -128,9 +128,9 @@ namespace Catch {
virtual void EndGroup( const std::string& groupName, const Totals& totals ) {
if( m_groupSpan.emitted && !groupName.empty() ) {
m_config.stream() << "[End of group: '" << groupName << "'. ";
m_config.stream << "[End of group: '" << groupName << "'. ";
ReportCounts( totals );
m_config.stream() << "]\n" << std::endl;
m_config.stream << "]\n" << std::endl;
m_groupSpan = SpanInfo();
}
}
@ -146,7 +146,7 @@ namespace Catch {
virtual void EndSection( const std::string& sectionName, const Counts& assertions ) {
SpanInfo& sectionSpan = m_sectionSpans.back();
if( sectionSpan.emitted && !sectionSpan.name.empty() ) {
m_config.stream() << "[End of section: '" << sectionName << "' ";
m_config.stream << "[End of section: '" << sectionName << "' ";
if( assertions.failed ) {
TextColour colour( TextColour::ResultError );
@ -154,35 +154,35 @@ namespace Catch {
}
else {
TextColour colour( TextColour::ResultSuccess );
m_config.stream() << ( assertions.passed > 1 ? "All " : "" )
m_config.stream << ( assertions.passed > 1 ? "All " : "" )
<< pluralise( assertions.passed, "assertion" ) << " passed" ;
}
m_config.stream() << "]\n" << std::endl;
m_config.stream << "]\n" << std::endl;
}
m_sectionSpans.pop_back();
}
virtual void Result( const ResultInfo& resultInfo ) {
if( !m_config.includeSuccessfulResults() && resultInfo.getResultType() == ResultWas::Ok )
if( !m_config.includeSuccessfulResults && resultInfo.getResultType() == ResultWas::Ok )
return;
StartSpansLazily();
if( !resultInfo.getFilename().empty() ) {
TextColour colour( TextColour::FileName );
m_config.stream() << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() );
m_config.stream << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() );
}
if( resultInfo.hasExpression() ) {
TextColour colour( TextColour::OriginalExpression );
m_config.stream() << resultInfo.getExpression();
m_config.stream << resultInfo.getExpression();
if( resultInfo.ok() ) {
TextColour successColour( TextColour::Success );
m_config.stream() << " succeeded";
m_config.stream << " succeeded";
}
else {
TextColour errorColour( TextColour::Error );
m_config.stream() << " failed";
m_config.stream << " failed";
}
}
switch( resultInfo.getResultType() ) {
@ -190,31 +190,31 @@ namespace Catch {
{
TextColour colour( TextColour::Error );
if( resultInfo.hasExpression() )
m_config.stream() << " with unexpected";
m_config.stream << " with unexpected";
else
m_config.stream() << "Unexpected";
m_config.stream() << " exception with message: '" << resultInfo.getMessage() << "'";
m_config.stream << "Unexpected";
m_config.stream << " exception with message: '" << resultInfo.getMessage() << "'";
}
break;
case ResultWas::DidntThrowException:
{
TextColour colour( TextColour::Error );
if( resultInfo.hasExpression() )
m_config.stream() << " because no exception was thrown where one was expected";
m_config.stream << " because no exception was thrown where one was expected";
else
m_config.stream() << "No exception thrown where one was expected";
m_config.stream << "No exception thrown where one was expected";
}
break;
case ResultWas::Info:
streamVariableLengthText( "info", resultInfo.getMessage() );
break;
case ResultWas::Warning:
m_config.stream() << "warning:\n'" << resultInfo.getMessage() << "'";
m_config.stream << "warning:\n'" << resultInfo.getMessage() << "'";
break;
case ResultWas::ExplicitFailure:
{
TextColour colour( TextColour::Error );
m_config.stream() << "failed with message: '" << resultInfo.getMessage() << "'";
m_config.stream << "failed with message: '" << resultInfo.getMessage() << "'";
}
break;
case ResultWas::Unknown: // These cases are here to prevent compiler warnings
@ -226,22 +226,22 @@ namespace Catch {
if( !resultInfo.hasExpression() ) {
if( resultInfo.ok() ) {
TextColour colour( TextColour::Success );
m_config.stream() << " succeeded";
m_config.stream << " succeeded";
}
else {
TextColour colour( TextColour::Error );
m_config.stream() << " failed";
m_config.stream << " failed";
}
}
break;
}
if( resultInfo.hasExpandedExpression() ) {
m_config.stream() << " for: ";
m_config.stream << " for: ";
TextColour colour( TextColour::ReconstructedExpression );
m_config.stream() << resultInfo.getExpandedExpression();
m_config.stream << resultInfo.getExpandedExpression();
}
m_config.stream() << std::endl;
m_config.stream << std::endl;
}
virtual void EndTestCase( const TestCaseInfo& testInfo,
@ -259,9 +259,9 @@ namespace Catch {
}
if( m_testSpan.emitted ) {
m_config.stream() << "[Finished: '" << testInfo.getName() << "' ";
m_config.stream << "[Finished: '" << testInfo.getName() << "' ";
ReportCounts( totals );
m_config.stream() << "]" << std::endl;
m_config.stream << "]" << std::endl;
}
}
@ -269,20 +269,20 @@ namespace Catch {
void StartSpansLazily() {
if( !m_testingSpan.emitted ) {
if( m_config.getName().empty() )
m_config.stream() << "[Started testing]" << std::endl;
if( m_config.name.empty() )
m_config.stream << "[Started testing]" << std::endl;
else
m_config.stream() << "[Started testing: " << m_config.getName() << "]" << std::endl;
m_config.stream << "[Started testing: " << m_config.name << "]" << std::endl;
m_testingSpan.emitted = true;
}
if( !m_groupSpan.emitted && !m_groupSpan.name.empty() ) {
m_config.stream() << "[Started group: '" << m_groupSpan.name << "']" << std::endl;
m_config.stream << "[Started group: '" << m_groupSpan.name << "']" << std::endl;
m_groupSpan.emitted = true;
}
if( !m_testSpan.emitted ) {
m_config.stream() << std::endl << "[Running: " << m_testSpan.name << "]" << std::endl;
m_config.stream << std::endl << "[Running: " << m_testSpan.name << "]" << std::endl;
m_testSpan.emitted = true;
}
@ -290,7 +290,7 @@ namespace Catch {
SpanInfo& sectionSpan = m_sectionSpans.back();
if( !sectionSpan.emitted && !sectionSpan.name.empty() ) {
if( m_firstSectionInTestCase ) {
m_config.stream() << "\n";
m_config.stream << "\n";
m_firstSectionInTestCase = false;
}
std::vector<SpanInfo>::iterator it = m_sectionSpans.begin();
@ -298,7 +298,7 @@ namespace Catch {
for(; it != itEnd; ++it ) {
SpanInfo& prevSpan = *it;
if( !prevSpan.emitted && !prevSpan.name.empty() ) {
m_config.stream() << "[Started section: '" << prevSpan.name << "']" << std::endl;
m_config.stream << "[Started section: '" << prevSpan.name << "']" << std::endl;
prevSpan.emitted = true;
}
}
@ -309,16 +309,16 @@ namespace Catch {
void streamVariableLengthText( const std::string& prefix, const std::string& text ) {
std::string trimmed = trim( text );
if( trimmed.find_first_of( "\r\n" ) == std::string::npos ) {
m_config.stream() << "[" << prefix << ": " << trimmed << "]\n";
m_config.stream << "[" << prefix << ": " << trimmed << "]\n";
}
else {
m_config.stream() << "\n[" << prefix << "] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" << trimmed
m_config.stream << "\n[" << prefix << "] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" << trimmed
<< "\n[end of " << prefix << "] <<<<<<<<<<<<<<<<<<<<<<<<\n";
}
}
private:
const IReporterConfig& m_config;
ReporterConfig m_config;
bool m_firstSectionInTestCase;
SpanInfo m_testingSpan;

View File

@ -57,7 +57,7 @@ namespace Catch {
};
public:
JunitReporter( const IReporterConfig& config )
JunitReporter( const ReporterConfig& config )
: m_config( config ),
m_testSuiteStats( "AllTests" ),
m_currentStats( &m_testSuiteStats )
@ -94,7 +94,7 @@ namespace Catch {
}
virtual void Result( const Catch::ResultInfo& resultInfo ) {
if( resultInfo.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults() ) {
if( resultInfo.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults ) {
TestCaseStats& testCaseStats = m_currentStats->m_testCaseStats.back();
TestStats stats;
std::ostringstream oss;
@ -151,7 +151,7 @@ namespace Catch {
}
virtual void EndTesting( const Totals& ) {
std::ostream& str = m_config.stream();
std::ostream& str = m_config.stream;
{
XmlWriter xml( str );
@ -212,7 +212,7 @@ namespace Catch {
}
private:
const IReporterConfig& m_config;
ReporterConfig m_config;
bool m_currentTestSuccess;
Stats m_testSuiteStats;

View File

@ -16,7 +16,7 @@
namespace Catch {
class XmlReporter : public SharedImpl<IReporter> {
public:
XmlReporter( const IReporterConfig& config ) : m_config( config ) {}
XmlReporter( const ReporterConfig& config ) : m_config( config ) {}
static std::string getDescription() {
return "Reports test results as an XML document";
@ -29,10 +29,10 @@ namespace Catch {
}
virtual void StartTesting() {
m_xml = XmlWriter( m_config.stream() );
m_xml = XmlWriter( m_config.stream );
m_xml.startElement( "Catch" );
if( !m_config.getName().empty() )
m_xml.writeAttribute( "name", m_config.getName() );
if( !m_config.name.empty() )
m_xml.writeAttribute( "name", m_config.name );
}
virtual void EndTesting( const Totals& totals ) {
@ -73,7 +73,7 @@ namespace Catch {
}
virtual void Result( const Catch::ResultInfo& resultInfo ) {
if( !m_config.includeSuccessfulResults() && resultInfo.getResultType() == ResultWas::Ok )
if( !m_config.includeSuccessfulResults && resultInfo.getResultType() == ResultWas::Ok )
return;
if( resultInfo.hasExpression() ) {
@ -133,7 +133,7 @@ namespace Catch {
}
private:
const IReporterConfig& m_config;
ReporterConfig m_config;
bool m_currentTestSuccess;
XmlWriter m_xml;
};

View File

@ -27,7 +27,7 @@ namespace Catch {
addRecorder( recordSections );
}
MockReporter( const IReporterConfig& ) {
MockReporter( const ReporterConfig& ) {
recordAll();
}

View File

@ -1,5 +1,5 @@
/*
* Generated: 2012-07-20 18:46:50.092936
* Generated: 2012-07-20 19:07:25.539622
* ----------------------------------------------------------
* This file has been merged from multiple headers. Please don't edit it directly
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
@ -274,11 +274,19 @@ namespace Catch {
namespace Catch
{
struct IReporterConfig {
virtual ~IReporterConfig() {}
virtual std::ostream& stream () const = 0;
virtual bool includeSuccessfulResults () const = 0;
virtual std::string getName () const = 0;
struct ReporterConfig
{
ReporterConfig( const std::string& _name,
std::ostream& _stream,
bool _includeSuccessfulResults = false )
: name( _name ),
stream( _stream ),
includeSuccessfulResults( _includeSuccessfulResults )
{}
std::string name;
std::ostream& stream;
bool includeSuccessfulResults;
};
class TestCaseInfo;
@ -301,7 +309,7 @@ namespace Catch
struct IReporterFactory {
virtual ~IReporterFactory() {}
virtual IReporter* create( const IReporterConfig& config ) const = 0;
virtual IReporter* create( const ReporterConfig& config ) const = 0;
virtual std::string getDescription() const = 0;
};
@ -309,7 +317,7 @@ namespace Catch
typedef std::map<std::string, IReporterFactory*> FactoryMap;
virtual ~IReporterRegistry() {}
virtual IReporter* create( const std::string& name, const IReporterConfig& config ) const = 0;
virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const = 0;
virtual void registerReporter( const std::string& name, IReporterFactory* factory ) = 0;
virtual const FactoryMap& getFactories() const = 0;
};
@ -2478,7 +2486,7 @@ namespace Catch {
bool allowThrows;
};
class Config : public IReporterConfig, public IConfig {
class Config : public IConfig {
private:
Config( const Config& other );
Config& operator = ( const Config& other );
@ -3316,7 +3324,7 @@ namespace Catch {
deleteAllValues( m_factories );
}
virtual IReporter* create( const std::string& name, const IReporterConfig& config ) const {
virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const {
FactoryMap::const_iterator it = m_factories.find( name );
if( it == m_factories.end() )
return NULL;
@ -3707,7 +3715,7 @@ namespace Catch {
class ReporterFactory : public IReporterFactory {
virtual IReporter* create( const IReporterConfig& config ) const {
virtual IReporter* create( const ReporterConfig& config ) const {
return new T( config );
}
@ -3769,7 +3777,7 @@ namespace Catch {
};
public:
BasicReporter( const IReporterConfig& config )
BasicReporter( const ReporterConfig& config )
: m_config( config ),
m_firstSectionInTestCase( true ),
m_aborted( false )
@ -3783,27 +3791,27 @@ namespace Catch {
void ReportCounts( const std::string& label, const Counts& counts, const std::string& allPrefix = "All " ) {
if( counts.passed )
m_config.stream() << counts.failed << " of " << counts.total() << " " << label << "s failed";
m_config.stream << counts.failed << " of " << counts.total() << " " << label << "s failed";
else
m_config.stream() << ( counts.failed > 1 ? allPrefix : "" ) << pluralise( counts.failed, label ) << " failed";
m_config.stream << ( counts.failed > 1 ? allPrefix : "" ) << pluralise( counts.failed, label ) << " failed";
}
void ReportCounts( const Totals& totals, const std::string& allPrefix = "All " ) {
if( totals.assertions.total() == 0 ) {
m_config.stream() << "No tests ran";
m_config.stream << "No tests ran";
}
else if( totals.assertions.failed ) {
TextColour colour( TextColour::ResultError );
ReportCounts( "test case", totals.testCases, allPrefix );
if( totals.testCases.failed > 0 ) {
m_config.stream() << " (";
m_config.stream << " (";
ReportCounts( "assertion", totals.assertions, allPrefix );
m_config.stream() << ")";
m_config.stream << ")";
}
}
else {
TextColour colour( TextColour::ResultSuccess );
m_config.stream() << allPrefix << "tests passed ("
m_config.stream << allPrefix << "tests passed ("
<< pluralise( totals.assertions.passed, "assertion" ) << " in "
<< pluralise( totals.testCases.passed, "test case" ) << ")";
}
@ -3826,14 +3834,14 @@ namespace Catch {
virtual void EndTesting( const Totals& totals ) {
// Output the overall test results even if "Started Testing" was not emitted
if( m_aborted ) {
m_config.stream() << "\n[Testing aborted. ";
m_config.stream << "\n[Testing aborted. ";
ReportCounts( totals, "The first " );
}
else {
m_config.stream() << "\n[Testing completed. ";
m_config.stream << "\n[Testing completed. ";
ReportCounts( totals );
}
m_config.stream() << "]\n" << std::endl;
m_config.stream << "]\n" << std::endl;
}
virtual void StartGroup( const std::string& groupName ) {
@ -3842,9 +3850,9 @@ namespace Catch {
virtual void EndGroup( const std::string& groupName, const Totals& totals ) {
if( m_groupSpan.emitted && !groupName.empty() ) {
m_config.stream() << "[End of group: '" << groupName << "'. ";
m_config.stream << "[End of group: '" << groupName << "'. ";
ReportCounts( totals );
m_config.stream() << "]\n" << std::endl;
m_config.stream << "]\n" << std::endl;
m_groupSpan = SpanInfo();
}
}
@ -3860,7 +3868,7 @@ namespace Catch {
virtual void EndSection( const std::string& sectionName, const Counts& assertions ) {
SpanInfo& sectionSpan = m_sectionSpans.back();
if( sectionSpan.emitted && !sectionSpan.name.empty() ) {
m_config.stream() << "[End of section: '" << sectionName << "' ";
m_config.stream << "[End of section: '" << sectionName << "' ";
if( assertions.failed ) {
TextColour colour( TextColour::ResultError );
@ -3868,35 +3876,35 @@ namespace Catch {
}
else {
TextColour colour( TextColour::ResultSuccess );
m_config.stream() << ( assertions.passed > 1 ? "All " : "" )
m_config.stream << ( assertions.passed > 1 ? "All " : "" )
<< pluralise( assertions.passed, "assertion" ) << " passed" ;
}
m_config.stream() << "]\n" << std::endl;
m_config.stream << "]\n" << std::endl;
}
m_sectionSpans.pop_back();
}
virtual void Result( const ResultInfo& resultInfo ) {
if( !m_config.includeSuccessfulResults() && resultInfo.getResultType() == ResultWas::Ok )
if( !m_config.includeSuccessfulResults && resultInfo.getResultType() == ResultWas::Ok )
return;
StartSpansLazily();
if( !resultInfo.getFilename().empty() ) {
TextColour colour( TextColour::FileName );
m_config.stream() << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() );
m_config.stream << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() );
}
if( resultInfo.hasExpression() ) {
TextColour colour( TextColour::OriginalExpression );
m_config.stream() << resultInfo.getExpression();
m_config.stream << resultInfo.getExpression();
if( resultInfo.ok() ) {
TextColour successColour( TextColour::Success );
m_config.stream() << " succeeded";
m_config.stream << " succeeded";
}
else {
TextColour errorColour( TextColour::Error );
m_config.stream() << " failed";
m_config.stream << " failed";
}
}
switch( resultInfo.getResultType() ) {
@ -3904,31 +3912,31 @@ namespace Catch {
{
TextColour colour( TextColour::Error );
if( resultInfo.hasExpression() )
m_config.stream() << " with unexpected";
m_config.stream << " with unexpected";
else
m_config.stream() << "Unexpected";
m_config.stream() << " exception with message: '" << resultInfo.getMessage() << "'";
m_config.stream << "Unexpected";
m_config.stream << " exception with message: '" << resultInfo.getMessage() << "'";
}
break;
case ResultWas::DidntThrowException:
{
TextColour colour( TextColour::Error );
if( resultInfo.hasExpression() )
m_config.stream() << " because no exception was thrown where one was expected";
m_config.stream << " because no exception was thrown where one was expected";
else
m_config.stream() << "No exception thrown where one was expected";
m_config.stream << "No exception thrown where one was expected";
}
break;
case ResultWas::Info:
streamVariableLengthText( "info", resultInfo.getMessage() );
break;
case ResultWas::Warning:
m_config.stream() << "warning:\n'" << resultInfo.getMessage() << "'";
m_config.stream << "warning:\n'" << resultInfo.getMessage() << "'";
break;
case ResultWas::ExplicitFailure:
{
TextColour colour( TextColour::Error );
m_config.stream() << "failed with message: '" << resultInfo.getMessage() << "'";
m_config.stream << "failed with message: '" << resultInfo.getMessage() << "'";
}
break;
case ResultWas::Unknown: // These cases are here to prevent compiler warnings
@ -3940,22 +3948,22 @@ namespace Catch {
if( !resultInfo.hasExpression() ) {
if( resultInfo.ok() ) {
TextColour colour( TextColour::Success );
m_config.stream() << " succeeded";
m_config.stream << " succeeded";
}
else {
TextColour colour( TextColour::Error );
m_config.stream() << " failed";
m_config.stream << " failed";
}
}
break;
}
if( resultInfo.hasExpandedExpression() ) {
m_config.stream() << " for: ";
m_config.stream << " for: ";
TextColour colour( TextColour::ReconstructedExpression );
m_config.stream() << resultInfo.getExpandedExpression();
m_config.stream << resultInfo.getExpandedExpression();
}
m_config.stream() << std::endl;
m_config.stream << std::endl;
}
virtual void EndTestCase( const TestCaseInfo& testInfo,
@ -3973,9 +3981,9 @@ namespace Catch {
}
if( m_testSpan.emitted ) {
m_config.stream() << "[Finished: '" << testInfo.getName() << "' ";
m_config.stream << "[Finished: '" << testInfo.getName() << "' ";
ReportCounts( totals );
m_config.stream() << "]" << std::endl;
m_config.stream << "]" << std::endl;
}
}
@ -3983,20 +3991,20 @@ namespace Catch {
void StartSpansLazily() {
if( !m_testingSpan.emitted ) {
if( m_config.getName().empty() )
m_config.stream() << "[Started testing]" << std::endl;
if( m_config.name.empty() )
m_config.stream << "[Started testing]" << std::endl;
else
m_config.stream() << "[Started testing: " << m_config.getName() << "]" << std::endl;
m_config.stream << "[Started testing: " << m_config.name << "]" << std::endl;
m_testingSpan.emitted = true;
}
if( !m_groupSpan.emitted && !m_groupSpan.name.empty() ) {
m_config.stream() << "[Started group: '" << m_groupSpan.name << "']" << std::endl;
m_config.stream << "[Started group: '" << m_groupSpan.name << "']" << std::endl;
m_groupSpan.emitted = true;
}
if( !m_testSpan.emitted ) {
m_config.stream() << std::endl << "[Running: " << m_testSpan.name << "]" << std::endl;
m_config.stream << std::endl << "[Running: " << m_testSpan.name << "]" << std::endl;
m_testSpan.emitted = true;
}
@ -4004,7 +4012,7 @@ namespace Catch {
SpanInfo& sectionSpan = m_sectionSpans.back();
if( !sectionSpan.emitted && !sectionSpan.name.empty() ) {
if( m_firstSectionInTestCase ) {
m_config.stream() << "\n";
m_config.stream << "\n";
m_firstSectionInTestCase = false;
}
std::vector<SpanInfo>::iterator it = m_sectionSpans.begin();
@ -4012,7 +4020,7 @@ namespace Catch {
for(; it != itEnd; ++it ) {
SpanInfo& prevSpan = *it;
if( !prevSpan.emitted && !prevSpan.name.empty() ) {
m_config.stream() << "[Started section: '" << prevSpan.name << "']" << std::endl;
m_config.stream << "[Started section: '" << prevSpan.name << "']" << std::endl;
prevSpan.emitted = true;
}
}
@ -4023,16 +4031,16 @@ namespace Catch {
void streamVariableLengthText( const std::string& prefix, const std::string& text ) {
std::string trimmed = trim( text );
if( trimmed.find_first_of( "\r\n" ) == std::string::npos ) {
m_config.stream() << "[" << prefix << ": " << trimmed << "]\n";
m_config.stream << "[" << prefix << ": " << trimmed << "]\n";
}
else {
m_config.stream() << "\n[" << prefix << "] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" << trimmed
m_config.stream << "\n[" << prefix << "] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" << trimmed
<< "\n[end of " << prefix << "] <<<<<<<<<<<<<<<<<<<<<<<<\n";
}
}
private:
const IReporterConfig& m_config;
ReporterConfig m_config;
bool m_firstSectionInTestCase;
SpanInfo m_testingSpan;
@ -4250,7 +4258,7 @@ namespace Catch {
namespace Catch {
class XmlReporter : public SharedImpl<IReporter> {
public:
XmlReporter( const IReporterConfig& config ) : m_config( config ) {}
XmlReporter( const ReporterConfig& config ) : m_config( config ) {}
static std::string getDescription() {
return "Reports test results as an XML document";
@ -4263,10 +4271,10 @@ namespace Catch {
}
virtual void StartTesting() {
m_xml = XmlWriter( m_config.stream() );
m_xml = XmlWriter( m_config.stream );
m_xml.startElement( "Catch" );
if( !m_config.getName().empty() )
m_xml.writeAttribute( "name", m_config.getName() );
if( !m_config.name.empty() )
m_xml.writeAttribute( "name", m_config.name );
}
virtual void EndTesting( const Totals& totals ) {
@ -4307,7 +4315,7 @@ namespace Catch {
}
virtual void Result( const Catch::ResultInfo& resultInfo ) {
if( !m_config.includeSuccessfulResults() && resultInfo.getResultType() == ResultWas::Ok )
if( !m_config.includeSuccessfulResults && resultInfo.getResultType() == ResultWas::Ok )
return;
if( resultInfo.hasExpression() ) {
@ -4367,7 +4375,7 @@ namespace Catch {
}
private:
const IReporterConfig& m_config;
ReporterConfig m_config;
bool m_currentTestSuccess;
XmlWriter m_xml;
};
@ -4420,7 +4428,7 @@ namespace Catch {
};
public:
JunitReporter( const IReporterConfig& config )
JunitReporter( const ReporterConfig& config )
: m_config( config ),
m_testSuiteStats( "AllTests" ),
m_currentStats( &m_testSuiteStats )
@ -4457,7 +4465,7 @@ namespace Catch {
}
virtual void Result( const Catch::ResultInfo& resultInfo ) {
if( resultInfo.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults() ) {
if( resultInfo.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults ) {
TestCaseStats& testCaseStats = m_currentStats->m_testCaseStats.back();
TestStats stats;
std::ostringstream oss;
@ -4514,7 +4522,7 @@ namespace Catch {
}
virtual void EndTesting( const Totals& ) {
std::ostream& str = m_config.stream();
std::ostream& str = m_config.stream;
{
XmlWriter xml( str );
@ -4574,7 +4582,7 @@ namespace Catch {
}
private:
const IReporterConfig& m_config;
ReporterConfig m_config;
bool m_currentTestSuccess;
Stats m_testSuiteStats;
@ -4601,7 +4609,10 @@ namespace Catch {
std::string reporterName = config.data().reporter.empty()
? "basic"
: config.data().reporter;
Ptr<IReporter> reporter = getCurrentContext().getReporterRegistry().create( reporterName, config );
ReporterConfig reporterConfig( config.getName(), config.stream(), config.includeSuccessfulResults() );
Ptr<IReporter> reporter = getCurrentContext().getReporterRegistry().create( reporterName, reporterConfig );
if( !config.data().stream.empty() ) {
if( config.data().stream[0] == '%' )