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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/internal/catch_run_context.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-02-12 21:39:57 +0100
committerMartin Hořeňovský2026-02-13 21:17:37 +0100
commit045ac7acce5205e529a7a6fda155cadc3dfe68e7 (patch)
tree36c9289ebbe051791968cb997ff474669888b32c /src/catch2/internal/catch_run_context.cpp
parent72671fdbdfc7a6f1fad03af40e75ad8d881822a8 (diff)
downloadcatch3-045ac7acce5205e529a7a6fda155cadc3dfe68e7.tar.gz
Simplify IGeneratorTracker
* Removed `IGeneratorTracker::hasGenerator`, as it was never used. * Removed `IGeneratorTracker::setGenerator`, as actually using it after the tracker was used would lead to inconsistent behaviour. Instead, the tracker is given the generator it guards during construction.
Diffstat (limited to 'src/catch2/internal/catch_run_context.cpp')
-rw-r--r--src/catch2/internal/catch_run_context.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp
index 7852b369..86ae0446 100644
--- a/src/catch2/internal/catch_run_context.cpp
+++ b/src/catch2/internal/catch_run_context.cpp
@@ -39,8 +39,13 @@ namespace Catch {
GeneratorTracker(
TestCaseTracking::NameAndLocation&& nameAndLocation,
TrackerContext& ctx,
- ITracker* parent ):
- TrackerBase( CATCH_MOVE( nameAndLocation ), ctx, parent ) {}
+ ITracker* parent,
+ GeneratorBasePtr&& generator ):
+ TrackerBase( CATCH_MOVE( nameAndLocation ), ctx, parent ),
+ m_generator( CATCH_MOVE( generator ) ) {
+ assert( m_generator &&
+ "Cannot create tracker without generator" );
+ }
static GeneratorTracker*
acquire( TrackerContext& ctx,
@@ -84,9 +89,6 @@ namespace Catch {
// TrackerBase interface
bool isGeneratorTracker() const override { return true; }
- auto hasGenerator() const -> bool override {
- return !!m_generator;
- }
void close() override {
TrackerBase::close();
// If a generator has a child (it is followed by a section)
@@ -157,9 +159,6 @@ namespace Catch {
auto getGenerator() const -> GeneratorBasePtr const& override {
return m_generator;
}
- void setGenerator( GeneratorBasePtr&& generator ) override {
- m_generator = CATCH_MOVE( generator );
- }
};
} // namespace
}
@@ -497,12 +496,15 @@ namespace Catch {
currentTracker.nameAndLocation() != nameAndLoc &&
"Trying to create tracker for a generator that already has one" );
- auto newTracker = Catch::Detail::make_unique<Generators::GeneratorTracker>(
- CATCH_MOVE(nameAndLoc), m_trackerContext, &currentTracker );
+ auto newTracker =
+ Catch::Detail::make_unique<Generators::GeneratorTracker>(
+ CATCH_MOVE( nameAndLoc ),
+ m_trackerContext,
+ &currentTracker,
+ CATCH_MOVE( generator ) );
auto ret = newTracker.get();
currentTracker.addChild( CATCH_MOVE( newTracker ) );
- ret->setGenerator( CATCH_MOVE( generator ) );
ret->open();
return ret;
}