Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2020-08-23 22:43:56 +0200
committerMartin Hořeňovský2020-08-24 10:19:24 +0200
commit2a8e317cfbe92f9c108960d8d33e6cefe2c40c69 (patch)
tree5a70366fc685bc9e105fb788d8196ecd2ab19c0e
parent6a08d401aabac2ead19c3eff17647a2b482f96b0 (diff)
downloadcatch3-2a8e317cfbe92f9c108960d8d33e6cefe2c40c69.tar.gz
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.
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/catch2/reporters/catch_reporter_combined_tu.cpp75
-rw-r--r--src/catch2/reporters/catch_reporter_compact.cpp1
-rw-r--r--src/catch2/reporters/catch_reporter_console.cpp1
-rw-r--r--src/catch2/reporters/catch_reporter_helpers.hpp29
-rw-r--r--src/catch2/reporters/catch_reporter_junit.cpp2
-rw-r--r--src/catch2/reporters/catch_reporter_streaming_base.cpp62
-rw-r--r--src/catch2/reporters/catch_reporter_streaming_base.hpp18
-rw-r--r--src/catch2/reporters/catch_reporter_teamcity.cpp1
-rw-r--r--src/catch2/reporters/catch_reporter_xml.cpp1
-rw-r--r--src/catch2/reporters/catch_reporters_all.hpp1
11 files changed, 113 insertions, 80 deletions
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 <catch2/interfaces/catch_interfaces_config.hpp>
+#include <catch2/internal/catch_console_width.hpp>
+#include <catch2/internal/catch_errno_guard.hpp>
+#include <catch2/internal/catch_stream.hpp>
+#include <catch2/reporters/catch_reporter_helpers.hpp>
+#include <cfloat>
+#include <cstdio>
+
+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();
+ }
+
+ 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 <catch2/reporters/catch_reporter_compact.hpp>
+#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <catch2/interfaces/catch_interfaces_config.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_console_colour.hpp>
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 <catch2/internal/catch_stringref.hpp>
#include <catch2/catch_test_case_info.hpp>
#include <catch2/internal/catch_console_width.hpp>
+#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <cfloat>
#include <cstdio>
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 <iosfwd>
+#include <string>
+#include <vector>
+
+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<std::string> 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 <catch2/reporters/catch_reporter_junit.hpp>
-#include <catch2/reporters/catch_reporter_streaming_base.hpp>
+#include <catch2/reporters/catch_reporter_helpers.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_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 <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 ) {}
@@ -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 <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 ):
@@ -64,15 +57,6 @@ namespace Catch {
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 );
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 <catch2/reporters/catch_reporter_teamcity.hpp>
+#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <catch2/internal/catch_string_manip.hpp>
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_textflow.hpp>
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 <catch2/reporters/catch_reporter_xml.hpp>
+#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <catch2/interfaces/catch_interfaces_config.hpp>
#include <catch2/catch_test_spec.hpp>
#include <catch2/internal/catch_string_manip.hpp>
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 <catch2/reporters/catch_reporter_compact.hpp>
#include <catch2/reporters/catch_reporter_console.hpp>
#include <catch2/reporters/catch_reporter_cumulative_base.hpp>
+#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <catch2/reporters/catch_reporter_junit.hpp>
#include <catch2/reporters/catch_reporter_listening.hpp>
#include <catch2/reporters/catch_reporter_sonarqube.hpp>