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

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-02-10 09:16:03 +0100
committerMartin Hořeňovský2026-02-10 09:37:19 +0100
commitdaadf42a0e21ac09abc1f286f875078b24e2dd4d (patch)
tree1a680c2c82f71ad1701ce0b8e3c28ce9e50470b9 /src/catch2
parentd079ee13ab137547ab26bd1ed5ca2858d7fbd847 (diff)
downloadcatch3-daadf42a0e21ac09abc1f286f875078b24e2dd4d.tar.gz
Add --warn InfiniteGenerators
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/catch_config.cpp3
-rw-r--r--src/catch2/catch_config.hpp1
-rw-r--r--src/catch2/interfaces/catch_interfaces_config.hpp3
-rw-r--r--src/catch2/internal/catch_commandline.cpp3
-rw-r--r--src/catch2/internal/catch_run_context.cpp7
5 files changed, 17 insertions, 0 deletions
diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp
index fef03d7d..f83821a7 100644
--- a/src/catch2/catch_config.cpp
+++ b/src/catch2/catch_config.cpp
@@ -197,6 +197,9 @@ namespace Catch {
bool Config::warnAboutUnmatchedTestSpecs() const {
return !!( m_data.warnings & WarnAbout::UnmatchedTestSpec );
}
+ bool Config::warnAboutInfiniteGenerators() const {
+ return !!( m_data.warnings & WarnAbout::InfiniteGenerator );
+ }
bool Config::zeroTestsCountAsSuccess() const { return m_data.allowZeroTests; }
ShowDurations Config::showDurations() const { return m_data.showDurations; }
double Config::minDuration() const { return m_data.minDuration; }
diff --git a/src/catch2/catch_config.hpp b/src/catch2/catch_config.hpp
index cdf286ad..8014eb9e 100644
--- a/src/catch2/catch_config.hpp
+++ b/src/catch2/catch_config.hpp
@@ -124,6 +124,7 @@ namespace Catch {
bool includeSuccessfulResults() const override;
bool warnAboutMissingAssertions() const override;
bool warnAboutUnmatchedTestSpecs() const override;
+ bool warnAboutInfiniteGenerators() const override;
bool zeroTestsCountAsSuccess() const override;
ShowDurations showDurations() const override;
double minDuration() const override;
diff --git a/src/catch2/interfaces/catch_interfaces_config.hpp b/src/catch2/interfaces/catch_interfaces_config.hpp
index 82a298db..db4745c3 100644
--- a/src/catch2/interfaces/catch_interfaces_config.hpp
+++ b/src/catch2/interfaces/catch_interfaces_config.hpp
@@ -29,6 +29,8 @@ namespace Catch {
NoAssertions = 0x01,
//! A command line test spec matched no test cases
UnmatchedTestSpec = 0x02,
+ //! The resulting generator in GENERATE is infinite
+ InfiniteGenerator = 0x04,
}; };
enum class ShowDurations {
@@ -71,6 +73,7 @@ namespace Catch {
virtual bool shouldDebugBreak() const = 0;
virtual bool warnAboutMissingAssertions() const = 0;
virtual bool warnAboutUnmatchedTestSpecs() const = 0;
+ virtual bool warnAboutInfiniteGenerators() const = 0;
virtual bool zeroTestsCountAsSuccess() const = 0;
virtual int abortAfter() const = 0;
virtual bool showInvisibles() const = 0;
diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp
index cf9cbf6d..61825df9 100644
--- a/src/catch2/internal/catch_commandline.cpp
+++ b/src/catch2/internal/catch_commandline.cpp
@@ -32,6 +32,9 @@ namespace Catch {
} else if ( warning == "UnmatchedTestSpec" ) {
config.warnings = static_cast<WarnAbout::What>(config.warnings | WarnAbout::UnmatchedTestSpec);
return ParserResult::ok( ParseResultType::Matched );
+ } else if ( warning == "InfiniteGenerators" ) {
+ config.warnings = static_cast<WarnAbout::What>(config.warnings | WarnAbout::InfiniteGenerator);
+ return ParserResult::ok( ParseResultType::Matched );
}
return ParserResult ::runtimeError(
diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp
index 5e5f95a4..8e04748e 100644
--- a/src/catch2/internal/catch_run_context.cpp
+++ b/src/catch2/internal/catch_run_context.cpp
@@ -21,7 +21,9 @@
#include <catch2/internal/catch_assertion_handler.hpp>
#include <catch2/internal/catch_test_failure_exception.hpp>
#include <catch2/internal/catch_thread_local.hpp>
+#include <catch2/internal/catch_unreachable.hpp>
#include <catch2/internal/catch_result_type.hpp>
+#include <catch2/catch_test_macros.hpp>
#include <cassert>
#include <algorithm>
@@ -495,6 +497,11 @@ namespace Catch {
currentTracker.addChild( CATCH_MOVE( newTracker ) );
ret->setGenerator( CATCH_MOVE( generator ) );
+ if ( m_config->warnAboutInfiniteGenerators() &&
+ !ret->getGenerator()->isFinite() ) {
+ // TBD: Would it be better to expand this macro inline?
+ FAIL( "GENERATE() would run infinitely" );
+ }
ret->open();
return ret;
}