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

summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorLeitwolf2026-10-24 19:03:40 +0300
committerGitHub2026-10-24 19:03:40 +0300
commit4f1c759cffcb14bd6511e1d7c5fbace682e24f2d (patch)
tree415fe5d48a5b48650bba3747beaf245d727c4f61 /examples
parent83c6fc3ac13abe83fa39f7b5f8559ccaf4412233 (diff)
parent622188f9c08e4af35941c146979883ed4882410e (diff)
downloadcatch3-4f1c759cffcb14bd6511e1d7c5fbace682e24f2d.tar.gz
Merge pull request #15 from Progmasoft/feature/catch3-runner
Replace Catch2's runner with the Catch3 runner
Diffstat (limited to 'examples')
-rw-r--r--examples/210-Evt-EventListeners.cpp8
-rw-r--r--examples/232-Cfg-CustomMain.cpp40
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() );
}