Stop exceptions in generator constructors from aborting the binary

Fixes #2615
This commit is contained in:
Martin Hořeňovský
2023-01-17 11:04:49 +01:00
parent adf43494e1
commit 8359a6b244
25 changed files with 230 additions and 40 deletions

View File

@@ -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