Skip to content

Commit

Permalink
Insert listeners and reporters in the right order
Browse files Browse the repository at this point in the history
  • Loading branch information
horenmar committed Dec 19, 2021
1 parent fd3fba3 commit d20087b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/catch2/reporters/catch_reporter_listening.cpp
Expand Up @@ -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 ) {
Expand All @@ -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 ) );
}

Expand Down
7 changes: 7 additions & 0 deletions src/catch2/reporters/catch_reporter_listening.hpp
Expand Up @@ -14,9 +14,16 @@ namespace Catch {

class ListeningReporter final : public IStreamingReporter {
using Reporters = std::vector<IStreamingReporterPtr>;
// 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 ) {
Expand Down

0 comments on commit d20087b

Please sign in to comment.