2015-08-05 20:02:17 +02: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 22:51:44 +02:00
|
|
|
class MultipleReporters : public IStreamingReporter {
|
2017-04-29 20:38:34 +02:00
|
|
|
typedef std::vector<IStreamingReporterPtr> Reporters;
|
2015-08-05 20:02:17 +02:00
|
|
|
Reporters m_reporters;
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-08-05 20:02:17 +02:00
|
|
|
public:
|
2017-04-29 20:38:34 +02:00
|
|
|
void add( IStreamingReporterPtr&& reporter ) {
|
|
|
|
m_reporters.push_back( std::move( reporter ) );
|
2015-08-05 20:02:17 +02:00
|
|
|
}
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-08-05 20:02:17 +02:00
|
|
|
public: // IStreamingReporter
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual ReporterPreferences getPreferences() const override {
|
2015-08-05 20:02:17 +02:00
|
|
|
return m_reporters[0]->getPreferences();
|
|
|
|
}
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual void noMatchingTestCases( std::string const& spec ) override {
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& reporter : m_reporters )
|
|
|
|
reporter->noMatchingTestCases( spec );
|
2015-08-05 20:02:17 +02:00
|
|
|
}
|
|
|
|
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual void testRunStarting( TestRunInfo const& testRunInfo ) override {
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& reporter : m_reporters )
|
|
|
|
reporter->testRunStarting( testRunInfo );
|
2015-08-05 20:02:17 +02:00
|
|
|
}
|
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual void testGroupStarting( GroupInfo const& groupInfo ) override {
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& reporter : m_reporters )
|
|
|
|
reporter->testGroupStarting( groupInfo );
|
2015-08-05 20:02:17 +02:00
|
|
|
}
|
|
|
|
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual void testCaseStarting( TestCaseInfo const& testInfo ) override {
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& reporter : m_reporters )
|
|
|
|
reporter->testCaseStarting( testInfo );
|
2015-08-05 20:02:17 +02:00
|
|
|
}
|
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual void sectionStarting( SectionInfo const& sectionInfo ) override {
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& reporter : m_reporters )
|
|
|
|
reporter->sectionStarting( sectionInfo );
|
2015-08-05 20:02:17 +02:00
|
|
|
}
|
|
|
|
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual void assertionStarting( AssertionInfo const& assertionInfo ) override {
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& reporter : m_reporters )
|
|
|
|
reporter->assertionStarting( assertionInfo );
|
2015-08-05 20:02:17 +02:00
|
|
|
}
|
|
|
|
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-08-05 20:02:17 +02: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 20:02:17 +02:00
|
|
|
bool clearBuffer = false;
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& reporter : m_reporters )
|
|
|
|
clearBuffer |= reporter->assertionEnded( assertionStats );
|
2015-08-05 20:02:17 +02:00
|
|
|
return clearBuffer;
|
|
|
|
}
|
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual void sectionEnded( SectionStats const& sectionStats ) override {
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& reporter : m_reporters )
|
|
|
|
reporter->sectionEnded( sectionStats );
|
2015-08-05 20:02:17 +02:00
|
|
|
}
|
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) override {
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& reporter : m_reporters )
|
|
|
|
reporter->testCaseEnded( testCaseStats );
|
2015-08-05 20:02:17 +02:00
|
|
|
}
|
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) override {
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& reporter : m_reporters )
|
|
|
|
reporter->testGroupEnded( testGroupStats );
|
2015-08-05 20:02:17 +02:00
|
|
|
}
|
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual void testRunEnded( TestRunStats const& testRunStats ) override {
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& reporter : m_reporters )
|
|
|
|
reporter->testRunEnded( testRunStats );
|
2015-08-05 20:02:17 +02:00
|
|
|
}
|
|
|
|
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-04-25 12:41:30 +02:00
|
|
|
virtual void skipTest( TestCaseInfo const& testInfo ) override {
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& reporter : m_reporters )
|
|
|
|
reporter->skipTest( testInfo );
|
2015-08-05 20:02:17 +02:00
|
|
|
}
|
2017-01-26 23:13:12 +01:00
|
|
|
|
2017-04-29 20:38:34 +02:00
|
|
|
virtual bool isMulti() const override {
|
|
|
|
return true;
|
2016-04-28 08:54:57 +02:00
|
|
|
}
|
2017-01-26 23:13:12 +01:00
|
|
|
|
2015-08-05 20:02:17 +02:00
|
|
|
};
|
|
|
|
|
2017-04-29 20:38:34 +02:00
|
|
|
void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter ) {
|
|
|
|
|
|
|
|
if( !existingReporter ) {
|
|
|
|
existingReporter = std::move( additionalReporter );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 20:02:17 +02:00
|
|
|
}
|
2015-11-04 19:01:28 +01:00
|
|
|
|
|
|
|
|
2015-08-05 20:02:17 +02:00
|
|
|
} // end namespace Catch
|