2010-11-10 00:24:00 +01:00
|
|
|
/*
|
|
|
|
* catch_reporter_basic.hpp
|
|
|
|
* Catch
|
|
|
|
*
|
|
|
|
* Created by Phil on 28/10/2010.
|
|
|
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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_BASIC_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_REPORTER_BASIC_HPP_INCLUDED
|
|
|
|
|
|
|
|
#include "internal/catch_capture.hpp"
|
2010-12-31 23:46:51 +01:00
|
|
|
#include "internal/catch_interfaces_reporter.h"
|
|
|
|
#include "internal/catch_reporter_registrars.hpp"
|
2010-11-10 00:24:00 +01:00
|
|
|
|
|
|
|
namespace Catch
|
|
|
|
{
|
2010-12-31 23:07:47 +01:00
|
|
|
class BasicReporter : public IReporter
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2011-02-09 20:26:59 +01:00
|
|
|
struct SpanInfo
|
|
|
|
{
|
|
|
|
SpanInfo()
|
|
|
|
: emitted( false )
|
|
|
|
{}
|
|
|
|
|
|
|
|
SpanInfo( const std::string& spanName )
|
|
|
|
: name( spanName ),
|
|
|
|
emitted( false )
|
|
|
|
{}
|
|
|
|
|
|
|
|
SpanInfo( const SpanInfo& other )
|
|
|
|
: name( other.name ),
|
|
|
|
emitted( other.emitted )
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::string name;
|
|
|
|
bool emitted;
|
|
|
|
};
|
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
public:
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:30:17 +01:00
|
|
|
BasicReporter
|
|
|
|
(
|
|
|
|
const IReporterConfig& config
|
|
|
|
)
|
2010-11-10 00:24:00 +01:00
|
|
|
: m_config( config )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:30:17 +01:00
|
|
|
static std::string getDescription
|
|
|
|
()
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
|
|
|
return "Reports test results as lines of text";
|
|
|
|
}
|
|
|
|
|
2010-11-29 20:40:44 +01:00
|
|
|
private:
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:30:17 +01:00
|
|
|
void ReportCounts
|
|
|
|
(
|
|
|
|
std::size_t succeeded,
|
|
|
|
std::size_t failed
|
|
|
|
)
|
2010-11-29 20:40:44 +01:00
|
|
|
{
|
|
|
|
if( failed + succeeded == 0 )
|
|
|
|
m_config.stream() << "No tests ran";
|
|
|
|
else if( failed == 0 )
|
|
|
|
m_config.stream() << "All " << succeeded << " test(s) succeeded";
|
|
|
|
else if( succeeded == 0 )
|
|
|
|
m_config.stream() << "All " << failed << " test(s) failed";
|
|
|
|
else
|
|
|
|
m_config.stream() << succeeded << " test(s) passed but " << failed << " test(s) failed";
|
|
|
|
}
|
|
|
|
|
2010-12-31 23:07:47 +01:00
|
|
|
private: // IReporter
|
2010-11-29 20:40:44 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:30:17 +01:00
|
|
|
virtual void StartTesting
|
|
|
|
()
|
2010-11-29 20:40:44 +01:00
|
|
|
{
|
2011-02-09 20:26:59 +01:00
|
|
|
m_testingSpan = SpanInfo();
|
2010-11-29 20:40:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:30:17 +01:00
|
|
|
virtual void EndTesting
|
|
|
|
(
|
|
|
|
std::size_t succeeded,
|
|
|
|
std::size_t failed
|
|
|
|
)
|
2010-11-29 20:40:44 +01:00
|
|
|
{
|
2011-02-09 20:26:59 +01:00
|
|
|
if( m_testingSpan.emitted )
|
|
|
|
{
|
|
|
|
m_config.stream() << "[Testing completed. ";
|
|
|
|
ReportCounts( succeeded, failed );
|
|
|
|
m_config.stream() << "]" << std::endl;
|
|
|
|
}
|
2010-11-29 20:40:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:30:17 +01:00
|
|
|
virtual void StartGroup
|
|
|
|
(
|
|
|
|
const std::string& groupName
|
|
|
|
)
|
2010-11-29 20:40:44 +01:00
|
|
|
{
|
2011-02-09 20:26:59 +01:00
|
|
|
m_groupSpan = groupName;
|
2010-11-29 20:40:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:30:17 +01:00
|
|
|
virtual void EndGroup
|
|
|
|
(
|
|
|
|
const std::string& groupName,
|
|
|
|
std::size_t succeeded,
|
|
|
|
std::size_t failed
|
|
|
|
)
|
2010-11-29 20:40:44 +01:00
|
|
|
{
|
2011-02-09 20:26:59 +01:00
|
|
|
if( m_groupSpan.emitted && !groupName.empty() )
|
2010-11-29 20:40:44 +01:00
|
|
|
{
|
|
|
|
m_config.stream() << "[End of group: '" << groupName << "'. ";
|
|
|
|
ReportCounts( succeeded, failed );
|
|
|
|
m_config.stream() << "]\n" << std::endl;
|
2011-02-09 20:26:59 +01:00
|
|
|
m_groupSpan = SpanInfo();
|
2010-11-29 20:40:44 +01:00
|
|
|
}
|
|
|
|
}
|
2010-11-10 00:24:00 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:30:17 +01:00
|
|
|
virtual void StartTestCase
|
|
|
|
(
|
|
|
|
const TestCaseInfo& testInfo
|
|
|
|
)
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2011-02-09 20:26:59 +01:00
|
|
|
m_testSpan = testInfo.getName();
|
2010-11-29 20:40:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:30:17 +01:00
|
|
|
virtual void StartSection
|
|
|
|
(
|
|
|
|
const std::string& sectionName,
|
|
|
|
const std::string /*description*/
|
|
|
|
)
|
2010-11-29 20:40:44 +01:00
|
|
|
{
|
2011-02-28 09:18:52 +01:00
|
|
|
m_sectionSpans.push_back( SpanInfo( sectionName ) );
|
2010-11-29 20:40:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:30:17 +01:00
|
|
|
virtual void EndSection
|
|
|
|
(
|
|
|
|
const std::string& sectionName,
|
|
|
|
std::size_t succeeded,
|
|
|
|
std::size_t failed
|
|
|
|
)
|
2010-11-29 20:40:44 +01:00
|
|
|
{
|
2011-02-28 09:18:52 +01:00
|
|
|
SpanInfo& sectionSpan = m_sectionSpans.back();
|
|
|
|
if( sectionSpan.emitted && !sectionSpan.name.empty() )
|
2011-02-09 20:26:59 +01:00
|
|
|
{
|
|
|
|
m_config.stream() << "[End of section: '" << sectionName << "'. ";
|
|
|
|
ReportCounts( succeeded, failed );
|
|
|
|
m_config.stream() << "]\n" << std::endl;
|
|
|
|
}
|
2011-02-28 09:18:52 +01:00
|
|
|
m_sectionSpans.pop_back();
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:30:17 +01:00
|
|
|
virtual void Result
|
|
|
|
(
|
|
|
|
const ResultInfo& resultInfo
|
|
|
|
)
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2010-12-27 23:05:13 +01:00
|
|
|
if( !m_config.includeSuccessfulResults() && resultInfo.getResultType() == ResultWas::Ok )
|
2010-11-10 00:24:00 +01:00
|
|
|
return;
|
|
|
|
|
2011-02-09 20:26:59 +01:00
|
|
|
StartSpansLazily();
|
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
if( !resultInfo.getFilename().empty() )
|
|
|
|
m_config.stream() << resultInfo.getFilename() << "(" << resultInfo.getLine() << "): ";
|
|
|
|
|
|
|
|
if( resultInfo.hasExpression() )
|
|
|
|
{
|
|
|
|
m_config.stream() << resultInfo.getExpression();
|
|
|
|
if( resultInfo.ok() )
|
|
|
|
m_config.stream() << " succeeded";
|
|
|
|
else
|
|
|
|
m_config.stream() << " failed";
|
|
|
|
}
|
|
|
|
switch( resultInfo.getResultType() )
|
|
|
|
{
|
|
|
|
case ResultWas::ThrewException:
|
|
|
|
if( resultInfo.hasExpression() )
|
|
|
|
m_config.stream() << " with unexpected";
|
|
|
|
else
|
|
|
|
m_config.stream() << "Unexpected";
|
|
|
|
m_config.stream() << " exception with message: '" << resultInfo.getMessage() << "'";
|
|
|
|
break;
|
2011-03-14 20:21:35 +01:00
|
|
|
case ResultWas::DidntThrowException:
|
|
|
|
if( resultInfo.hasExpression() )
|
|
|
|
m_config.stream() << " because no exception was thrown where one was expected";
|
|
|
|
else
|
|
|
|
m_config.stream() << "No exception thrown where one was expected";
|
|
|
|
break;
|
2010-11-10 00:24:00 +01:00
|
|
|
case ResultWas::Info:
|
2011-03-14 09:50:25 +01:00
|
|
|
m_config.stream() << "info:\n'" << resultInfo.getMessage() << "'";
|
2010-11-10 00:24:00 +01:00
|
|
|
break;
|
|
|
|
case ResultWas::Warning:
|
2011-03-14 09:50:25 +01:00
|
|
|
m_config.stream() << "warning:\n'" << resultInfo.getMessage() << "'";
|
2010-11-10 00:24:00 +01:00
|
|
|
break;
|
|
|
|
case ResultWas::ExplicitFailure:
|
|
|
|
m_config.stream() << "failed with message: '" << resultInfo.getMessage() << "'";
|
|
|
|
break;
|
2010-12-28 15:42:46 +01:00
|
|
|
default:
|
2011-03-14 20:21:35 +01:00
|
|
|
if( !resultInfo.hasExpression() )
|
|
|
|
{
|
|
|
|
if( resultInfo.ok() )
|
|
|
|
m_config.stream() << " succeeded";
|
|
|
|
else
|
|
|
|
m_config.stream() << " failed";
|
|
|
|
}
|
2010-12-28 15:42:46 +01:00
|
|
|
break;
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if( resultInfo.hasExpression() )
|
|
|
|
{
|
|
|
|
m_config.stream() << " for: " << resultInfo.getExpandedExpression();
|
|
|
|
}
|
|
|
|
m_config.stream() << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-14 09:30:17 +01:00
|
|
|
virtual void EndTestCase
|
|
|
|
(
|
|
|
|
const TestCaseInfo& testInfo,
|
|
|
|
std::size_t succeeded,
|
|
|
|
std::size_t failed,
|
|
|
|
const std::string& stdOut,
|
|
|
|
const std::string& stdErr
|
|
|
|
)
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2011-03-14 09:50:25 +01:00
|
|
|
if( !stdOut.empty() )
|
|
|
|
m_config.stream() << "[stdout: " << trim( stdOut ) << "]\n";
|
2010-11-30 07:48:21 +01:00
|
|
|
|
2011-03-14 09:50:25 +01:00
|
|
|
if( !stdErr.empty() )
|
|
|
|
m_config.stream() << "[stderr: " << trim( stdErr ) << "]\n";
|
2011-02-09 20:26:59 +01:00
|
|
|
|
2011-03-14 09:50:25 +01:00
|
|
|
if( m_testSpan.emitted )
|
|
|
|
{
|
2011-02-09 20:26:59 +01:00
|
|
|
m_config.stream() << "[Finished: " << testInfo.getName() << " ";
|
|
|
|
ReportCounts( succeeded, failed );
|
|
|
|
m_config.stream() << "]" << std::endl;
|
|
|
|
}
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2011-02-09 20:26:59 +01:00
|
|
|
|
|
|
|
private: // helpers
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
void StartSpansLazily()
|
|
|
|
{
|
|
|
|
if( !m_testingSpan.emitted )
|
|
|
|
{
|
|
|
|
m_config.stream() << "[Started testing]" << 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_groupSpan.emitted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_testSpan.emitted )
|
|
|
|
{
|
|
|
|
m_config.stream() << std::endl << "[Running: " << m_testSpan.name << "]" << std::endl;
|
|
|
|
m_testSpan.emitted = true;
|
|
|
|
}
|
|
|
|
|
2011-02-28 09:18:52 +01:00
|
|
|
if( !m_sectionSpans.empty() )
|
2011-02-09 20:26:59 +01:00
|
|
|
{
|
2011-02-28 09:18:52 +01:00
|
|
|
SpanInfo& sectionSpan = m_sectionSpans.back();
|
|
|
|
if( !sectionSpan.emitted && !sectionSpan.name.empty() )
|
2011-02-09 20:26:59 +01:00
|
|
|
{
|
2011-02-28 09:18:52 +01:00
|
|
|
if( m_firstSectionInTestCase )
|
|
|
|
{
|
|
|
|
m_config.stream() << "\n";
|
|
|
|
m_firstSectionInTestCase = false;
|
|
|
|
}
|
|
|
|
std::vector<SpanInfo>::iterator it = m_sectionSpans.begin();
|
|
|
|
std::vector<SpanInfo>::iterator itEnd = m_sectionSpans.end();
|
|
|
|
for(; it != itEnd; ++it )
|
|
|
|
{
|
|
|
|
SpanInfo& prevSpan = *it;
|
|
|
|
if( !prevSpan.emitted && !prevSpan.name.empty() )
|
|
|
|
{
|
|
|
|
m_config.stream() << "[Started section: '" << prevSpan.name << "']" << std::endl;
|
|
|
|
prevSpan.emitted = true;
|
|
|
|
}
|
|
|
|
}
|
2011-02-09 20:26:59 +01:00
|
|
|
}
|
2011-02-28 09:18:52 +01:00
|
|
|
}
|
2011-02-09 20:26:59 +01:00
|
|
|
}
|
2010-11-10 00:24:00 +01:00
|
|
|
|
|
|
|
private:
|
2010-12-31 23:07:47 +01:00
|
|
|
const IReporterConfig& m_config;
|
2010-11-29 20:40:44 +01:00
|
|
|
bool m_firstSectionInTestCase;
|
2011-02-09 20:26:59 +01:00
|
|
|
|
|
|
|
SpanInfo m_testingSpan;
|
|
|
|
SpanInfo m_groupSpan;
|
|
|
|
SpanInfo m_testSpan;
|
2011-02-28 09:18:52 +01:00
|
|
|
std::vector<SpanInfo> m_sectionSpans;
|
2010-11-10 00:24:00 +01:00
|
|
|
};
|
2010-12-31 17:12:48 +01:00
|
|
|
|
2011-02-16 20:02:09 +01:00
|
|
|
INTERNAL_CATCH_REGISTER_REPORTER( "basic", BasicReporter )
|
2010-11-10 00:24:00 +01:00
|
|
|
|
|
|
|
} // end namespace Catch
|
|
|
|
|
2010-12-28 15:42:46 +01:00
|
|
|
#endif // TWOBLUECUBES_CATCH_REPORTER_BASIC_HPP_INCLUDED
|