diff options
| author | Martin Hořeňovský | 2020-08-22 23:16:23 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-08-23 07:30:26 +0200 |
| commit | ed7eaf2df3dc4d38974234591d725c4cdba11a84 (patch) | |
| tree | 933416d7d9fdfdda442b911e345731d6b26a8b5b /src | |
| parent | 24559493bfa5ac5f120aacee7bd4a26c9c130863 (diff) | |
| download | catch3-ed7eaf2df3dc4d38974234591d725c4cdba11a84.tar.gz | |
Split catch_reporter_bases.hpp into two separate headers
Each of the two reporter bases now has its own header file, and
cpp file. Even though this adds another TU to the compilation,
the total CPU time taken by compilation is reduced by about 1%
for debug build and ~0.5% for optimized build of the main library.
(The improvement would be roughly doubles without splitting the TUs,
but the maintainability hit is not worth it.)
The code size of the static library build has also somewhat decreased.
Follow up: Introduce combined TU for reporters, and further split
apart the catch_reporter_streaming_base.hpp header into its
constituent parts, as it still contains a whole bunch of other stuff.
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_automake.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_bases.hpp | 169 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_compact.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_console.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_cumulative_base.cpp (renamed from src/catch2/reporters/catch_reporter_bases.cpp) | 95 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_cumulative_base.hpp | 82 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_junit.cpp | 3 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_junit.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_sonarqube.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_streaming_base.cpp | 99 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_streaming_base.hpp | 90 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_tap.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_teamcity.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_xml.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporters_all.hpp | 3 |
16 files changed, 287 insertions, 276 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 24b3b055..0bc0fc3d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -193,24 +193,26 @@ set(INTERNAL_FILES ${IMPL_SOURCES} ${INTERNAL_HEADERS}) set(REPORTER_HEADERS ${SOURCES_DIR}/reporters/catch_reporters_all.hpp ${SOURCES_DIR}/reporters/catch_reporter_automake.hpp - ${SOURCES_DIR}/reporters/catch_reporter_bases.hpp ${SOURCES_DIR}/reporters/catch_reporter_compact.hpp ${SOURCES_DIR}/reporters/catch_reporter_console.hpp + ${SOURCES_DIR}/reporters/catch_reporter_cumulative_base.hpp ${SOURCES_DIR}/reporters/catch_reporter_junit.hpp ${SOURCES_DIR}/reporters/catch_reporter_listening.hpp ${SOURCES_DIR}/reporters/catch_reporter_sonarqube.hpp + ${SOURCES_DIR}/reporters/catch_reporter_streaming_base.hpp ${SOURCES_DIR}/reporters/catch_reporter_tap.hpp ${SOURCES_DIR}/reporters/catch_reporter_teamcity.hpp ${SOURCES_DIR}/reporters/catch_reporter_xml.hpp ) set(REPORTER_SOURCES ${SOURCES_DIR}/reporters/catch_reporter_automake.cpp - ${SOURCES_DIR}/reporters/catch_reporter_bases.cpp ${SOURCES_DIR}/reporters/catch_reporter_compact.cpp ${SOURCES_DIR}/reporters/catch_reporter_console.cpp + ${SOURCES_DIR}/reporters/catch_reporter_cumulative_base.cpp ${SOURCES_DIR}/reporters/catch_reporter_junit.cpp ${SOURCES_DIR}/reporters/catch_reporter_listening.cpp ${SOURCES_DIR}/reporters/catch_reporter_sonarqube.cpp + ${SOURCES_DIR}/reporters/catch_reporter_streaming_base.cpp ${SOURCES_DIR}/reporters/catch_reporter_tap.cpp ${SOURCES_DIR}/reporters/catch_reporter_teamcity.cpp ${SOURCES_DIR}/reporters/catch_reporter_xml.cpp diff --git a/src/catch2/reporters/catch_reporter_automake.hpp b/src/catch2/reporters/catch_reporter_automake.hpp index 2d1066ed..5eec5218 100644 --- a/src/catch2/reporters/catch_reporter_automake.hpp +++ b/src/catch2/reporters/catch_reporter_automake.hpp @@ -5,7 +5,7 @@ #ifndef TWOBLUECUBES_CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED #define TWOBLUECUBES_CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED -#include <catch2/reporters/catch_reporter_bases.hpp> +#include <catch2/reporters/catch_reporter_streaming_base.hpp> namespace Catch { diff --git a/src/catch2/reporters/catch_reporter_bases.hpp b/src/catch2/reporters/catch_reporter_bases.hpp deleted file mode 100644 index 282394eb..00000000 --- a/src/catch2/reporters/catch_reporter_bases.hpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Created by Phil on 27/11/2013. - * Copyright 2013 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED -#define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED - -#include <catch2/interfaces/catch_interfaces_reporter.hpp> - -#include <iosfwd> -#include <memory> -#include <string> -#include <vector> - -namespace Catch { - // Returns double formatted as %.3f (format expected on output) - std::string getFormattedDuration( double duration ); - - //! Should the reporter show - bool shouldShowDuration( IConfig const& config, double duration ); - - std::string serializeFilters( std::vector<std::string> const& container ); - - struct StreamingReporterBase : IStreamingReporter { - - StreamingReporterBase( ReporterConfig const& _config ): - m_config( _config.fullConfig() ), stream( _config.stream() ) { - } - - - ~StreamingReporterBase() override; - - void noMatchingTestCases(std::string const&) override {} - - void reportInvalidArguments(std::string const&) override {} - - void testRunStarting(TestRunInfo const& _testRunInfo) override { - currentTestRunInfo = _testRunInfo; - } - - void testGroupStarting(GroupInfo const& _groupInfo) override { - currentGroupInfo = _groupInfo; - } - - void testCaseStarting(TestCaseInfo const& _testInfo) override { - currentTestCaseInfo = &_testInfo; - } - void sectionStarting(SectionInfo const& _sectionInfo) override { - m_sectionStack.push_back(_sectionInfo); - } - - void sectionEnded(SectionStats const& /* _sectionStats */) override { - m_sectionStack.pop_back(); - } - void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override { - currentTestCaseInfo = nullptr; - } - void testGroupEnded( TestGroupStats const& ) override; - void testRunEnded( TestRunStats const& /* _testRunStats */ ) override; - - void skipTest(TestCaseInfo const&) override { - // Don't do anything with this by default. - // It can optionally be overridden in the derived class. - } - - IConfig const* m_config; - std::ostream& stream; - - LazyStat<TestRunInfo> currentTestRunInfo; - LazyStat<GroupInfo> currentGroupInfo; - TestCaseInfo const* currentTestCaseInfo = nullptr; - - std::vector<SectionInfo> m_sectionStack; - }; - - struct CumulativeReporterBase : IStreamingReporter { - template<typename T, typename ChildNodeT> - struct Node { - explicit Node( T const& _value ) : value( _value ) {} - virtual ~Node() {} - - using ChildNodes = std::vector<std::shared_ptr<ChildNodeT>>; - T value; - ChildNodes children; - }; - struct SectionNode { - explicit SectionNode(SectionStats const& _stats) : stats(_stats) {} - - bool operator == (SectionNode const& other) const { - return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; - } - - SectionStats stats; - using ChildSections = std::vector<std::shared_ptr<SectionNode>>; - using Assertions = std::vector<AssertionStats>; - ChildSections childSections; - Assertions assertions; - std::string stdOut; - std::string stdErr; - }; - - - using TestCaseNode = Node<TestCaseStats, SectionNode>; - using TestGroupNode = Node<TestGroupStats, TestCaseNode>; - using TestRunNode = Node<TestRunStats, TestGroupNode>; - - CumulativeReporterBase( ReporterConfig const& _config ): - m_config( _config.fullConfig() ), stream( _config.stream() ) {} - ~CumulativeReporterBase() override; - - void testRunStarting( TestRunInfo const& ) override {} - void testGroupStarting( GroupInfo const& ) override {} - - void testCaseStarting( TestCaseInfo const& ) override {} - - void sectionStarting( SectionInfo const& sectionInfo ) override; - - void assertionStarting( AssertionInfo const& ) override {} - - bool assertionEnded( AssertionStats const& assertionStats ) override; - void sectionEnded( SectionStats const& sectionStats ) override; - void testCaseEnded( TestCaseStats const& testCaseStats ) override; - void testGroupEnded( TestGroupStats const& testGroupStats ) override; - void testRunEnded( TestRunStats const& testRunStats ) override; - virtual void testRunEndedCumulative() = 0; - - void skipTest(TestCaseInfo const&) override {} - - IConfig const* m_config; - std::ostream& stream; - std::vector<AssertionStats> m_assertions; - std::vector<std::vector<std::shared_ptr<SectionNode>>> m_sections; - std::vector<std::shared_ptr<TestCaseNode>> m_testCases; - std::vector<std::shared_ptr<TestGroupNode>> m_testGroups; - - std::vector<std::shared_ptr<TestRunNode>> m_testRuns; - - std::shared_ptr<SectionNode> m_rootSection; - std::shared_ptr<SectionNode> m_deepestSection; - std::vector<std::shared_ptr<SectionNode>> m_sectionStack; - }; - - struct lineOfChars { - char c; - constexpr lineOfChars(char c): - c(c) - {} - - friend std::ostream& operator<< (std::ostream& out, lineOfChars value); - }; - - struct TestEventListenerBase : StreamingReporterBase { - TestEventListenerBase( ReporterConfig const& _config ); - - void assertionStarting(AssertionInfo const&) override; - bool assertionEnded(AssertionStats const&) override; - - // Event listeners should not use the default listing impl - void listReporters(std::vector<ReporterDescription> const&, IConfig const&) override {} - void listTests(std::vector<TestCaseHandle> const&, IConfig const&) override {} - void listTags(std::vector<TagInfo> const&, IConfig const&) override {} - }; - -} // end namespace Catch - -#endif // TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED
\ No newline at end of file diff --git a/src/catch2/reporters/catch_reporter_compact.hpp b/src/catch2/reporters/catch_reporter_compact.hpp index 7c814c09..aaf974ce 100644 --- a/src/catch2/reporters/catch_reporter_compact.hpp +++ b/src/catch2/reporters/catch_reporter_compact.hpp @@ -9,7 +9,7 @@ #define TWOBLUECUBES_CATCH_REPORTER_COMPACT_H_INCLUDED -#include <catch2/reporters/catch_reporter_bases.hpp> +#include <catch2/reporters/catch_reporter_streaming_base.hpp> namespace Catch { diff --git a/src/catch2/reporters/catch_reporter_console.hpp b/src/catch2/reporters/catch_reporter_console.hpp index 56c7231a..908fd126 100644 --- a/src/catch2/reporters/catch_reporter_console.hpp +++ b/src/catch2/reporters/catch_reporter_console.hpp @@ -8,7 +8,7 @@ #ifndef TWOBLUECUBES_CATCH_REPORTER_CONSOLE_H_INCLUDED #define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_H_INCLUDED -#include <catch2/reporters/catch_reporter_bases.hpp> +#include <catch2/reporters/catch_reporter_streaming_base.hpp> #include <catch2/internal/catch_unique_ptr.hpp> #if defined(_MSC_VER) diff --git a/src/catch2/reporters/catch_reporter_bases.cpp b/src/catch2/reporters/catch_reporter_cumulative_base.cpp index 08aff91a..ae974e89 100644 --- a/src/catch2/reporters/catch_reporter_bases.cpp +++ b/src/catch2/reporters/catch_reporter_cumulative_base.cpp @@ -1,23 +1,6 @@ -/* - * Created by Phil on 27/11/2013. - * Copyright 2013 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ - -#include <catch2/interfaces/catch_interfaces_reporter.hpp> -#include <catch2/internal/catch_console_width.hpp> -#include <catch2/internal/catch_errno_guard.hpp> -#include <catch2/reporters/catch_reporter_bases.hpp> -#include <catch2/internal/catch_stream.hpp> -#include <catch2/interfaces/catch_interfaces_config.hpp> +#include <catch2/reporters/catch_reporter_cumulative_base.hpp> #include <algorithm> -#include <cstring> -#include <cfloat> -#include <cstdio> -#include <ostream> #include <cassert> namespace Catch { @@ -44,74 +27,6 @@ namespace Catch { } } // namespace - // Because formatting using c++ streams is stateful, drop down to C is required - // Alternatively we could use stringstream, but its performance is... not good. - std::string getFormattedDuration( double duration ) { - // Max exponent + 1 is required to represent the whole part - // + 1 for decimal point - // + 3 for the 3 decimal places - // + 1 for null terminator - const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; - char buffer[maxDoubleSize]; - - // Save previous errno, to prevent sprintf from overwriting it - ErrnoGuard guard; -#ifdef _MSC_VER - sprintf_s(buffer, "%.3f", duration); -#else - std::sprintf(buffer, "%.3f", duration); -#endif - return std::string(buffer); - } - - bool shouldShowDuration( IConfig const& config, double duration ) { - if ( config.showDurations() == ShowDurations::Always ) { - return true; - } - if ( config.showDurations() == ShowDurations::Never ) { - return false; - } - const double min = config.minDuration(); - return min >= 0 && duration >= min; - } - - std::string serializeFilters( std::vector<std::string> const& container ) { - ReusableStringStream oss; - bool first = true; - for (auto&& filter : container) - { - if (!first) - oss << ' '; - else - first = false; - - oss << filter; - } - return oss.str(); - } - - TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config) - :StreamingReporterBase(_config) {} - - void TestEventListenerBase::assertionStarting(AssertionInfo const &) {} - - bool TestEventListenerBase::assertionEnded(AssertionStats const &) { - return false; - } - - - StreamingReporterBase::~StreamingReporterBase() = default; - - void StreamingReporterBase::testGroupEnded( TestGroupStats const& ) { - currentGroupInfo.reset(); - } - - void StreamingReporterBase::testRunEnded( TestRunStats const& ) { - currentTestCaseInfo = nullptr; - currentGroupInfo.reset(); - currentTestRunInfo.reset(); - } - CumulativeReporterBase::~CumulativeReporterBase() = default; @@ -189,12 +104,4 @@ namespace Catch { testRunEndedCumulative(); } - - std::ostream& operator<<(std::ostream& out, lineOfChars value) { - for (size_t idx = 0; idx < CATCH_CONFIG_CONSOLE_WIDTH - 1; ++idx) { - out.put(value.c); - } - return out; - } - } // end namespace Catch diff --git a/src/catch2/reporters/catch_reporter_cumulative_base.hpp b/src/catch2/reporters/catch_reporter_cumulative_base.hpp new file mode 100644 index 00000000..6aa055be --- /dev/null +++ b/src/catch2/reporters/catch_reporter_cumulative_base.hpp @@ -0,0 +1,82 @@ +#ifndef CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED +#define CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED + +#include <catch2/interfaces/catch_interfaces_reporter.hpp> + +#include <iosfwd> +#include <memory> +#include <string> +#include <vector> + +namespace Catch { + + struct CumulativeReporterBase : IStreamingReporter { + template<typename T, typename ChildNodeT> + struct Node { + explicit Node( T const& _value ) : value( _value ) {} + virtual ~Node() {} + + using ChildNodes = std::vector<std::shared_ptr<ChildNodeT>>; + T value; + ChildNodes children; + }; + struct SectionNode { + explicit SectionNode(SectionStats const& _stats) : stats(_stats) {} + + bool operator == (SectionNode const& other) const { + return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; + } + + SectionStats stats; + using ChildSections = std::vector<std::shared_ptr<SectionNode>>; + using Assertions = std::vector<AssertionStats>; + ChildSections childSections; + Assertions assertions; + std::string stdOut; + std::string stdErr; + }; + + + using TestCaseNode = Node<TestCaseStats, SectionNode>; + using TestGroupNode = Node<TestGroupStats, TestCaseNode>; + using TestRunNode = Node<TestRunStats, TestGroupNode>; + + CumulativeReporterBase( ReporterConfig const& _config ): + m_config( _config.fullConfig() ), stream( _config.stream() ) {} + ~CumulativeReporterBase() override; + + void testRunStarting( TestRunInfo const& ) override {} + void testGroupStarting( GroupInfo const& ) override {} + + void testCaseStarting( TestCaseInfo const& ) override {} + + void sectionStarting( SectionInfo const& sectionInfo ) override; + + void assertionStarting( AssertionInfo const& ) override {} + + bool assertionEnded( AssertionStats const& assertionStats ) override; + void sectionEnded( SectionStats const& sectionStats ) override; + void testCaseEnded( TestCaseStats const& testCaseStats ) override; + void testGroupEnded( TestGroupStats const& testGroupStats ) override; + void testRunEnded( TestRunStats const& testRunStats ) override; + virtual void testRunEndedCumulative() = 0; + + void skipTest(TestCaseInfo const&) override {} + + IConfig const* m_config; + std::ostream& stream; + std::vector<AssertionStats> m_assertions; + std::vector<std::vector<std::shared_ptr<SectionNode>>> m_sections; + std::vector<std::shared_ptr<TestCaseNode>> m_testCases; + std::vector<std::shared_ptr<TestGroupNode>> m_testGroups; + + std::vector<std::shared_ptr<TestRunNode>> m_testRuns; + + std::shared_ptr<SectionNode> m_rootSection; + std::shared_ptr<SectionNode> m_deepestSection; + std::vector<std::shared_ptr<SectionNode>> m_sectionStack; + }; + +} // end namespace Catch + +#endif // CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED diff --git a/src/catch2/reporters/catch_reporter_junit.cpp b/src/catch2/reporters/catch_reporter_junit.cpp index ff679e71..78ae1d92 100644 --- a/src/catch2/reporters/catch_reporter_junit.cpp +++ b/src/catch2/reporters/catch_reporter_junit.cpp @@ -6,10 +6,9 @@ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ -#include <catch2/reporters/catch_reporter_bases.hpp> - #include <catch2/reporters/catch_reporter_junit.hpp> +#include <catch2/reporters/catch_reporter_streaming_base.hpp> #include <catch2/catch_tostring.hpp> #include <catch2/internal/catch_string_manip.hpp> #include <catch2/internal/catch_textflow.hpp> diff --git a/src/catch2/reporters/catch_reporter_junit.hpp b/src/catch2/reporters/catch_reporter_junit.hpp index 3a75570a..ab80f368 100644 --- a/src/catch2/reporters/catch_reporter_junit.hpp +++ b/src/catch2/reporters/catch_reporter_junit.hpp @@ -8,7 +8,7 @@ #define TWOBLUECUBES_CATCH_REPORTER_JUNIT_H_INCLUDED -#include <catch2/reporters/catch_reporter_bases.hpp> +#include <catch2/reporters/catch_reporter_cumulative_base.hpp> #include <catch2/internal/catch_xmlwriter.hpp> #include <catch2/catch_timer.hpp> diff --git a/src/catch2/reporters/catch_reporter_sonarqube.hpp b/src/catch2/reporters/catch_reporter_sonarqube.hpp index a5f174f1..ea84f6f9 100644 --- a/src/catch2/reporters/catch_reporter_sonarqube.hpp +++ b/src/catch2/reporters/catch_reporter_sonarqube.hpp @@ -5,7 +5,7 @@ #ifndef CATCH_REPORTER_SONARQUBE_HPP_INCLUDED #define CATCH_REPORTER_SONARQUBE_HPP_INCLUDED -#include <catch2/reporters/catch_reporter_bases.hpp> +#include <catch2/reporters/catch_reporter_cumulative_base.hpp> #include <catch2/internal/catch_xmlwriter.hpp> diff --git a/src/catch2/reporters/catch_reporter_streaming_base.cpp b/src/catch2/reporters/catch_reporter_streaming_base.cpp new file mode 100644 index 00000000..6d84c096 --- /dev/null +++ b/src/catch2/reporters/catch_reporter_streaming_base.cpp @@ -0,0 +1,99 @@ +#include <catch2/reporters/catch_reporter_streaming_base.hpp> + +#include <catch2/internal/catch_console_width.hpp> +#include <catch2/internal/catch_errno_guard.hpp> +#include <catch2/internal/catch_stream.hpp> +#include <catch2/interfaces/catch_interfaces_config.hpp> + +#include <cfloat> +#include <cstdio> +#include <ostream> + +namespace Catch { + + // Because formatting using c++ streams is stateful, drop down to C is + // required Alternatively we could use stringstream, but its performance + // is... not good. + std::string getFormattedDuration( double duration ) { + // Max exponent + 1 is required to represent the whole part + // + 1 for decimal point + // + 3 for the 3 decimal places + // + 1 for null terminator + const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; + char buffer[maxDoubleSize]; + + // Save previous errno, to prevent sprintf from overwriting it + ErrnoGuard guard; +#ifdef _MSC_VER + sprintf_s( buffer, "%.3f", duration ); +#else + std::sprintf( buffer, "%.3f", duration ); +#endif + return std::string( buffer ); + } + + bool shouldShowDuration( IConfig const& config, double duration ) { + if ( config.showDurations() == ShowDurations::Always ) { + return true; + } + if ( config.showDurations() == ShowDurations::Never ) { + return false; + } + const double min = config.minDuration(); + return min >= 0 && duration >= min; + } + + std::string serializeFilters( std::vector<std::string> const& container ) { + ReusableStringStream oss; + bool first = true; + for ( auto&& filter : container ) { + if ( !first ) + oss << ' '; + else + first = false; + + oss << filter; + } + return oss.str(); + } + + TestEventListenerBase::TestEventListenerBase( + ReporterConfig const& _config ): + StreamingReporterBase( _config ) {} + + void TestEventListenerBase::assertionStarting( AssertionInfo const& ) {} + + bool TestEventListenerBase::assertionEnded( AssertionStats const& ) { + return false; + } + + StreamingReporterBase::~StreamingReporterBase() = default; + + void + StreamingReporterBase::testRunStarting( TestRunInfo const& _testRunInfo ) { + currentTestRunInfo = _testRunInfo; + } + + void + StreamingReporterBase::testGroupStarting( GroupInfo const& _groupInfo ) { + currentGroupInfo = _groupInfo; + } + + void StreamingReporterBase::testGroupEnded( TestGroupStats const& ) { + currentGroupInfo.reset(); + } + + void StreamingReporterBase::testRunEnded( TestRunStats const& ) { + currentTestCaseInfo = nullptr; + currentGroupInfo.reset(); + currentTestRunInfo.reset(); + } + + std::ostream& operator<<( std::ostream& out, lineOfChars value ) { + for ( size_t idx = 0; idx < CATCH_CONFIG_CONSOLE_WIDTH - 1; ++idx ) { + out.put( value.c ); + } + return out; + } + +} // end namespace Catch diff --git a/src/catch2/reporters/catch_reporter_streaming_base.hpp b/src/catch2/reporters/catch_reporter_streaming_base.hpp new file mode 100644 index 00000000..0d1cbd38 --- /dev/null +++ b/src/catch2/reporters/catch_reporter_streaming_base.hpp @@ -0,0 +1,90 @@ +#ifndef CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED +#define CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED + +#include <catch2/interfaces/catch_interfaces_reporter.hpp> + +#include <iosfwd> +#include <string> +#include <vector> + +namespace Catch { + // Returns double formatted as %.3f (format expected on output) + std::string getFormattedDuration( double duration ); + + //! Should the reporter show + bool shouldShowDuration( IConfig const& config, double duration ); + + std::string serializeFilters( std::vector<std::string> const& container ); + + struct StreamingReporterBase : IStreamingReporter { + + StreamingReporterBase( ReporterConfig const& _config ): + m_config( _config.fullConfig() ), stream( _config.stream() ) { + } + + + ~StreamingReporterBase() override; + + void noMatchingTestCases(std::string const&) override {} + + void reportInvalidArguments(std::string const&) override {} + + void testRunStarting( TestRunInfo const& _testRunInfo ) override; + + void testGroupStarting( GroupInfo const& _groupInfo ) override; + + void testCaseStarting(TestCaseInfo const& _testInfo) override { + currentTestCaseInfo = &_testInfo; + } + void sectionStarting(SectionInfo const& _sectionInfo) override { + m_sectionStack.push_back(_sectionInfo); + } + + void sectionEnded(SectionStats const& /* _sectionStats */) override { + m_sectionStack.pop_back(); + } + void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override { + currentTestCaseInfo = nullptr; + } + void testGroupEnded( TestGroupStats const& ) override; + void testRunEnded( TestRunStats const& /* _testRunStats */ ) override; + + void skipTest(TestCaseInfo const&) override { + // Don't do anything with this by default. + // It can optionally be overridden in the derived class. + } + + IConfig const* m_config; + std::ostream& stream; + + LazyStat<TestRunInfo> currentTestRunInfo; + LazyStat<GroupInfo> currentGroupInfo; + TestCaseInfo const* currentTestCaseInfo = nullptr; + + std::vector<SectionInfo> m_sectionStack; + }; + + struct lineOfChars { + char c; + constexpr lineOfChars(char c): + c(c) + {} + + friend std::ostream& operator<< (std::ostream& out, lineOfChars value); + }; + + struct TestEventListenerBase : StreamingReporterBase { + TestEventListenerBase( ReporterConfig const& _config ); + + void assertionStarting(AssertionInfo const&) override; + bool assertionEnded(AssertionStats const&) override; + + // Event listeners should not use the default listing impl + void listReporters(std::vector<ReporterDescription> const&, IConfig const&) override {} + void listTests(std::vector<TestCaseHandle> const&, IConfig const&) override {} + void listTags(std::vector<TagInfo> const&, IConfig const&) override {} + }; + +} // end namespace Catch + +#endif // CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED diff --git a/src/catch2/reporters/catch_reporter_tap.hpp b/src/catch2/reporters/catch_reporter_tap.hpp index 63042481..7c3365dc 100644 --- a/src/catch2/reporters/catch_reporter_tap.hpp +++ b/src/catch2/reporters/catch_reporter_tap.hpp @@ -5,7 +5,7 @@ #ifndef TWOBLUECUBES_CATCH_REPORTER_TAP_HPP_INCLUDED #define TWOBLUECUBES_CATCH_REPORTER_TAP_HPP_INCLUDED -#include <catch2/reporters/catch_reporter_bases.hpp> +#include <catch2/reporters/catch_reporter_streaming_base.hpp> namespace Catch { diff --git a/src/catch2/reporters/catch_reporter_teamcity.hpp b/src/catch2/reporters/catch_reporter_teamcity.hpp index a1d6e2fe..69e2c31e 100644 --- a/src/catch2/reporters/catch_reporter_teamcity.hpp +++ b/src/catch2/reporters/catch_reporter_teamcity.hpp @@ -5,8 +5,8 @@ #ifndef TWOBLUECUBES_CATCH_REPORTER_TEAMCITY_HPP_INCLUDED #define TWOBLUECUBES_CATCH_REPORTER_TEAMCITY_HPP_INCLUDED +#include <catch2/reporters/catch_reporter_streaming_base.hpp> #include <catch2/catch_timer.hpp> -#include <catch2/reporters/catch_reporter_bases.hpp> #include <cstring> diff --git a/src/catch2/reporters/catch_reporter_xml.hpp b/src/catch2/reporters/catch_reporter_xml.hpp index 30cc57dd..9a225126 100644 --- a/src/catch2/reporters/catch_reporter_xml.hpp +++ b/src/catch2/reporters/catch_reporter_xml.hpp |