1 /* 2 * Created by Phil on 5/08/2015. 3 * Copyright 2015 Two Blue Cubes Ltd. All rights reserved. 4 * 5 * Distributed under the Boost Software License, Version 1.0. (See accompanying 6 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 */ 8 9 #include "catch_reporter_listening.h" 10 #include <cassert> 11 12 namespace Catch { 13 ListeningReporter()14 ListeningReporter::ListeningReporter() { 15 // We will assume that listeners will always want all assertions 16 m_preferences.shouldReportAllAssertions = true; 17 } 18 addListener(IStreamingReporterPtr && listener)19 void ListeningReporter::addListener( IStreamingReporterPtr&& listener ) { 20 m_listeners.push_back( std::move( listener ) ); 21 } 22 addReporter(IStreamingReporterPtr && reporter)23 void ListeningReporter::addReporter(IStreamingReporterPtr&& reporter) { 24 assert(!m_reporter && "Listening reporter can wrap only 1 real reporter"); 25 m_reporter = std::move( reporter ); 26 m_preferences.shouldRedirectStdOut = m_reporter->getPreferences().shouldRedirectStdOut; 27 } 28 getPreferences() const29 ReporterPreferences ListeningReporter::getPreferences() const { 30 return m_preferences; 31 } 32 getSupportedVerbosities()33 std::set<Verbosity> ListeningReporter::getSupportedVerbosities() { 34 return std::set<Verbosity>{ }; 35 } 36 37 noMatchingTestCases(std::string const & spec)38 void ListeningReporter::noMatchingTestCases( std::string const& spec ) { 39 for ( auto const& listener : m_listeners ) { 40 listener->noMatchingTestCases( spec ); 41 } 42 m_reporter->noMatchingTestCases( spec ); 43 } 44 reportInvalidArguments(std::string const & arg)45 void ListeningReporter::reportInvalidArguments(std::string const&arg){ 46 for ( auto const& listener : m_listeners ) { 47 listener->reportInvalidArguments( arg ); 48 } 49 m_reporter->reportInvalidArguments( arg ); 50 } 51 52 #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) benchmarkPreparing(std::string const & name)53 void ListeningReporter::benchmarkPreparing( std::string const& name ) { 54 for (auto const& listener : m_listeners) { 55 listener->benchmarkPreparing(name); 56 } 57 m_reporter->benchmarkPreparing(name); 58 } benchmarkStarting(BenchmarkInfo const & benchmarkInfo)59 void ListeningReporter::benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) { 60 for ( auto const& listener : m_listeners ) { 61 listener->benchmarkStarting( benchmarkInfo ); 62 } 63 m_reporter->benchmarkStarting( benchmarkInfo ); 64 } benchmarkEnded(BenchmarkStats<> const & benchmarkStats)65 void ListeningReporter::benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) { 66 for ( auto const& listener : m_listeners ) { 67 listener->benchmarkEnded( benchmarkStats ); 68 } 69 m_reporter->benchmarkEnded( benchmarkStats ); 70 } 71 benchmarkFailed(std::string const & error)72 void ListeningReporter::benchmarkFailed( std::string const& error ) { 73 for (auto const& listener : m_listeners) { 74 listener->benchmarkFailed(error); 75 } 76 m_reporter->benchmarkFailed(error); 77 } 78 #endif // CATCH_CONFIG_ENABLE_BENCHMARKING 79 testRunStarting(TestRunInfo const & testRunInfo)80 void ListeningReporter::testRunStarting( TestRunInfo const& testRunInfo ) { 81 for ( auto const& listener : m_listeners ) { 82 listener->testRunStarting( testRunInfo ); 83 } 84 m_reporter->testRunStarting( testRunInfo ); 85 } 86 testGroupStarting(GroupInfo const & groupInfo)87 void ListeningReporter::testGroupStarting( GroupInfo const& groupInfo ) { 88 for ( auto const& listener : m_listeners ) { 89 listener->testGroupStarting( groupInfo ); 90 } 91 m_reporter->testGroupStarting( groupInfo ); 92 } 93 94 testCaseStarting(TestCaseInfo const & testInfo)95 void ListeningReporter::testCaseStarting( TestCaseInfo const& testInfo ) { 96 for ( auto const& listener : m_listeners ) { 97 listener->testCaseStarting( testInfo ); 98 } 99 m_reporter->testCaseStarting( testInfo ); 100 } 101 sectionStarting(SectionInfo const & sectionInfo)102 void ListeningReporter::sectionStarting( SectionInfo const& sectionInfo ) { 103 for ( auto const& listener : m_listeners ) { 104 listener->sectionStarting( sectionInfo ); 105 } 106 m_reporter->sectionStarting( sectionInfo ); 107 } 108 assertionStarting(AssertionInfo const & assertionInfo)109 void ListeningReporter::assertionStarting( AssertionInfo const& assertionInfo ) { 110 for ( auto const& listener : m_listeners ) { 111 listener->assertionStarting( assertionInfo ); 112 } 113 m_reporter->assertionStarting( assertionInfo ); 114 } 115 116 // The return value indicates if the messages buffer should be cleared: assertionEnded(AssertionStats const & assertionStats)117 bool ListeningReporter::assertionEnded( AssertionStats const& assertionStats ) { 118 for( auto const& listener : m_listeners ) { 119 static_cast<void>( listener->assertionEnded( assertionStats ) ); 120 } 121 return m_reporter->assertionEnded( assertionStats ); 122 } 123 sectionEnded(SectionStats const & sectionStats)124 void ListeningReporter::sectionEnded( SectionStats const& sectionStats ) { 125 for ( auto const& listener : m_listeners ) { 126 listener->sectionEnded( sectionStats ); 127 } 128 m_reporter->sectionEnded( sectionStats ); 129 } 130 testCaseEnded(TestCaseStats const & testCaseStats)131 void ListeningReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { 132 for ( auto const& listener : m_listeners ) { 133 listener->testCaseEnded( testCaseStats ); 134 } 135 m_reporter->testCaseEnded( testCaseStats ); 136 } 137 testGroupEnded(TestGroupStats const & testGroupStats)138 void ListeningReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { 139 for ( auto const& listener : m_listeners ) { 140 listener->testGroupEnded( testGroupStats ); 141 } 142 m_reporter->testGroupEnded( testGroupStats ); 143 } 144 testRunEnded(TestRunStats const & testRunStats)145 void ListeningReporter::testRunEnded( TestRunStats const& testRunStats ) { 146 for ( auto const& listener : m_listeners ) { 147 listener->testRunEnded( testRunStats ); 148 } 149 m_reporter->testRunEnded( testRunStats ); 150 } 151 152 skipTest(TestCaseInfo const & testInfo)153 void ListeningReporter::skipTest( TestCaseInfo const& testInfo ) { 154 for ( auto const& listener : m_listeners ) { 155 listener->skipTest( testInfo ); 156 } 157 m_reporter->skipTest( testInfo ); 158 } 159 isMulti() const160 bool ListeningReporter::isMulti() const { 161 return true; 162 } 163 164 } // end namespace Catch