mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-02 05:15:39 +02:00
Stop exceptions in generator constructors from aborting the binary
Fixes #2615
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user