From 2a8e317cfbe92f9c108960d8d33e6cefe2c40c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sun, 23 Aug 2020 22:43:56 +0200 Subject: [PATCH] Split various reporter helpers out from streaming_base.hpp Due to also adding a new TU, there is no improvement to the compilation times of the static library, but it improves the compilation times of consumer's reporter TUs. --- src/CMakeLists.txt | 2 + .../reporters/catch_reporter_combined_tu.cpp | 75 +++++++++++++++++++ .../reporters/catch_reporter_compact.cpp | 1 + .../reporters/catch_reporter_console.cpp | 1 + .../reporters/catch_reporter_helpers.hpp | 29 +++++++ src/catch2/reporters/catch_reporter_junit.cpp | 2 +- .../catch_reporter_streaming_base.cpp | 62 --------------- .../catch_reporter_streaming_base.hpp | 18 +---- .../reporters/catch_reporter_teamcity.cpp | 1 + src/catch2/reporters/catch_reporter_xml.cpp | 1 + src/catch2/reporters/catch_reporters_all.hpp | 1 + 11 files changed, 113 insertions(+), 80 deletions(-) create mode 100644 src/catch2/reporters/catch_reporter_combined_tu.cpp create mode 100644 src/catch2/reporters/catch_reporter_helpers.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 730b5c52..a56d2989 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -198,6 +198,7 @@ set(REPORTER_HEADERS ${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_helpers.hpp ${SOURCES_DIR}/reporters/catch_reporter_junit.hpp ${SOURCES_DIR}/reporters/catch_reporter_listening.hpp ${SOURCES_DIR}/reporters/catch_reporter_sonarqube.hpp @@ -208,6 +209,7 @@ set(REPORTER_HEADERS ) set(REPORTER_SOURCES ${SOURCES_DIR}/reporters/catch_reporter_automake.cpp + ${SOURCES_DIR}/reporters/catch_reporter_combined_tu.cpp ${SOURCES_DIR}/reporters/catch_reporter_compact.cpp ${SOURCES_DIR}/reporters/catch_reporter_console.cpp ${SOURCES_DIR}/reporters/catch_reporter_cumulative_base.cpp diff --git a/src/catch2/reporters/catch_reporter_combined_tu.cpp b/src/catch2/reporters/catch_reporter_combined_tu.cpp new file mode 100644 index 00000000..f6a650eb --- /dev/null +++ b/src/catch2/reporters/catch_reporter_combined_tu.cpp @@ -0,0 +1,75 @@ +/** \file + * This is a special TU that combines what would otherwise be a very + * small reporter-related TUs into one bigger TU. + * + * The reason for this is compilation performance improvements by + * avoiding reparsing headers for many small TUs, instead having this + * one TU include bit more, but having it all parsed only once. + * + * To avoid heavy-tail problem with compilation times, each "subpart" + * of Catch2 has its own combined TU like this. + */ + +#include +#include +#include +#include +#include +#include +#include + +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 const& container ) { + ReusableStringStream oss; + bool first = true; + for ( auto&& filter : container ) { + if ( !first ) + oss << ' '; + else + first = false; + + oss << filter; + } + return oss.str(); + } + + 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; + } +} // namespace Catch diff --git a/src/catch2/reporters/catch_reporter_compact.cpp b/src/catch2/reporters/catch_reporter_compact.cpp index 36f4f8b0..b3db9bb9 100644 --- a/src/catch2/reporters/catch_reporter_compact.cpp +++ b/src/catch2/reporters/catch_reporter_compact.cpp @@ -7,6 +7,7 @@ #include +#include #include #include #include diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp index 8bf57fef..b6eb83e7 100644 --- a/src/catch2/reporters/catch_reporter_console.cpp +++ b/src/catch2/reporters/catch_reporter_console.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/src/catch2/reporters/catch_reporter_helpers.hpp b/src/catch2/reporters/catch_reporter_helpers.hpp new file mode 100644 index 00000000..96fd51d3 --- /dev/null +++ b/src/catch2/reporters/catch_reporter_helpers.hpp @@ -0,0 +1,29 @@ +#ifndef CATCH_REPORTER_HELPERS_HPP_INCLUDED +#define CATCH_REPORTER_HELPERS_HPP_INCLUDED + +#include +#include +#include + +namespace Catch { + + struct IConfig; + + // 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 const& container ); + + struct lineOfChars { + char c; + constexpr lineOfChars( char c ): c( c ) {} + + friend std::ostream& operator<<( std::ostream& out, lineOfChars value ); + }; + +} // end namespace Catch + +#endif // CATCH_REPORTER_HELPERS_HPP_INCLUDED diff --git a/src/catch2/reporters/catch_reporter_junit.cpp b/src/catch2/reporters/catch_reporter_junit.cpp index 78ae1d92..b56f2e45 100644 --- a/src/catch2/reporters/catch_reporter_junit.cpp +++ b/src/catch2/reporters/catch_reporter_junit.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include #include #include diff --git a/src/catch2/reporters/catch_reporter_streaming_base.cpp b/src/catch2/reporters/catch_reporter_streaming_base.cpp index 6d84c096..73c63746 100644 --- a/src/catch2/reporters/catch_reporter_streaming_base.cpp +++ b/src/catch2/reporters/catch_reporter_streaming_base.cpp @@ -1,62 +1,7 @@ #include -#include -#include -#include -#include - -#include -#include -#include - 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 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 ) {} @@ -89,11 +34,4 @@ namespace Catch { 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 index 0d1cbd38..30902ba1 100644 --- a/src/catch2/reporters/catch_reporter_streaming_base.hpp +++ b/src/catch2/reporters/catch_reporter_streaming_base.hpp @@ -8,14 +8,7 @@ #include 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 const& container ); - + struct StreamingReporterBase : IStreamingReporter { StreamingReporterBase( ReporterConfig const& _config ): @@ -64,15 +57,6 @@ namespace Catch { std::vector 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 ); diff --git a/src/catch2/reporters/catch_reporter_teamcity.cpp b/src/catch2/reporters/catch_reporter_teamcity.cpp index dd60cf9e..57fd586c 100644 --- a/src/catch2/reporters/catch_reporter_teamcity.cpp +++ b/src/catch2/reporters/catch_reporter_teamcity.cpp @@ -5,6 +5,7 @@ #include +#include #include #include #include diff --git a/src/catch2/reporters/catch_reporter_xml.cpp b/src/catch2/reporters/catch_reporter_xml.cpp index a576bbec..8f0ec720 100644 --- a/src/catch2/reporters/catch_reporter_xml.cpp +++ b/src/catch2/reporters/catch_reporter_xml.cpp @@ -8,6 +8,7 @@ #include +#include #include #include #include diff --git a/src/catch2/reporters/catch_reporters_all.hpp b/src/catch2/reporters/catch_reporters_all.hpp index aa46c699..5531427b 100644 --- a/src/catch2/reporters/catch_reporters_all.hpp +++ b/src/catch2/reporters/catch_reporters_all.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include