diff --git a/src/catch2/reporters/catch_reporter_listening.cpp b/src/catch2/reporters/catch_reporter_listening.cpp index de3a2b9f29..771b3c4f23 100644 --- a/src/catch2/reporters/catch_reporter_listening.cpp +++ b/src/catch2/reporters/catch_reporter_listening.cpp @@ -16,7 +16,8 @@ namespace Catch { void ListeningReporter::addListener( IStreamingReporterPtr&& listener ) { - m_listeners.push_back( CATCH_MOVE( listener ) ); + m_listeners.insert(m_listeners.begin() + m_insertedListeners, CATCH_MOVE(listener) ); + ++m_insertedListeners; } void ListeningReporter::addReporter( IStreamingReporterPtr&& reporter ) { @@ -28,6 +29,8 @@ namespace Catch { m_preferences.shouldReportAllAssertions |= reporter->getPreferences().shouldReportAllAssertions; + // Reporters can always be placed to the back without breaking the + // reporting order m_listeners.push_back( CATCH_MOVE( reporter ) ); } diff --git a/src/catch2/reporters/catch_reporter_listening.hpp b/src/catch2/reporters/catch_reporter_listening.hpp index 7b98c0219d..d998711d43 100644 --- a/src/catch2/reporters/catch_reporter_listening.hpp +++ b/src/catch2/reporters/catch_reporter_listening.hpp @@ -14,9 +14,16 @@ namespace Catch { class ListeningReporter final : public IStreamingReporter { using Reporters = std::vector; + // It is important that all listeners are called before any + // reporter. + // Reporters and listeners should also be generally called + // in order of their insertion. Reporters m_listeners; bool m_haveNoncapturingListeners = false; + // Keep track of how many listeners we have already inserted, + // so that we can insert them into the main vector at the right place + size_t m_insertedListeners = 0; public: ListeningReporter( IConfig const* config ): IStreamingReporter( config ) {