Skip to content

Commit

Permalink
Refactor how listening reporter updates its preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
horenmar committed Dec 19, 2021
1 parent d20087b commit b981b9e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/catch2/reporters/catch_reporter_listening.cpp
Expand Up @@ -14,21 +14,27 @@
#include <cassert>

namespace Catch {
void ListeningReporter::updatePreferences(IStreamingReporter const& reporterish) {
m_preferences.shouldRedirectStdOut |=
reporterish.getPreferences().shouldRedirectStdOut;
m_preferences.shouldReportAllAssertions |=
reporterish.getPreferences().shouldReportAllAssertions;
}

void ListeningReporter::addListener( IStreamingReporterPtr&& listener ) {
updatePreferences(*listener);
m_listeners.insert(m_listeners.begin() + m_insertedListeners, CATCH_MOVE(listener) );
++m_insertedListeners;
}

void ListeningReporter::addReporter( IStreamingReporterPtr&& reporter ) {
m_preferences.shouldRedirectStdOut |= reporter->getPreferences().shouldRedirectStdOut;
updatePreferences(*reporter);

// We will need to output the captured stdout if there are reporters
// that do not want it captured.
// TODO: Should this also apply to listeners?
m_haveNoncapturingListeners |= !reporter->getPreferences().shouldRedirectStdOut;

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
3 changes: 3 additions & 0 deletions src/catch2/reporters/catch_reporter_listening.hpp
Expand Up @@ -24,6 +24,9 @@ namespace Catch {
// 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;

void updatePreferences(IStreamingReporter const& reporterish);

public:
ListeningReporter( IConfig const* config ):
IStreamingReporter( config ) {
Expand Down

0 comments on commit b981b9e

Please sign in to comment.