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)
|
|
|
|
*/
|
|
|
|
#ifndef TWOBLUECUBES_CATCH_REPORTER_MULTI_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_REPORTER_MULTI_HPP_INCLUDED
|
|
|
|
|
|
|
|
#include "../internal/catch_interfaces_reporter.h"
|
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
|
2017-04-25 22:51:44 +02:00
|
|
|
class MultipleReporters : public IStreamingReporter {
|
2017-04-25 21:42:01 +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-25 21:42:01 +02:00
|
|
|
void add( IStreamingReporterPtr const& reporter ) {
|
2015-08-05 20:02:17 +02:00
|
|
|
m_reporters.push_back( reporter );
|
|
|
|
}
|
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-25 12:41:30 +02:00
|
|
|
virtual MultipleReporters* tryAsMulti() override {
|
2016-04-28 08:54:57 +02:00
|
|
|
return this;
|
|
|
|
}
|
2017-01-26 23:13:12 +01:00
|
|
|
|
2015-08-05 20:02:17 +02:00
|
|
|
};
|
|
|
|
|
2017-04-25 21:42:01 +02:00
|
|
|
IStreamingReporterPtr addReporter( IStreamingReporterPtr const& existingReporter, IStreamingReporterPtr const& additionalReporter ) {
|
|
|
|
IStreamingReporterPtr resultingReporter;
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-08-05 20:02:17 +02:00
|
|
|
if( existingReporter ) {
|
2016-04-28 08:54:57 +02:00
|
|
|
MultipleReporters* multi = existingReporter->tryAsMulti();
|
2015-08-05 20:02:17 +02:00
|
|
|
if( !multi ) {
|
|
|
|
multi = new MultipleReporters;
|
2017-04-25 21:42:01 +02:00
|
|
|
resultingReporter = IStreamingReporterPtr( multi );
|
2015-08-05 20:02:17 +02:00
|
|
|
if( existingReporter )
|
|
|
|
multi->add( existingReporter );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
resultingReporter = existingReporter;
|
|
|
|
multi->add( additionalReporter );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
resultingReporter = additionalReporter;
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-08-05 20:02:17 +02:00
|
|
|
return resultingReporter;
|
|
|
|
}
|
2015-11-04 19:01:28 +01:00
|
|
|
|
|
|
|
|
2015-08-05 20:02:17 +02:00
|
|
|
} // end namespace Catch
|
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_REPORTER_MULTI_HPP_INCLUDED
|