mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
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.
This commit is contained in:
parent
6a08d401aa
commit
2a8e317cfb
@ -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
|
||||
|
75
src/catch2/reporters/catch_reporter_combined_tu.cpp
Normal file
75
src/catch2/reporters/catch_reporter_combined_tu.cpp
Normal file
@ -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
|
@ -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>
|
||||
|
@ -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>
|
||||
|
29
src/catch2/reporters/catch_reporter_helpers.hpp
Normal file
29
src/catch2/reporters/catch_reporter_helpers.hpp
Normal file
@ -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
|
@ -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>
|
||||
|
@ -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
|
||||
|
@ -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 );
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user