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 /examples | |
| 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 'examples')
| -rw-r--r-- | examples/210-Evt-EventListeners.cpp | 8 | ||||
| -rw-r--r-- | examples/232-Cfg-CustomMain.cpp | 40 |
2 files changed, 22 insertions, 26 deletions
diff --git a/examples/210-Evt-EventListeners.cpp b/examples/210-Evt-EventListeners.cpp index d1cfdb4f..f0a9f0af 100644 --- a/examples/210-Evt-EventListeners.cpp +++ b/examples/210-Evt-EventListeners.cpp @@ -334,14 +334,6 @@ struct MyListener : Catch::EventListenerBase { print( std::cout, 1, "- testRunStats", testRunStats ); } - // A test is being skipped (because it is "hidden") - void skipTest( Catch::TestCaseInfo const& testInfo ) override { - std::cout - << dashed_line - << "\nEvent: skipTest:\n"; - print( std::cout, 1, "- testInfo", testInfo ); - } - // Test cases starting void testCaseStarting( Catch::TestCaseInfo const& testInfo ) override { std::cout diff --git a/examples/232-Cfg-CustomMain.cpp b/examples/232-Cfg-CustomMain.cpp index 27040993..6ef05fe7 100644 --- a/examples/232-Cfg-CustomMain.cpp +++ b/examples/232-Cfg-CustomMain.cpp @@ -7,35 +7,39 @@ // SPDX-License-Identifier: BSL-1.0 // 232-Cfg-CustomMain.cpp -// Show how to use custom main and add a custom option to the CLI parser +// Show how to use custom main and read an option of your own before the +// rest of the command line goes to the Catch3 runner. +// +// The runner starts this binary again for its worker processes, with the +// same `main`: what happens before `run` happens in every worker too, which +// is where global set-up belongs. #include <catch2/catch_session.hpp> +#include <cstdlib> #include <iostream> +#include <string> +#include <vector> int main(int argc, char** argv) { Catch::Session session; // There must be exactly one instance int height = 0; // Some user variable you want to be able to set - // Build a new parser on top of Catch2's - using namespace Catch::Clara; - auto cli - = session.cli() // Get Catch2's command line parser - | Opt( height, "height" ) // bind variable to a new option, with a hint string - ["--height"] // the option names it will respond to - ("how high?"); // description string for the help output + // Take our own option out of the command line; the runner reads the rest. + // Workers are started with the runner's options only, so a value they + // need too belongs in the environment, which they inherit. + std::vector<char const*> arguments; + for ( int i = 0; i < argc; ++i ) { + std::string const argument = argv[i]; + if ( argument.rfind( "--height=", 0 ) == 0 ) { + height = std::atoi( argument.c_str() + 9 ); + } else { + arguments.push_back( argv[i] ); + } + } - // Now pass the new composite back to Catch2 so it uses that - session.cli( cli ); - - // Let Catch2 (using Clara) parse the command line - int returnCode = session.applyCommandLine( argc, argv ); - if( returnCode != 0 ) // Indicates a command line error - return returnCode; - - // if set on the command line then 'height' is now set at this point std::cout << "height: " << height << '\n'; - return session.run(); + return session.run( static_cast<int>( arguments.size() ), arguments.data() ); } |