mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-22 11:23:29 +01:00
Cleanup internal includes by splitting out some event structs
* Split out BenchmarkInfo and BenchmarkStats to their own header * Outline BenchmarkStats<> declaration to separate header * Split out TestRunInfo into its own header These changes let us remove the large `interfaces_reporter.hpp` include from `benchmark.hpp`, and replace it with `interfaces_capture.hpp` in `run_context.hpp`. I also cleaned out `interfaces_repoter.hpp` from reporter headers that depend on `reporter_common_base.hpp`. This will not change anything in the actual inclusion set, but makes it logically more consistent.
This commit is contained in:
parent
1f881ab464
commit
9f08097f55
@ -21,6 +21,8 @@ set(BENCHMARK_HEADERS
|
||||
${SOURCES_DIR}/benchmark/catch_sample_analysis.hpp
|
||||
${SOURCES_DIR}/benchmark/detail/catch_analyse.hpp
|
||||
${SOURCES_DIR}/benchmark/detail/catch_benchmark_function.hpp
|
||||
${SOURCES_DIR}/benchmark/detail/catch_benchmark_stats.hpp
|
||||
${SOURCES_DIR}/benchmark/detail/catch_benchmark_stats_fwd.hpp
|
||||
${SOURCES_DIR}/benchmark/detail/catch_complete_invoke.hpp
|
||||
${SOURCES_DIR}/benchmark/detail/catch_estimate_clock.hpp
|
||||
${SOURCES_DIR}/benchmark/detail/catch_measure.hpp
|
||||
@ -128,6 +130,7 @@ set(IMPL_HEADERS
|
||||
${SOURCES_DIR}/internal/catch_test_failure_exception.hpp
|
||||
${SOURCES_DIR}/internal/catch_test_macro_impl.hpp
|
||||
${SOURCES_DIR}/internal/catch_test_registry.hpp
|
||||
${SOURCES_DIR}/internal/catch_test_run_info.hpp
|
||||
${SOURCES_DIR}/internal/catch_test_spec_parser.hpp
|
||||
${SOURCES_DIR}/internal/catch_textflow.hpp
|
||||
${SOURCES_DIR}/internal/catch_to_string.hpp
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_config.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
||||
#include <catch2/benchmark/detail/catch_benchmark_stats.hpp>
|
||||
#include <catch2/benchmark/catch_clock.hpp>
|
||||
#include <catch2/benchmark/catch_environment.hpp>
|
||||
#include <catch2/benchmark/catch_execution_plan.hpp>
|
||||
|
@ -33,6 +33,8 @@
|
||||
#include <catch2/benchmark/catch_sample_analysis.hpp>
|
||||
#include <catch2/benchmark/detail/catch_analyse.hpp>
|
||||
#include <catch2/benchmark/detail/catch_benchmark_function.hpp>
|
||||
#include <catch2/benchmark/detail/catch_benchmark_stats.hpp>
|
||||
#include <catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp>
|
||||
#include <catch2/benchmark/detail/catch_complete_invoke.hpp>
|
||||
#include <catch2/benchmark/detail/catch_estimate_clock.hpp>
|
||||
#include <catch2/benchmark/detail/catch_measure.hpp>
|
||||
|
64
src/catch2/benchmark/detail/catch_benchmark_stats.hpp
Normal file
64
src/catch2/benchmark/detail/catch_benchmark_stats.hpp
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
#ifndef CATCH_BENCHMARK_STATS_HPP_INCLUDED
|
||||
#define CATCH_BENCHMARK_STATS_HPP_INCLUDED
|
||||
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
#include <catch2/benchmark/catch_estimate.hpp>
|
||||
#include <catch2/benchmark/catch_outlier_classification.hpp>
|
||||
// The fwd decl & default specialization needs to be seen by VS2017 before
|
||||
// BenchmarkStats itself, or VS2017 will report compilation error.
|
||||
#include <catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct BenchmarkInfo {
|
||||
std::string name;
|
||||
double estimatedDuration;
|
||||
int iterations;
|
||||
unsigned int samples;
|
||||
unsigned int resamples;
|
||||
double clockResolution;
|
||||
double clockCost;
|
||||
};
|
||||
|
||||
template <class Duration>
|
||||
struct BenchmarkStats {
|
||||
BenchmarkInfo info;
|
||||
|
||||
std::vector<Duration> samples;
|
||||
Benchmark::Estimate<Duration> mean;
|
||||
Benchmark::Estimate<Duration> standardDeviation;
|
||||
Benchmark::OutlierClassification outliers;
|
||||
double outlierVariance;
|
||||
|
||||
template <typename Duration2>
|
||||
operator BenchmarkStats<Duration2>() const {
|
||||
std::vector<Duration2> samples2;
|
||||
samples2.reserve(samples.size());
|
||||
for (auto const& sample : samples) {
|
||||
samples2.push_back(Duration2(sample));
|
||||
}
|
||||
return {
|
||||
info,
|
||||
CATCH_MOVE(samples2),
|
||||
mean,
|
||||
standardDeviation,
|
||||
outliers,
|
||||
outlierVariance,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // CATCH_BENCHMARK_STATS_HPP_INCLUDED
|
23
src/catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp
Normal file
23
src/catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
#ifndef CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED
|
||||
#define CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
// We cannot forward declare the type with default template argument
|
||||
// multiple times, so it is split out into a separate header so that
|
||||
// we can prevent multiple declarations in dependees
|
||||
template <typename Duration = std::chrono::duration<double, std::nano>>
|
||||
struct BenchmarkStats;
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED
|
@ -111,6 +111,7 @@
|
||||
#include <catch2/internal/catch_test_failure_exception.hpp>
|
||||
#include <catch2/internal/catch_test_macro_impl.hpp>
|
||||
#include <catch2/internal/catch_test_registry.hpp>
|
||||
#include <catch2/internal/catch_test_run_info.hpp>
|
||||
#include <catch2/internal/catch_test_spec_parser.hpp>
|
||||
#include <catch2/internal/catch_textflow.hpp>
|
||||
#include <catch2/internal/catch_to_string.hpp>
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include <catch2/catch_test_spec.hpp>
|
||||
#include <catch2/catch_version.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_testcase.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
||||
#include <catch2/internal/catch_startup_exception_registry.hpp>
|
||||
#include <catch2/internal/catch_sharding.hpp>
|
||||
#include <catch2/internal/catch_textflow.hpp>
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <catch2/internal/catch_stringref.hpp>
|
||||
#include <catch2/internal/catch_result_type.hpp>
|
||||
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||
#include <catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
@ -31,8 +32,6 @@ namespace Catch {
|
||||
class IGeneratorTracker;
|
||||
|
||||
struct BenchmarkInfo;
|
||||
template <typename Duration = std::chrono::duration<double, std::nano>>
|
||||
struct BenchmarkStats;
|
||||
|
||||
namespace Generators {
|
||||
class GeneratorUntypedBase;
|
||||
|
@ -13,11 +13,10 @@
|
||||
#include <catch2/catch_assertion_result.hpp>
|
||||
#include <catch2/internal/catch_message_info.hpp>
|
||||
#include <catch2/internal/catch_stringref.hpp>
|
||||
#include <catch2/internal/catch_test_run_info.hpp>
|
||||
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
#include <catch2/benchmark/catch_estimate.hpp>
|
||||
#include <catch2/benchmark/catch_outlier_classification.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
||||
#include <catch2/benchmark/detail/catch_benchmark_stats.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
@ -57,11 +56,6 @@ namespace Catch {
|
||||
std::map<std::string, std::string> m_customOptions;
|
||||
};
|
||||
|
||||
struct TestRunInfo {
|
||||
constexpr TestRunInfo(StringRef _name) : name(_name) {}
|
||||
StringRef name;
|
||||
};
|
||||
|
||||
struct AssertionStats {
|
||||
AssertionStats( AssertionResult const& _assertionResult,
|
||||
std::vector<MessageInfo> const& _infoMessages,
|
||||
@ -113,45 +107,6 @@ namespace Catch {
|
||||
bool aborting;
|
||||
};
|
||||
|
||||
|
||||
struct BenchmarkInfo {
|
||||
std::string name;
|
||||
double estimatedDuration;
|
||||
int iterations;
|
||||
unsigned int samples;
|
||||
unsigned int resamples;
|
||||
double clockResolution;
|
||||
double clockCost;
|
||||
};
|
||||
|
||||
template <class Duration>
|
||||
struct BenchmarkStats {
|
||||
BenchmarkInfo info;
|
||||
|
||||
std::vector<Duration> samples;
|
||||
Benchmark::Estimate<Duration> mean;
|
||||
Benchmark::Estimate<Duration> standardDeviation;
|
||||
Benchmark::OutlierClassification outliers;
|
||||
double outlierVariance;
|
||||
|
||||
template <typename Duration2>
|
||||
operator BenchmarkStats<Duration2>() const {
|
||||
std::vector<Duration2> samples2;
|
||||
samples2.reserve(samples.size());
|
||||
for (auto const& sample : samples) {
|
||||
samples2.push_back(Duration2(sample));
|
||||
}
|
||||
return {
|
||||
info,
|
||||
CATCH_MOVE(samples2),
|
||||
mean,
|
||||
standardDeviation,
|
||||
outliers,
|
||||
outlierVariance,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
//! By setting up its preferences, a reporter can modify Catch2's behaviour
|
||||
//! in some regards, e.g. it can request Catch2 to capture writes to
|
||||
//! stdout/stderr during test execution, and pass them to the reporter.
|
||||
|
@ -8,8 +8,9 @@
|
||||
#include <catch2/internal/catch_run_context.hpp>
|
||||
|
||||
#include <catch2/catch_user_config.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_generatortracker.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_config.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_generatortracker.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
||||
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
||||
#include <catch2/internal/catch_context.hpp>
|
||||
#include <catch2/internal/catch_enforce.hpp>
|
||||
|
@ -8,8 +8,9 @@
|
||||
#ifndef CATCH_RUN_CONTEXT_HPP_INCLUDED
|
||||
#define CATCH_RUN_CONTEXT_HPP_INCLUDED
|
||||
|
||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
||||
#include <catch2/internal/catch_test_registry.hpp>
|
||||
#include <catch2/internal/catch_test_run_info.hpp>
|
||||
#include <catch2/internal/catch_fatal_condition_handler.hpp>
|
||||
#include <catch2/catch_test_case_info.hpp>
|
||||
#include <catch2/catch_message.hpp>
|
||||
@ -26,6 +27,8 @@ namespace Catch {
|
||||
|
||||
class IGeneratorTracker;
|
||||
class IConfig;
|
||||
class IEventListener;
|
||||
using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
22
src/catch2/internal/catch_test_run_info.hpp
Normal file
22
src/catch2/internal/catch_test_run_info.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
#ifndef CATCH_TEST_RUN_INFO_HPP_INCLUDED
|
||||
#define CATCH_TEST_RUN_INFO_HPP_INCLUDED
|
||||
|
||||
#include <catch2/internal/catch_stringref.hpp>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct TestRunInfo {
|
||||
constexpr TestRunInfo(StringRef _name) : name(_name) {}
|
||||
StringRef name;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // CATCH_TEST_RUN_INFO_HPP_INCLUDED
|
@ -32,6 +32,8 @@ benchmark_headers = [
|
||||
'benchmark/catch_sample_analysis.hpp',
|
||||
'benchmark/detail/catch_analyse.hpp',
|
||||
'benchmark/detail/catch_benchmark_function.hpp',
|
||||
'benchmark/detail/catch_benchmark_stats.hpp',
|
||||
'benchmark/detail/catch_benchmark_stats_fwd.hpp',
|
||||
'benchmark/detail/catch_complete_invoke.hpp',
|
||||
'benchmark/detail/catch_estimate_clock.hpp',
|
||||
'benchmark/detail/catch_measure.hpp',
|
||||
@ -133,6 +135,7 @@ internal_headers = [
|
||||
'internal/catch_test_failure_exception.hpp',
|
||||
'internal/catch_test_macro_impl.hpp',
|
||||
'internal/catch_test_registry.hpp',
|
||||
'internal/catch_test_run_info.hpp',
|
||||
'internal/catch_test_spec_parser.hpp',
|
||||
'internal/catch_textflow.hpp',
|
||||
'internal/catch_to_string.hpp',
|
||||
|
@ -8,7 +8,6 @@
|
||||
#ifndef CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED
|
||||
#define CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED
|
||||
|
||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
||||
#include <catch2/reporters/catch_reporter_streaming_base.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
#ifndef CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED
|
||||
#define CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED
|
||||
|
||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
||||
#include <catch2/reporters/catch_reporter_common_base.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||
|
@ -8,7 +8,6 @@
|
||||
#ifndef CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED
|
||||
#define CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED
|
||||
|
||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
||||
#include <catch2/reporters/catch_reporter_common_base.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user