mirror of https://github.com/catchorg/Catch2.git
Previous implementation didn't work
It relied on calling a virtual method from a base constructer
This commit is contained in:
parent
f749347523
commit
058b21e604
|
@ -77,10 +77,12 @@ namespace Catch {
|
||||||
TestCaseStats::~TestCaseStats() {}
|
TestCaseStats::~TestCaseStats() {}
|
||||||
TestGroupStats::~TestGroupStats() {}
|
TestGroupStats::~TestGroupStats() {}
|
||||||
TestRunStats::~TestRunStats() {}
|
TestRunStats::~TestRunStats() {}
|
||||||
CumulativeReporterBase::SectionNode::~SectionNode() {}
|
template<typename DerivedT>
|
||||||
CumulativeReporterBase::~CumulativeReporterBase() {}
|
CumulativeReporterBase<DerivedT>::SectionNode::~SectionNode() {}
|
||||||
|
template<typename DerivedT>
|
||||||
StreamingReporterBase::~StreamingReporterBase() {}
|
CumulativeReporterBase<DerivedT>::~CumulativeReporterBase() {}
|
||||||
|
template<typename DerivedT>
|
||||||
|
StreamingReporterBase<DerivedT>::~StreamingReporterBase() {}
|
||||||
ConsoleReporter::~ConsoleReporter() {}
|
ConsoleReporter::~ConsoleReporter() {}
|
||||||
CompactReporter::~CompactReporter() {}
|
CompactReporter::~CompactReporter() {}
|
||||||
IRunner::~IRunner() {}
|
IRunner::~IRunner() {}
|
||||||
|
|
|
@ -208,13 +208,12 @@ namespace Catch
|
||||||
struct IStreamingReporter {
|
struct IStreamingReporter {
|
||||||
virtual ~IStreamingReporter();
|
virtual ~IStreamingReporter();
|
||||||
|
|
||||||
// Implementing class must also provide the following static method:
|
// Implementing class must also provide the following static methods:
|
||||||
// static std::string getDescription();
|
// static std::string getDescription();
|
||||||
|
// static std::set<Verbosity> getSupportedVerbosities()
|
||||||
|
|
||||||
virtual ReporterPreferences getPreferences() const = 0;
|
virtual ReporterPreferences getPreferences() const = 0;
|
||||||
|
|
||||||
virtual std::set<Verbosity> const& getSupportedVerbosities() const = 0;
|
|
||||||
|
|
||||||
virtual void noMatchingTestCases( std::string const& spec ) = 0;
|
virtual void noMatchingTestCases( std::string const& spec ) = 0;
|
||||||
|
|
||||||
virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
|
virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct AutomakeReporter : StreamingReporterBase {
|
struct AutomakeReporter : StreamingReporterBase<AutomakeReporter> {
|
||||||
AutomakeReporter( ReporterConfig const& _config )
|
AutomakeReporter( ReporterConfig const& _config )
|
||||||
: StreamingReporterBase( _config )
|
: StreamingReporterBase( _config )
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace Catch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename DerivedT>
|
||||||
struct StreamingReporterBase : IStreamingReporter {
|
struct StreamingReporterBase : IStreamingReporter {
|
||||||
|
|
||||||
StreamingReporterBase( ReporterConfig const& _config )
|
StreamingReporterBase( ReporterConfig const& _config )
|
||||||
|
@ -49,16 +49,15 @@ namespace Catch {
|
||||||
stream( _config.stream() )
|
stream( _config.stream() )
|
||||||
{
|
{
|
||||||
m_reporterPrefs.shouldRedirectStdOut = false;
|
m_reporterPrefs.shouldRedirectStdOut = false;
|
||||||
CATCH_ENFORCE( getSupportedVerbosities().count( m_config->verbosity() ), "Verbosity level not supported by this reporter" );
|
CATCH_ENFORCE( DerivedT::getSupportedVerbosities().count( m_config->verbosity() ), "Verbosity level not supported by this reporter" );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ReporterPreferences getPreferences() const override {
|
virtual ReporterPreferences getPreferences() const override {
|
||||||
return m_reporterPrefs;
|
return m_reporterPrefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::set<Verbosity> const& getSupportedVerbosities() const override {
|
static std::set<Verbosity> getSupportedVerbosities() {
|
||||||
static std::set<Verbosity> supported{ Verbosity::Normal };
|
return { Verbosity::Normal };
|
||||||
return supported;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~StreamingReporterBase() override;
|
virtual ~StreamingReporterBase() override;
|
||||||
|
@ -110,6 +109,7 @@ namespace Catch {
|
||||||
ReporterPreferences m_reporterPrefs;
|
ReporterPreferences m_reporterPrefs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename DerivedT>
|
||||||
struct CumulativeReporterBase : IStreamingReporter {
|
struct CumulativeReporterBase : IStreamingReporter {
|
||||||
template<typename T, typename ChildNodeT>
|
template<typename T, typename ChildNodeT>
|
||||||
struct Node {
|
struct Node {
|
||||||
|
@ -161,7 +161,7 @@ namespace Catch {
|
||||||
stream( _config.stream() )
|
stream( _config.stream() )
|
||||||
{
|
{
|
||||||
m_reporterPrefs.shouldRedirectStdOut = false;
|
m_reporterPrefs.shouldRedirectStdOut = false;
|
||||||
CATCH_ENFORCE( getSupportedVerbosities().count( m_config->verbosity() ), "Verbosity level not supported by this reporter" );
|
CATCH_ENFORCE( DerivedT::getSupportedVerbosities().count( m_config->verbosity() ), "Verbosity level not supported by this reporter" );
|
||||||
}
|
}
|
||||||
~CumulativeReporterBase();
|
~CumulativeReporterBase();
|
||||||
|
|
||||||
|
@ -169,9 +169,8 @@ namespace Catch {
|
||||||
return m_reporterPrefs;
|
return m_reporterPrefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::set<Verbosity> const& getSupportedVerbosities() const override {
|
static std::set<Verbosity> getSupportedVerbosities() {
|
||||||
static std::set<Verbosity> supported{ Verbosity::Normal };
|
return { Verbosity::Normal };
|
||||||
return supported;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void testRunStarting( TestRunInfo const& ) override {}
|
virtual void testRunStarting( TestRunInfo const& ) override {}
|
||||||
|
@ -189,7 +188,7 @@ namespace Catch {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SectionNode& parentNode = *m_sectionStack.back();
|
SectionNode& parentNode = *m_sectionStack.back();
|
||||||
SectionNode::ChildSections::const_iterator it =
|
typename SectionNode::ChildSections::const_iterator it =
|
||||||
std::find_if( parentNode.childSections.begin(),
|
std::find_if( parentNode.childSections.begin(),
|
||||||
parentNode.childSections.end(),
|
parentNode.childSections.end(),
|
||||||
BySectionInfo( sectionInfo ) );
|
BySectionInfo( sectionInfo ) );
|
||||||
|
@ -284,7 +283,7 @@ namespace Catch {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct TestEventListenerBase : StreamingReporterBase {
|
struct TestEventListenerBase : StreamingReporterBase<TestEventListenerBase> {
|
||||||
TestEventListenerBase( ReporterConfig const& _config )
|
TestEventListenerBase( ReporterConfig const& _config )
|
||||||
: StreamingReporterBase( _config )
|
: StreamingReporterBase( _config )
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct CompactReporter : StreamingReporterBase {
|
struct CompactReporter : StreamingReporterBase<CompactReporter> {
|
||||||
|
|
||||||
using StreamingReporterBase::StreamingReporterBase;
|
using StreamingReporterBase::StreamingReporterBase;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
|
||||||
struct ConsoleReporter : StreamingReporterBase {
|
struct ConsoleReporter : StreamingReporterBase<ConsoleReporter> {
|
||||||
using StreamingReporterBase::StreamingReporterBase;
|
using StreamingReporterBase::StreamingReporterBase;
|
||||||
|
|
||||||
virtual ~ConsoleReporter() override;
|
virtual ~ConsoleReporter() override;
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace Catch {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class JunitReporter : public CumulativeReporterBase {
|
class JunitReporter : public CumulativeReporterBase<JunitReporter> {
|
||||||
public:
|
public:
|
||||||
JunitReporter( ReporterConfig const& _config )
|
JunitReporter( ReporterConfig const& _config )
|
||||||
: CumulativeReporterBase( _config ),
|
: CumulativeReporterBase( _config ),
|
||||||
|
|
|
@ -15,23 +15,9 @@ namespace Catch {
|
||||||
class MultipleReporters : public IStreamingReporter {
|
class MultipleReporters : public IStreamingReporter {
|
||||||
typedef std::vector<IStreamingReporterPtr> Reporters;
|
typedef std::vector<IStreamingReporterPtr> Reporters;
|
||||||
Reporters m_reporters;
|
Reporters m_reporters;
|
||||||
std::set<Verbosity> m_verbosities;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void add( IStreamingReporterPtr&& reporter ) {
|
void add( IStreamingReporterPtr&& reporter ) {
|
||||||
if( m_reporters.empty() ) {
|
|
||||||
m_verbosities = reporter->getSupportedVerbosities();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for( auto it = m_verbosities.cbegin(); it != m_verbosities.cend(); ) {
|
|
||||||
if( reporter->getSupportedVerbosities().count( *it ) == 0 ) {
|
|
||||||
it = m_verbosities.erase(it);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_reporters.push_back( std::move( reporter ) );
|
m_reporters.push_back( std::move( reporter ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +27,8 @@ public: // IStreamingReporter
|
||||||
return m_reporters[0]->getPreferences();
|
return m_reporters[0]->getPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::set<Verbosity> const& getSupportedVerbosities() const override {
|
static std::set<Verbosity> getSupportedVerbosities() {
|
||||||
return m_verbosities;
|
return { };
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void noMatchingTestCases( std::string const& spec ) override {
|
virtual void noMatchingTestCases( std::string const& spec ) override {
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct TAPReporter : StreamingReporterBase {
|
struct TAPReporter : StreamingReporterBase<TAPReporter> {
|
||||||
|
|
||||||
using StreamingReporterBase::StreamingReporterBase;
|
using StreamingReporterBase::StreamingReporterBase;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct TeamCityReporter : StreamingReporterBase {
|
struct TeamCityReporter : StreamingReporterBase<TeamCityReporter> {
|
||||||
TeamCityReporter( ReporterConfig const& _config )
|
TeamCityReporter( ReporterConfig const& _config )
|
||||||
: StreamingReporterBase( _config )
|
: StreamingReporterBase( _config )
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include "../internal/catch_timer.h"
|
#include "../internal/catch_timer.h"
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
class XmlReporter : public StreamingReporterBase {
|
class XmlReporter : public StreamingReporterBase<XmlReporter> {
|
||||||
public:
|
public:
|
||||||
XmlReporter( ReporterConfig const& _config )
|
XmlReporter( ReporterConfig const& _config )
|
||||||
: StreamingReporterBase( _config ),
|
: StreamingReporterBase( _config ),
|
||||||
|
|
Loading…
Reference in New Issue