Files
Catch2/include/reporters/catch_reporter_multi.cpp
T

124 lines
3.8 KiB
C++
Raw Normal View History

2015-08-05 19:02:17 +01:00
/*
* Created by Phil on 5/08/2015.
* Copyright 2015 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)
*/
#include "../internal/catch_interfaces_reporter.h"
namespace Catch {
2017-04-25 21:51:44 +01:00
class MultipleReporters : public IStreamingReporter {
2017-04-29 19:38:34 +01:00
typedef std::vector<IStreamingReporterPtr> Reporters;
2015-08-05 19:02:17 +01:00
Reporters m_reporters;
2015-08-05 19:02:17 +01:00
public:
2017-04-29 19:38:34 +01:00
void add( IStreamingReporterPtr&& reporter ) {
m_reporters.push_back( std::move( reporter ) );
2015-08-05 19:02:17 +01:00
}
2015-08-05 19:02:17 +01:00
public: // IStreamingReporter
2017-04-25 12:41:30 +02:00
virtual ReporterPreferences getPreferences() const override {
2015-08-05 19:02:17 +01:00
return m_reporters[0]->getPreferences();
}
2017-04-25 12:41:30 +02:00
virtual void noMatchingTestCases( std::string const& spec ) override {
for( auto const& reporter : m_reporters )
reporter->noMatchingTestCases( spec );
2015-08-05 19:02:17 +01:00
}
2017-04-25 12:41:30 +02:00
virtual void testRunStarting( TestRunInfo const& testRunInfo ) override {
for( auto const& reporter : m_reporters )
reporter->testRunStarting( testRunInfo );
2015-08-05 19:02:17 +01:00
}
2017-04-25 12:41:30 +02:00
virtual void testGroupStarting( GroupInfo const& groupInfo ) override {
for( auto const& reporter : m_reporters )
reporter->testGroupStarting( groupInfo );
2015-08-05 19:02:17 +01:00
}
2017-04-25 12:41:30 +02:00
virtual void testCaseStarting( TestCaseInfo const& testInfo ) override {
for( auto const& reporter : m_reporters )
reporter->testCaseStarting( testInfo );
2015-08-05 19:02:17 +01:00
}
2017-04-25 12:41:30 +02:00
virtual void sectionStarting( SectionInfo const& sectionInfo ) override {
for( auto const& reporter : m_reporters )
reporter->sectionStarting( sectionInfo );
2015-08-05 19:02:17 +01:00
}
2017-04-25 12:41:30 +02:00
virtual void assertionStarting( AssertionInfo const& assertionInfo ) override {
for( auto const& reporter : m_reporters )
reporter->assertionStarting( assertionInfo );
2015-08-05 19:02:17 +01:00
}
2015-08-05 19:02:17 +01:00
// The return value indicates if the messages buffer should be cleared:
2017-04-25 12:41:30 +02:00
virtual bool assertionEnded( AssertionStats const& assertionStats ) override {
2015-08-05 19:02:17 +01:00
bool clearBuffer = false;
for( auto const& reporter : m_reporters )
clearBuffer |= reporter->assertionEnded( assertionStats );
2015-08-05 19:02:17 +01:00
return clearBuffer;
}
2017-04-25 12:41:30 +02:00
virtual void sectionEnded( SectionStats const& sectionStats ) override {
for( auto const& reporter : m_reporters )
reporter->sectionEnded( sectionStats );
2015-08-05 19:02:17 +01:00
}
2017-04-25 12:41:30 +02:00
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) override {
for( auto const& reporter : m_reporters )
reporter->testCaseEnded( testCaseStats );
2015-08-05 19:02:17 +01:00
}
2017-04-25 12:41:30 +02:00
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) override {
for( auto const& reporter : m_reporters )
reporter->testGroupEnded( testGroupStats );
2015-08-05 19:02:17 +01:00
}
2017-04-25 12:41:30 +02:00
virtual void testRunEnded( TestRunStats const& testRunStats ) override {
for( auto const& reporter : m_reporters )
reporter->testRunEnded( testRunStats );
2015-08-05 19:02:17 +01:00
}
2017-04-25 12:41:30 +02:00
virtual void skipTest( TestCaseInfo const& testInfo ) override {
for( auto const& reporter : m_reporters )
reporter->skipTest( testInfo );
2015-08-05 19:02:17 +01:00
}
2017-01-26 23:13:12 +01:00
2017-04-29 19:38:34 +01:00
virtual bool isMulti() const override {
return true;
}
2017-01-26 23:13:12 +01:00
2015-08-05 19:02:17 +01:00
};
2017-04-29 19:38:34 +01:00
void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter ) {
2017-04-29 19:38:34 +01:00
if( !existingReporter ) {
existingReporter = std::move( additionalReporter );
return;
2015-08-05 19:02:17 +01:00
}
2017-04-29 19:38:34 +01:00
MultipleReporters* multi = nullptr;
if( existingReporter->isMulti() ) {
multi = static_cast<MultipleReporters*>( existingReporter.get() );
}
else {
auto newMulti = std::unique_ptr<MultipleReporters>( new MultipleReporters );
newMulti->add( std::move( existingReporter ) );
multi = newMulti.get();
existingReporter = std::move( newMulti );
}
multi->add( std::move( additionalReporter ) );
2015-08-05 19:02:17 +01:00
}
2015-08-05 19:02:17 +01:00
} // end namespace Catch