diff options
| author | Martin Hořeňovský | 2026-07-07 14:09:04 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-07-07 14:09:11 +0200 |
| commit | dd94b9a780e66651ff686083a66722386c540228 (patch) | |
| tree | 69d06224dec4f48b3a95bc4814339946da4d3750 /src/catch2/internal/catch_run_context.cpp | |
| parent | 9f7c9f6872308d4e7c32fff2f1ac6640aa866b6a (diff) | |
| download | catch3-dd94b9a780e66651ff686083a66722386c540228.tar.gz | |
Fix --warn InfiniteGenerators firing even if the generator was filtered
Diffstat (limited to 'src/catch2/internal/catch_run_context.cpp')
| -rw-r--r-- | src/catch2/internal/catch_run_context.cpp | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp index a435170f..18e01f75 100644 --- a/src/catch2/internal/catch_run_context.cpp +++ b/src/catch2/internal/catch_run_context.cpp @@ -196,6 +196,8 @@ namespace Catch { auto getGenerator() const -> GeneratorBasePtr const& override { return m_generator; } + + bool isFilteredImpl() const override { return m_isFiltered; } }; } // namespace } @@ -540,17 +542,6 @@ namespace Catch { SourceLineInfo lineInfo, Generators::GeneratorBasePtr&& generator ) { - // TBD: Do we want to avoid the warning if the generator is filtered? - if ( m_config->warnAboutInfiniteGenerators() && - !generator->isFinite() ) { - // We want the semantics of `FAIL()`, but we inline it - // to avoid issues with conditionally prefixed macros - INTERNAL_CATCH_MSG( "FAIL", - Catch::ResultWas::ExplicitFailure, - Catch::ResultDisposition::Normal, - "GENERATE() would run infinitely" ); - } - auto nameAndLoc = TestCaseTracking::NameAndLocation( static_cast<std::string>( generatorName ), lineInfo ); auto& currentTracker = m_trackerContext.currentTracker(); assert( @@ -563,11 +554,24 @@ namespace Catch { m_trackerContext, ¤tTracker, CATCH_MOVE( generator ) ); - auto ret = newTracker.get(); + + // The warning shouldn't fire if the generator is infinite, **but** filtered down. + if ( m_config->warnAboutInfiniteGenerators() && + !newTracker->m_generator->isFinite() && + !newTracker->isFiltered() ) { + // We want the semantics of `FAIL()`, but we inline it + // to avoid issues with conditionally prefixed macros + INTERNAL_CATCH_MSG( "FAIL", + Catch::ResultWas::ExplicitFailure, + Catch::ResultDisposition::Normal, + "GENERATE() would run infinitely" ); + } + + auto returnPtr = newTracker.get(); currentTracker.addChild( CATCH_MOVE( newTracker ) ); - ret->open(); - return ret; + returnPtr->open(); + return returnPtr; } bool RunContext::testForMissingAssertions(Counts& assertions) { |