Skip to content

Commit

Permalink
Renames and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
horenmar committed Dec 22, 2021
1 parent 8296f9f commit dceb260
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 57 deletions.
102 changes: 52 additions & 50 deletions src/catch2/reporters/catch_reporter_listening.cpp
Expand Up @@ -23,7 +23,7 @@ namespace Catch {

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

Expand All @@ -32,156 +32,158 @@ namespace Catch {

// 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;
// We do not consider listeners, because it is generally assumed that
// listeners are output-transparent, even though they can ask for stdout
// capture to do something with it.
m_haveNoncapturingReporters |= !reporter->getPreferences().shouldRedirectStdOut;

// Reporters can always be placed to the back without breaking the
// reporting order
m_listeners.push_back( CATCH_MOVE( reporter ) );
m_reporterLikes.push_back( CATCH_MOVE( reporter ) );
}

void ListeningReporter::noMatchingTestCases( StringRef unmatchedSpec ) {
for ( auto& listener : m_listeners ) {
listener->noMatchingTestCases( unmatchedSpec );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->noMatchingTestCases( unmatchedSpec );
}
}

void ListeningReporter::fatalErrorEncountered( StringRef error ) {
for ( auto& listener : m_listeners ) {
listener->fatalErrorEncountered( error );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->fatalErrorEncountered( error );
}
}

void ListeningReporter::reportInvalidTestSpec( StringRef arg ) {
for ( auto& listener : m_listeners ) {
listener->reportInvalidTestSpec( arg );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->reportInvalidTestSpec( arg );
}
}

void ListeningReporter::benchmarkPreparing( StringRef name ) {
for (auto& listener : m_listeners) {
listener->benchmarkPreparing(name);
for (auto& reporterish : m_reporterLikes) {
reporterish->benchmarkPreparing(name);
}
}
void ListeningReporter::benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) {
for ( auto& listener : m_listeners ) {
listener->benchmarkStarting( benchmarkInfo );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->benchmarkStarting( benchmarkInfo );
}
}
void ListeningReporter::benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) {
for ( auto& listener : m_listeners ) {
listener->benchmarkEnded( benchmarkStats );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->benchmarkEnded( benchmarkStats );
}
}

void ListeningReporter::benchmarkFailed( StringRef error ) {
for (auto& listener : m_listeners) {
listener->benchmarkFailed(error);
for (auto& reporterish : m_reporterLikes) {
reporterish->benchmarkFailed(error);
}
}

void ListeningReporter::testRunStarting( TestRunInfo const& testRunInfo ) {
for ( auto& listener : m_listeners ) {
listener->testRunStarting( testRunInfo );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->testRunStarting( testRunInfo );
}
}

void ListeningReporter::testCaseStarting( TestCaseInfo const& testInfo ) {
for ( auto& listener : m_listeners ) {
listener->testCaseStarting( testInfo );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->testCaseStarting( testInfo );
}
}

void
ListeningReporter::testCasePartialStarting( TestCaseInfo const& testInfo,
uint64_t partNumber ) {
for ( auto& listener : m_listeners ) {
listener->testCasePartialStarting( testInfo, partNumber );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->testCasePartialStarting( testInfo, partNumber );
}
}

void ListeningReporter::sectionStarting( SectionInfo const& sectionInfo ) {
for ( auto& listener : m_listeners ) {
listener->sectionStarting( sectionInfo );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->sectionStarting( sectionInfo );
}
}

void ListeningReporter::assertionStarting( AssertionInfo const& assertionInfo ) {
for ( auto& listener : m_listeners ) {
listener->assertionStarting( assertionInfo );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->assertionStarting( assertionInfo );
}
}

// The return value indicates if the messages buffer should be cleared:
void ListeningReporter::assertionEnded( AssertionStats const& assertionStats ) {
const bool alwaysReport =
const bool reportByDefault =
assertionStats.assertionResult.getResultType() != ResultWas::Ok ||
m_config->includeSuccessfulResults();

for ( auto & listener : m_listeners ) {
if ( alwaysReport ||
listener->getPreferences().shouldReportAllAssertions ) {
listener->assertionEnded( assertionStats );
for ( auto & reporterish : m_reporterLikes ) {
if ( reportByDefault ||
reporterish->getPreferences().shouldReportAllAssertions ) {
reporterish->assertionEnded( assertionStats );
}
}
}

void ListeningReporter::sectionEnded( SectionStats const& sectionStats ) {
for ( auto& listener : m_listeners ) {
listener->sectionEnded( sectionStats );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->sectionEnded( sectionStats );
}
}

void ListeningReporter::testCasePartialEnded( TestCaseStats const& testStats,
uint64_t partNumber ) {
// TODO: Fix handling of stderr/stdout?
for ( auto& listener : m_listeners ) {
listener->testCasePartialEnded( testStats, partNumber );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->testCasePartialEnded( testStats, partNumber );
}
}

void ListeningReporter::testCaseEnded( TestCaseStats const& testCaseStats ) {
if ( m_preferences.shouldRedirectStdOut && m_haveNoncapturingListeners ) {
if ( m_preferences.shouldRedirectStdOut && m_haveNoncapturingReporters ) {
if ( !testCaseStats.stdOut.empty() ) {
Catch::cout() << testCaseStats.stdOut << std::flush;
}
if ( !testCaseStats.stdErr.empty() ) {
Catch::cerr() << testCaseStats.stdErr << std::flush;
}
}
for ( auto& listener : m_listeners ) {
listener->testCaseEnded( testCaseStats );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->testCaseEnded( testCaseStats );
}
}

void ListeningReporter::testRunEnded( TestRunStats const& testRunStats ) {
for ( auto& listener : m_listeners ) {
listener->testRunEnded( testRunStats );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->testRunEnded( testRunStats );
}
}


void ListeningReporter::skipTest( TestCaseInfo const& testInfo ) {
for ( auto& listener : m_listeners ) {
listener->skipTest( testInfo );
for ( auto& reporterish : m_reporterLikes ) {
reporterish->skipTest( testInfo );
}
}

void ListeningReporter::listReporters(std::vector<ReporterDescription> const& descriptions) {
for (auto& listener : m_listeners) {
listener->listReporters(descriptions);
for (auto& reporterish : m_reporterLikes) {
reporterish->listReporters(descriptions);
}
}

void ListeningReporter::listTests(std::vector<TestCaseHandle> const& tests) {
for (auto& listener : m_listeners) {
listener->listTests(tests);
for (auto& reporterish : m_reporterLikes) {
reporterish->listTests(tests);
}
}

void ListeningReporter::listTags(std::vector<TagInfo> const& tags) {
for (auto& listener : m_listeners) {
listener->listTags(tags);
for (auto& reporterish : m_reporterLikes) {
reporterish->listTags(tags);
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/catch2/reporters/catch_reporter_listening.hpp
Expand Up @@ -13,13 +13,14 @@
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;
/*
* Stores all added reporters and listeners
*
* All Listeners are stored before all reporters, and individual
* listeners/reporters are stored in order of insertion.
*/
std::vector<IStreamingReporterPtr> m_reporterLikes;
bool m_haveNoncapturingReporters = 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
Expand Down

0 comments on commit dceb260

Please sign in to comment.