Split EventListener base from streaming_base.hpp

The base was also renamed from `TestEventListenerBase` to
`EventListenerBase`, and modified to derive directly from the
reporter interface, rather than deriving from `StreamingReporterBase`.
This commit is contained in:
Martin Hořeňovský
2020-08-24 22:52:59 +02:00
parent f9fdc96cbf
commit 33ad1ee2ac
9 changed files with 87 additions and 28 deletions

View File

@@ -198,6 +198,7 @@ set(REPORTER_HEADERS
${SOURCES_DIR}/reporters/catch_reporter_compact.hpp
${SOURCES_DIR}/reporters/catch_reporter_console.hpp
${SOURCES_DIR}/reporters/catch_reporter_cumulative_base.hpp
${SOURCES_DIR}/reporters/catch_reporter_event_listener.hpp
${SOURCES_DIR}/reporters/catch_reporter_helpers.hpp
${SOURCES_DIR}/reporters/catch_reporter_junit.hpp
${SOURCES_DIR}/reporters/catch_reporter_listening.hpp

View File

@@ -81,4 +81,33 @@ namespace Catch {
}
return out;
}
} // namespace Catch
#include <catch2/reporters/catch_reporter_event_listener.hpp>
namespace Catch {
void EventListenerBase::assertionStarting( AssertionInfo const& ) {}
bool EventListenerBase::assertionEnded( AssertionStats const& ) {
return false;
}
void
EventListenerBase::listReporters( std::vector<ReporterDescription> const&,
IConfig const& ) {}
void EventListenerBase::listTests( std::vector<TestCaseHandle> const&,
IConfig const& ) {}
void EventListenerBase::listTags( std::vector<TagInfo> const&,
IConfig const& ) {}
void EventListenerBase::noMatchingTestCases( std::string const& ) {}
void EventListenerBase::testRunStarting( TestRunInfo const& ) {}
void EventListenerBase::testGroupStarting( GroupInfo const& ) {}
void EventListenerBase::testCaseStarting( TestCaseInfo const& ) {}
void EventListenerBase::sectionStarting( SectionInfo const& ) {}
void EventListenerBase::sectionEnded( SectionStats const& ) {}
void EventListenerBase::testCaseEnded( TestCaseStats const& ) {}
void EventListenerBase::testGroupEnded( TestGroupStats const& ) {}
void EventListenerBase::testRunEnded( TestRunStats const& ) {}
void EventListenerBase::skipTest( TestCaseInfo const& ) {}
} // namespace Catch

View File

@@ -0,0 +1,47 @@
#ifndef CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED
#define CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
namespace Catch {
/**
* Base class identifying listeners.
*
* Provides default implementation for all IStreamingReporter member
* functions, so that listeners implementations can pick which
* member functions it actually cares about.
*/
class EventListenerBase : public IStreamingReporter {
IConfig const* m_config;
public:
EventListenerBase( ReporterConfig const& config ):
m_config( config.fullConfig() ) {}
void assertionStarting( AssertionInfo const& assertionInfo ) override;
bool assertionEnded( AssertionStats const& assertionStats ) override;
void
listReporters( std::vector<ReporterDescription> const& descriptions,
IConfig const& config ) override;
void listTests( std::vector<TestCaseHandle> const& tests,
IConfig const& config ) override;
void listTags( std::vector<TagInfo> const& tagInfos,
IConfig const& config ) override;
void noMatchingTestCases( std::string const& spec ) override;
void testRunStarting( TestRunInfo const& testRunInfo ) override;
void testGroupStarting( GroupInfo const& groupInfo ) override;
void testCaseStarting( TestCaseInfo const& testInfo ) override;
void sectionStarting( SectionInfo const& sectionInfo ) 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;
void skipTest( TestCaseInfo const& testInfo ) override;
};
} // end namespace Catch
#endif // CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED

View File

@@ -2,16 +2,6 @@
namespace Catch {
TestEventListenerBase::TestEventListenerBase(
ReporterConfig const& _config ):
StreamingReporterBase( _config ) {}
void TestEventListenerBase::assertionStarting( AssertionInfo const& ) {}
bool TestEventListenerBase::assertionEnded( AssertionStats const& ) {
return false;
}
StreamingReporterBase::~StreamingReporterBase() = default;
void

View File

@@ -74,18 +74,6 @@ namespace Catch {
std::vector<SectionInfo> m_sectionStack;
};
struct TestEventListenerBase : StreamingReporterBase {
TestEventListenerBase( ReporterConfig const& _config );
void assertionStarting(AssertionInfo const&) override;
bool assertionEnded(AssertionStats const&) override;
// Event listeners should not use the default listing impl
void listReporters(std::vector<ReporterDescription> const&, IConfig const&) override {}
void listTests(std::vector<TestCaseHandle> const&, IConfig const&) override {}
void listTags(std::vector<TagInfo> const&, IConfig const&) override {}
};
} // end namespace Catch
#endif // CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED

View File

@@ -18,6 +18,7 @@
#include <catch2/reporters/catch_reporter_compact.hpp>
#include <catch2/reporters/catch_reporter_console.hpp>
#include <catch2/reporters/catch_reporter_cumulative_base.hpp>
#include <catch2/reporters/catch_reporter_event_listener.hpp>
#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <catch2/reporters/catch_reporter_junit.hpp>
#include <catch2/reporters/catch_reporter_listening.hpp>