diff options
| author | Leitwolf11 | 2026-10-23 23:25:41 +0300 |
|---|---|---|
| committer | Leitwolf11 | 2026-10-23 23:25:41 +0300 |
| commit | 93d4e7dbebab867e0a7f59fc25308460a7a76280 (patch) | |
| tree | 54c568a3063d49e21f039b6d38f40f51be7991f0 /src/catch2 | |
| parent | 83c6fc3ac13abe83fa39f7b5f8559ccaf4412233 (diff) | |
| download | catch3-93d4e7dbebab867e0a7f59fc25308460a7a76280.tar.gz | |
Replace Catch2's runner with the Catch3 runner
Catch3 keeps Catch2's API for writing tests (test cases, sections,
assertions, matchers, generators, listeners, benchmarks) and replaces its
session, command line and reporters with a runner of its own.
The runner starts the test binary again as worker processes that take the
next test when they are free. A crash, an exit or a hang ends one test, not
the run. On top of that it adds:
- retries that tell deterministic, flaky and order-dependent failures
apart, and a bisection that names the test leaving state behind;
- a history of verdicts and durations, kept under a file lock, that drives
automatic quarantine, adaptive time limits, predictive ordering,
incremental runs, failure replay and analytics;
- selection by change, past failure or prediction, dependency closure,
and sharding by a stable hash or by recorded durations;
- tags for serial and isolated tests, shared resources, dependencies,
time limits and retries;
- a failure category, a signature, an analysis and a replay command for
every failure;
- console, JUnit XML (with flakyFailure and rerunFailure), JSON and Chrome
trace reports, and a versioned discovery listing (--list=json);
- a temporary directory per test (TMPDIR, TMP, TEMP and
TestTemporaryDirectory());
- Bazel's test environment: XML output file, test filter, sharding, seed,
premature exit file and undeclared outputs.
The command line is parsed by a hand-written, typed parser. Catch::Session
remains as a thin facade over the runner for custom main functions.
The result model in Progmasoft/Catch3/Results.hpp was rewritten around
tests and attempts, and the JUnit writer now writes it. The property
engine's example database is updated under a file lock with an atomic
rename, so parallel workers can write it at the same time.
Removed: Clara, the command-line and reporter-spec parsers, every reporter
and CATCH_REGISTER_REPORTER, listing, text flow, console colour and width,
the JSON and XML writers, sharding in the test registry, approval tests and
their baselines, Conan packaging, and the unused third_party/clara.hpp.
Listeners keep working; reporters' list and skip events are gone.
The Catch2 library is now compiled as C++20; code that includes only
Catch2's headers still needs C++14. Duplicate test cases are still refused
at start-up. Version 0.3.0.
ExtraTests now turn exceptions off for clang-cl with MSVC-style options,
which -fno-exceptions did not do.
Diffstat (limited to 'src/catch2')
75 files changed, 104 insertions, 9658 deletions
diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp index 82b11405..98c5f089 100644 --- a/src/catch2/catch_all.hpp +++ b/src/catch2/catch_all.hpp @@ -49,8 +49,6 @@ #include <catch2/interfaces/catch_interfaces_all.hpp> #include <catch2/internal/catch_assertion_handler.hpp> #include <catch2/internal/catch_case_insensitive_comparisons.hpp> -#include <catch2/internal/catch_clara.hpp> -#include <catch2/internal/catch_commandline.hpp> #include <catch2/internal/catch_compare_traits.hpp> #include <catch2/internal/catch_compiler_capabilities.hpp> #include <catch2/internal/catch_config_android_logwrite.hpp> @@ -59,11 +57,8 @@ #include <catch2/internal/catch_config_static_analysis_support.hpp> #include <catch2/internal/catch_config_uncaught_exceptions.hpp> #include <catch2/internal/catch_config_wchar.hpp> -#include <catch2/internal/catch_console_colour.hpp> -#include <catch2/internal/catch_console_width.hpp> #include <catch2/internal/catch_container_nonmembers.hpp> #include <catch2/internal/catch_context.hpp> -#include <catch2/internal/catch_debug_console.hpp> #include <catch2/internal/catch_debugger.hpp> #include <catch2/internal/catch_decomposer.hpp> #include <catch2/internal/catch_deprecation_macro.hpp> @@ -75,12 +70,9 @@ #include <catch2/internal/catch_floating_point_helpers.hpp> #include <catch2/internal/catch_getenv.hpp> #include <catch2/internal/catch_is_permutation.hpp> -#include <catch2/internal/catch_istream.hpp> -#include <catch2/internal/catch_jsonwriter.hpp> #include <catch2/internal/catch_lazy_expr.hpp> #include <catch2/internal/catch_leak_detector.hpp> #include <catch2/internal/catch_lifetimebound.hpp> -#include <catch2/internal/catch_list.hpp> #include <catch2/internal/catch_logical_traits.hpp> #include <catch2/internal/catch_message_info.hpp> #include <catch2/internal/catch_meta.hpp> @@ -100,12 +92,10 @@ #include <catch2/internal/catch_random_number_generator.hpp> #include <catch2/internal/catch_random_seed_generation.hpp> #include <catch2/internal/catch_reporter_registry.hpp> -#include <catch2/internal/catch_reporter_spec_parser.hpp> #include <catch2/internal/catch_result_type.hpp> #include <catch2/internal/catch_reusable_string_stream.hpp> #include <catch2/internal/catch_run_context.hpp> #include <catch2/internal/catch_section.hpp> -#include <catch2/internal/catch_sharding.hpp> #include <catch2/internal/catch_singletons.hpp> #include <catch2/internal/catch_source_line_info.hpp> #include <catch2/internal/catch_startup_exception_registry.hpp> @@ -122,7 +112,6 @@ #include <catch2/internal/catch_test_macro_impl.hpp> #include <catch2/internal/catch_test_registry.hpp> #include <catch2/internal/catch_test_spec_parser.hpp> -#include <catch2/internal/catch_textflow.hpp> #include <catch2/internal/catch_thread_local.hpp> #include <catch2/internal/catch_thread_support.hpp> #include <catch2/internal/catch_to_string.hpp> @@ -134,7 +123,6 @@ #include <catch2/internal/catch_unreachable.hpp> #include <catch2/internal/catch_void_type.hpp> #include <catch2/internal/catch_wildcard_pattern.hpp> -#include <catch2/internal/catch_xmlwriter.hpp> #include <catch2/matchers/catch_matchers_all.hpp> #include <catch2/reporters/catch_reporters_all.hpp> diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp index e71ee353..1c3022d0 100644 --- a/src/catch2/catch_config.cpp +++ b/src/catch2/catch_config.cpp @@ -7,92 +7,12 @@ // SPDX-License-Identifier: BSL-1.0 #include <catch2/catch_config.hpp> #include <catch2/catch_user_config.hpp> -#include <catch2/internal/catch_enforce.hpp> -#include <catch2/internal/catch_parse_numbers.hpp> -#include <catch2/internal/catch_stdstreams.hpp> -#include <catch2/internal/catch_stringref.hpp> #include <catch2/internal/catch_string_manip.hpp> #include <catch2/internal/catch_test_spec_parser.hpp> #include <catch2/interfaces/catch_interfaces_tag_alias_registry.hpp> -#include <catch2/internal/catch_getenv.hpp> - -#include <fstream> namespace Catch { - namespace { - static bool enableBazelEnvSupport() { -#if defined( CATCH_CONFIG_BAZEL_SUPPORT ) - return true; -#else - return Detail::getEnv( "BAZEL_TEST" ) != nullptr; -#endif - } - - struct bazelShardingOptions { - unsigned int shardIndex, shardCount; - std::string shardFilePath; - }; - - static Optional<bazelShardingOptions> readBazelShardingOptions() { - const auto bazelShardIndex = Detail::getEnv( "TEST_SHARD_INDEX" ); - const auto bazelShardTotal = Detail::getEnv( "TEST_TOTAL_SHARDS" ); - const auto bazelShardInfoFile = Detail::getEnv( "TEST_SHARD_STATUS_FILE" ); - - - const bool has_all = - bazelShardIndex && bazelShardTotal && bazelShardInfoFile; - if ( !has_all ) { - // We provide nice warning message if the input is - // misconfigured. - auto warn = []( const char* env_var ) { - Catch::cerr() - << "Warning: Bazel shard configuration is missing '" - << env_var << "'. Shard configuration is skipped.\n"; - }; - if ( !bazelShardIndex ) { - warn( "TEST_SHARD_INDEX" ); - } - if ( !bazelShardTotal ) { - warn( "TEST_TOTAL_SHARDS" ); - } - if ( !bazelShardInfoFile ) { - warn( "TEST_SHARD_STATUS_FILE" ); - } - return {}; - } - - auto shardIndex = parseUInt( bazelShardIndex ); - if ( !shardIndex ) { - Catch::cerr() - << "Warning: could not parse 'TEST_SHARD_INDEX' ('" << bazelShardIndex - << "') as unsigned int.\n"; - return {}; - } - auto shardTotal = parseUInt( bazelShardTotal ); - if ( !shardTotal ) { - Catch::cerr() - << "Warning: could not parse 'TEST_TOTAL_SHARD' ('" - << bazelShardTotal << "') as unsigned int.\n"; - return {}; - } - - return bazelShardingOptions{ - *shardIndex, *shardTotal, bazelShardInfoFile }; - - } - } // end namespace - - - bool operator==( ProcessedReporterSpec const& lhs, - ProcessedReporterSpec const& rhs ) { - return lhs.name == rhs.name && - lhs.outputFilename == rhs.outputFilename && - lhs.colourMode == rhs.colourMode && - lhs.verbosity == rhs.verbosity && - lhs.customOptions == rhs.customOptions; - } - bool operator==( PathFilter const& lhs, PathFilter const& rhs ) { return lhs.type == rhs.type && lhs.filter == rhs.filter; } @@ -102,33 +22,10 @@ namespace Catch { // We need to trim filter specs to avoid trouble with superfluous // whitespace (esp. important for bdd macros, as those are manually // aligned with whitespace). - for (auto& elem : m_data.testsOrTags) { elem = trim(elem); } - // Insert the default reporter if user hasn't asked for a specific one - if ( m_data.reporterSpecifications.empty() ) { -#if defined( CATCH_CONFIG_DEFAULT_REPORTER ) - const auto default_spec = CATCH_CONFIG_DEFAULT_REPORTER; -#else - const auto default_spec = "console"; -#endif - auto parsed = parseReporterSpec(default_spec); - CATCH_ENFORCE( parsed, - "Cannot parse the provided default reporter spec: '" - << default_spec << '\'' ); - m_data.reporterSpecifications.push_back( std::move( *parsed ) ); - } - - // Reading bazel env vars can change some parts of the config data, - // so we have to process the bazel env before acting on the config. - if ( enableBazelEnvSupport() ) { - readBazelEnvVars(); - } - - // Bazel support can modify the test specs, so parsing has to happen - // after reading Bazel env vars. TestSpecParser parser( ITagAliasRegistry::get() ); if ( !m_data.testsOrTags.empty() ) { m_hasTestFilters = true; @@ -137,60 +34,17 @@ namespace Catch { } } m_testSpec = parser.testSpec(); - - - // We now fixup the reporter specs to handle default output spec, - // default colour spec, etc - bool defaultOutputUsed = false; - for ( auto const& reporterSpec : m_data.reporterSpecifications ) { - // We do the default-output check separately, while always - // using the default output below to make the code simpler - // and avoid superfluous copies. - if ( reporterSpec.outputFile().none() ) { - CATCH_ENFORCE( !defaultOutputUsed, - "Internal error: cannot use default output for " - "multiple reporters" ); - defaultOutputUsed = true; - } - - m_processedReporterSpecs.push_back( ProcessedReporterSpec{ - reporterSpec.name(), - reporterSpec.outputFile() ? *reporterSpec.outputFile() - : data.defaultOutputFilename, - reporterSpec.colourMode().valueOr( data.defaultColourMode ), - reporterSpec.verbosity().valueOr( data.verbosity ), - reporterSpec.customOptions() } ); - } } Config::~Config() = default; - - bool Config::listTests() const { return m_data.listTests; } - bool Config::listTags() const { return m_data.listTags; } - bool Config::listReporters() const { return m_data.listReporters; } - bool Config::listListeners() const { return m_data.listListeners; } - std::vector<std::string> const& Config::getTestsOrTags() const { return m_data.testsOrTags; } std::vector<PathFilter> const& Config::getPathFilters() const { return m_data.pathFilters; } bool Config::useNewFilterBehaviour() const { return m_data.useNewPathFilteringBehaviour; } - std::vector<ReporterSpec> const& Config::getReporterSpecs() const { - return m_data.reporterSpecifications; - } - - std::vector<ProcessedReporterSpec> const& - Config::getProcessedReporterSpecs() const { - return m_processedReporterSpecs; - } - TestSpec const& Config::testSpec() const { return m_testSpec; } bool Config::hasTestFilters() const { return m_hasTestFilters; } - bool Config::showHelp() const { return m_data.showHelp; } - - std::string const& Config::getExitGuardFilePath() const { return m_data.prematureExitGuardFilePath; } - // IConfig interface bool Config::allowThrows() const { return !m_data.noThrow; } StringRef Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } @@ -225,58 +79,4 @@ namespace Catch { unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; } std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); } - void Config::readBazelEnvVars() { - // Register a JUnit reporter for Bazel. Bazel sets an environment - // variable with the path to XML output. If this file is written to - // during test, Bazel will not generate a default XML output. - // This allows the XML output file to contain higher level of detail - // than what is possible otherwise. - const auto bazelOutputFile = Detail::getEnv( "XML_OUTPUT_FILE" ); - - if ( bazelOutputFile ) { - m_data.reporterSpecifications.push_back( - { "junit", std::string( bazelOutputFile ), {}, {}, {} } ); - } - - const auto bazelTestSpec = Detail::getEnv( "TESTBRIDGE_TEST_ONLY" ); - if ( bazelTestSpec ) { - // Presumably the test spec from environment should overwrite - // the one we got from CLI (if we got any) - m_data.testsOrTags.clear(); - m_data.testsOrTags.push_back( bazelTestSpec ); - } - - const auto bazelShardOptions = readBazelShardingOptions(); - if ( bazelShardOptions ) { - std::ofstream f( bazelShardOptions->shardFilePath, - std::ios_base::out | std::ios_base::trunc ); - if ( f.is_open() ) { - f << ""; - m_data.shardIndex = bazelShardOptions->shardIndex; - m_data.shardCount = bazelShardOptions->shardCount; - } - } - - const auto bazel |