Shifted some of MockReporter into the impl file file

This commit is contained in:
Phil Nash 2012-05-07 18:59:33 +01:00
parent 49e6d536e1
commit e848a91704
2 changed files with 105 additions and 156 deletions

View File

@ -37,7 +37,89 @@ namespace Catch{
m_output = oss.str(); m_output = oss.str();
return result; return result;
} }
void MockReporter::Result
(
const ResultInfo& resultInfo
)
{
if( resultInfo.getResultType() == ResultWas::Ok )
return;
switch( resultInfo.getResultType() )
{
case ResultWas::Info:
m_log << "Info";
break;
case ResultWas::Warning:
m_log << "Warning";
break;
case ResultWas::ExplicitFailure:
m_log << "ExplicitFailure";
break;
case ResultWas::ExpressionFailed:
m_log << "ExpressionFailed";
break;
case ResultWas::Unknown:
m_log << "Unknown";
break;
case ResultWas::ThrewException:
m_log << "ThrewException";
break;
case ResultWas::DidntThrowException:
m_log << "DidntThrowException";
break;
// We shouldn't ever see these
case ResultWas::Ok:
m_log << "Ok";
break;
case ResultWas::FailureBit:
m_log << "FailureBit";
break;
case ResultWas::Exception:
m_log << "Exception";
break;
default:
m_log << "{unrecognised ResultType enum value}";
break;
}
if( resultInfo.hasExpression() )
m_log << resultInfo.getExpression();
if( resultInfo.hasMessage() )
m_log << "'" << resultInfo.getMessage() << "'";
if( resultInfo.hasExpandedExpression() )
m_log << resultInfo.getExpandedExpression();
}
void MockReporter::openLabel( const std::string& label, const std::string& arg )
{
if( shouldRecord( label ) )
{
m_log << m_indent << "\\" << label;
if( !arg.empty() )
m_log << " " << arg;
m_log << "\n";
m_indent += " ";
}
}
void MockReporter::closeLabel( const std::string& label, const std::string& arg )
{
if( shouldRecord( label ) )
{
m_indent = m_indent.substr( 0, m_indent.size()-1 );
m_log << m_indent << "/" << label;
if( !arg.empty() )
m_log << " " << arg;
m_log << "\n";
}
}
const std::string MockReporter::recordGroups = "[g]"; const std::string MockReporter::recordGroups = "[g]";
const std::string MockReporter::recordTestCases = "[tc]"; const std::string MockReporter::recordTestCases = "[tc]";
const std::string MockReporter::recordSections =" [s]"; const std::string MockReporter::recordSections =" [s]";

View File

