catch_reporter_listening.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #include "catch_reporter_listening.h"
  9. #include <cassert>
  10. namespace Catch {
  11. ListeningReporter::ListeningReporter() {
  12. // We will assume that listeners will always want all assertions
  13. m_preferences.shouldReportAllAssertions = true;
  14. }
  15. void ListeningReporter::addListener( IStreamingReporterPtr&& listener ) {
  16. m_listeners.push_back( std::move( listener ) );
  17. }
  18. void ListeningReporter::addReporter(IStreamingReporterPtr&& reporter) {
  19. assert(!m_reporter && "Listening reporter can wrap only 1 real reporter");
  20. m_reporter = std::move( reporter );
  21. m_preferences.shouldRedirectStdOut = m_reporter->getPreferences().shouldRedirectStdOut;
  22. }
  23. ReporterPreferences ListeningReporter::getPreferences() const {
  24. return m_preferences;
  25. }
  26. std::set<Verbosity> ListeningReporter::getSupportedVerbosities() {
  27. return std::set<Verbosity>{ };
  28. }
  29. void ListeningReporter::noMatchingTestCases( std::string const& spec ) {
  30. for ( auto const& listener : m_listeners ) {
  31. listener->noMatchingTestCases( spec );
  32. }
  33. m_reporter->noMatchingTestCases( spec );
  34. }
  35. void ListeningReporter::reportInvalidArguments(std::string const&arg){
  36. for ( auto const& listener : m_listeners ) {
  37. listener->reportInvalidArguments( arg );
  38. }
  39. m_reporter->reportInvalidArguments( arg );
  40. }
  41. #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
  42. void ListeningReporter::benchmarkPreparing( std::string const& name ) {
  43. for (auto const& listener : m_listeners) {
  44. listener->benchmarkPreparing(name);
  45. }
  46. m_reporter->benchmarkPreparing(name);
  47. }
  48. void ListeningReporter::benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) {
  49. for ( auto const& listener : m_listeners ) {
  50. listener->benchmarkStarting( benchmarkInfo );
  51. }
  52. m_reporter->benchmarkStarting( benchmarkInfo );
  53. }
  54. void ListeningReporter::benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) {
  55. for ( auto const& listener : m_listeners ) {
  56. listener->benchmarkEnded( benchmarkStats );
  57. }
  58. m_reporter->benchmarkEnded( benchmarkStats );
  59. }
  60. void ListeningReporter::benchmarkFailed( std::string const& error ) {
  61. for (auto const& listener : m_listeners) {
  62. listener->benchmarkFailed(error);
  63. }
  64. m_reporter->benchmarkFailed(error);
  65. }
  66. #endif // CATCH_CONFIG_ENABLE_BENCHMARKING
  67. void ListeningReporter::testRunStarting( TestRunInfo const& testRunInfo ) {
  68. for ( auto const& listener : m_listeners ) {
  69. listener->testRunStarting( testRunInfo );
  70. }
  71. m_reporter->testRunStarting( testRunInfo );
  72. }
  73. void ListeningReporter::testGroupStarting( GroupInfo const& groupInfo ) {
  74. for ( auto const& listener : m_listeners ) {
  75. listener->testGroupStarting( groupInfo );
  76. }
  77. m_reporter->testGroupStarting( groupInfo );
  78. }
  79. void ListeningReporter::testCaseStarting( TestCaseInfo const& testInfo ) {
  80. for ( auto const& listener : m_listeners ) {
  81. listener->testCaseStarting( testInfo );
  82. }
  83. m_reporter->testCaseStarting( testInfo );
  84. }
  85. void ListeningReporter::sectionStarting( SectionInfo const& sectionInfo ) {
  86. for ( auto const& listener : m_listeners ) {
  87. listener->sectionStarting( sectionInfo );
  88. }
  89. m_reporter->sectionStarting( sectionInfo );
  90. }
  91. void ListeningReporter::assertionStarting( AssertionInfo const& assertionInfo ) {
  92. for ( auto const& listener : m_listeners ) {
  93. listener->assertionStarting( assertionInfo );
  94. }
  95. m_reporter->assertionStarting( assertionInfo );
  96. }
  97. // The return value indicates if the messages buffer should be cleared:
  98. bool ListeningReporter::assertionEnded( AssertionStats const& assertionStats ) {
  99. for( auto const& listener : m_listeners ) {
  100. static_cast<void>( listener->assertionEnded( assertionStats ) );
  101. }
  102. return m_reporter->assertionEnded( assertionStats );
  103. }
  104. void ListeningReporter::sectionEnded( SectionStats const& sectionStats ) {
  105. for ( auto const& listener : m_listeners ) {
  106. listener->sectionEnded( sectionStats );
  107. }
  108. m_reporter->sectionEnded( sectionStats );
  109. }
  110. void ListeningReporter::testCaseEnded( TestCaseStats const& testCaseStats ) {
  111. for ( auto const& listener : m_listeners ) {
  112. listener->testCaseEnded( testCaseStats );
  113. }
  114. m_reporter->testCaseEnded( testCaseStats );
  115. }
  116. void ListeningReporter::testGroupEnded( TestGroupStats const& testGroupStats ) {
  117. for ( auto const& listener : m_listeners ) {
  118. listener->testGroupEnded( testGroupStats );
  119. }
  120. m_reporter->testGroupEnded( testGroupStats );
  121. }
  122. void ListeningReporter::testRunEnded( TestRunStats const& testRunStats ) {
  123. for ( auto const& listener : m_listeners ) {
  124. listener->testRunEnded( testRunStats );
  125. }
  126. m_reporter->testRunEnded( testRunStats );
  127. }
  128. void ListeningReporter::skipTest( TestCaseInfo const& testInfo ) {
  129. for ( auto const& listener : m_listeners ) {
  130. listener->skipTest( testInfo );
  131. }
  132. m_reporter->skipTest( testInfo );
  133. }
  134. bool ListeningReporter::isMulti() const {
  135. return true;
  136. }
  137. } // end namespace Catch