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

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/UsageTests/Generators.tests.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2023-01-17 11:04:49 +0100
committerMartin Hořeňovský2023-01-22 16:04:16 +0100
commit8359a6b244a26cffabd4440b17fac8b1392815af (patch)
treeeb0a396ddc582cb7f1b5e5f7d0b3b369d18ebc40 /tests/SelfTest/UsageTests/Generators.tests.cpp
parentadf43494e19077d492343ea13d597af5133b7288 (diff)
downloadcatch3-8359a6b244a26cffabd4440b17fac8b1392815af.tar.gz
Stop exceptions in generator constructors from aborting the binary
Fixes #2615
Diffstat (limited to 'tests/SelfTest/UsageTests/Generators.tests.cpp')
-rw-r--r--tests/SelfTest/UsageTests/Generators.tests.cpp35
1 files changed, 33 insertions, 2 deletions
diff --git a/tests/SelfTest/UsageTests/Generators.tests.cpp b/tests/SelfTest/UsageTests/Generators.tests.cpp
index 3b691247..274c63b8 100644
--- a/tests/SelfTest/UsageTests/Generators.tests.cpp
+++ b/tests/SelfTest/UsageTests/Generators.tests.cpp
@@ -277,6 +277,37 @@ TEST_CASE("#1913 - GENERATEs can share a line", "[regression][generators]") {
REQUIRE(i != j);
}
-#if defined(__clang__)
-#pragma clang diagnostic pop
+namespace {
+ class test_generator : public Catch::Generators::IGenerator<int> {
+ public:
+ [[noreturn]] explicit test_generator() {
+ // removing the following line will cause the program to terminate
+ // gracefully.
+ throw Catch::GeneratorException( "failure to init" );
+ }
+
+ auto get() const -> int const& override {
+ static constexpr int value = 1;
+ return value;
+ }
+
+ auto next() -> bool override { return false; }
+ };
+
+ static auto make_test_generator()
+ -> Catch::Generators::GeneratorWrapper<int> {
+ return { new test_generator() };
+ }
+
+} // namespace
+
+TEST_CASE( "#2615 - Throwing in constructor generator fails test case but does not abort", "[!shouldfail]" ) {
+ // this should fail the test case, but not abort the application
+ auto sample = GENERATE( make_test_generator() );
+ // this assertion shouldn't trigger
+ REQUIRE( sample == 0U );
+}
+
+#if defined( __clang__ )
+# pragma clang diagnostic pop
#endif