@ -18,220 +18,87 @@
namespace Catch namespace Catch
{ {
class MockReporter : public SharedImpl<IReporter> class MockReporter : public SharedImpl<IReporter> {
{
public: public:
static const std::string recordGroups; static const std::string recordGroups;
static const std::string recordTestCases; static const std::string recordTestCases;
static const std::string recordSections; static const std::string recordSections;
void recordAll void recordAll() {
()
{
addRecorder( recordGroups ); addRecorder( recordGroups );
addRecorder( recordTestCases ); addRecorder( recordTestCases );
addRecorder( recordSections ); addRecorder( recordSections );
} }
MockReporter MockReporter( const IReporterConfig& config ) {
(
const IReporterConfig& config
)
{
recordAll(); recordAll();
} }
MockReporter MockReporter() {
()
{
recordAll(); recordAll();
} }
void addRecorder void addRecorder( const std::string& recorder ) {
(
const std::string& recorder
)
{
m_recorders.insert( recorder ); m_recorders.insert( recorder );
} }
static std::string getDescription static std::string getDescription() {
()
{
return "mock reporter"; return "mock reporter";
} }
std::string getLog std::string getLog() const {
()
const
{
return m_log.str(); return m_log.str();
} }
private: // IReporter private: // IReporter
virtual bool shouldRedirectStdout virtual bool shouldRedirectStdout() const {
()
const
{
return false; return false;
} }
virtual void StartTesting virtual void StartTesting() {}
()
{
}
virtual void EndTesting virtual void EndTesting( const Totals& totals ) {}
(
const Totals& totals
)
{
}
virtual void StartGroup virtual void StartGroup( const std::string& groupName ) {
(
const std::string& groupName
)
{
openLabel( recordGroups, groupName ); openLabel( recordGroups, groupName );
} }
virtual void EndGroup virtual void EndGroup( const std::string& groupName, const Totals& totals ) {
(
const std::string& groupName,
const Totals& totals
)
{
closeLabel( recordGroups, groupName ); closeLabel( recordGroups, groupName );
} }
virtual void StartSection virtual void StartSection( const std::string& sectionName, const std::string description ) {
(
const std::string& sectionName,
const std::string description
)
{
openLabel( recordSections, sectionName ); openLabel( recordSections, sectionName );
} }
virtual void EndSection virtual void EndSection( const std::string& sectionName, const Counts& assertions ) {
(
const std::string& sectionName,
const Counts& assertions
)
{
closeLabel( recordSections, sectionName ); closeLabel( recordSections, sectionName );
} }
virtual void StartTestCase virtual void StartTestCase( const TestCaseInfo& testInfo ) {
(
const TestCaseInfo& testInfo
)
{
openLabel( recordTestCases, testInfo.getName() ); openLabel( recordTestCases, testInfo.getName() );
} }
virtual void EndTestCase virtual void EndTestCase( const TestCaseInfo& testInfo,
( const Totals& totals,
const TestCaseInfo& testInfo, const std::string& stdOut,
const Totals& totals, const std::string& stdErr ) {
const std::string& stdOut,
const std::string& stdErr
)
{
closeLabel( recordTestCases, testInfo.getName() ); closeLabel( recordTestCases, testInfo.getName() );
} }
virtual void Result virtual void Result( const ResultInfo& resultInfo );
(
const ResultInfo& resultInfo
)
{
if( resultInfo.getResultType() == ResultWas::Ok )
return;
switch( resultInfo.getResultType() )
{
case ResultWas::Info:
m_log << "Info";
break;
case ResultWas::Warning:
m_log << "Warning";
break;
case ResultWas::ExplicitFailure:
m_log << "ExplicitFailure";
break;
case ResultWas::ExpressionFailed:
m_log << "ExpressionFailed";
break;
case ResultWas::Unknown:
m_log << "Unknown";
break;
case ResultWas::ThrewException:
m_log << "ThrewException";
break;
case ResultWas::DidntThrowException:
m_log << "DidntThrowException";
break;
// We shouldn't ever see these
case ResultWas::Ok:
m_log << "Ok";
break;
case ResultWas::FailureBit:
m_log << "FailureBit";
break;
case ResultWas::Exception:
m_log << "Exception";
break;
default:
m_log << "{unrecognised ResultType enum value}";
break;
}
if( resultInfo.hasExpression() )
m_log << resultInfo.getExpression();
if( resultInfo.hasMessage() )
m_log << "'" << resultInfo.getMessage() << "'";
if( resultInfo.hasExpandedExpression() )
m_log << resultInfo.getExpandedExpression();
}
private: private:
bool shouldRecord( const std::string& recorder ) const bool shouldRecord( const std::string& recorder ) const {
{
return m_recorders.find( recorder ) != m_recorders.end(); return m_recorders.find( recorder ) != m_recorders.end();
} }
void openLabel( const std::string& label, const std::string& arg = "" ) void openLabel( const std::string& label, const std::string& arg = "" );
{ void closeLabel( const std::string& label, const std::string& arg = "" );
if( shouldRecord( label ) )
{
m_log << m_indent << "\\" << label;
if( !arg.empty() )
m_log << " " << arg;
m_log << "\n";
m_indent += " ";
}
}
void closeLabel( const std::string& label, const std::string& arg = "" )
{
if( shouldRecord( label ) )
{
m_indent = m_indent.substr( 0, m_indent.size()-1 );
m_log << m_indent << "/" << label;
if( !arg.empty() )
m_log << " " << arg;
m_log << "\n";
}
}
std::string m_indent; std::string m_indent;
std::ostringstream m_log; std::ostringstream m_log;