diff options
| author | Martin Hořeňovský | 2025-08-01 23:23:34 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2025-08-02 10:11:52 +0200 |
| commit | c5e0ef4e67639e6001dc6f24b210ee9b1f0a7c1f (patch) | |
| tree | 732892633ae48081cd1129f65f5e5dbe0b25f98d /tests/SelfTest/IntrospectiveTests/ToString.tests.cpp | |
| parent | 17fe5eaa5c0c28e7a6a197420f0f16b085a8fa9a (diff) | |
| download | catch3-c5e0ef4e67639e6001dc6f24b210ee9b1f0a7c1f.tar.gz | |
Catch exceptions from StringMakers inside Detail::stringify
This stops tests failing falsely if the assertion passed, but the
stringification itself failed as the assertion was sent to the reporter.
I don't think that stringification should be fallible, but the
overhead in compilation ended up being small enough (<0.5% on `SelfTest`)
that it might be worth implementing, in case there is more users
with weird `StringMaker`s than just MongoDB.
Closes #2980
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/ToString.tests.cpp')
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/ToString.tests.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp b/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp index 60fafc80..c3c70142 100644 --- a/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp @@ -118,3 +118,24 @@ TEST_CASE( "#2944 - Stringifying dates before 1970 should not crash", "[.approva Equals( "gmtime from provided timepoint has failed. This " "happens e.g. with pre-1970 dates using Microsoft libc" ) ); } + +namespace { + struct ThrowsOnStringification { + friend bool operator==( ThrowsOnStringification, + ThrowsOnStringification ) { + return true; + } + }; +} + +template <> +struct Catch::StringMaker<ThrowsOnStringification> { + static std::string convert(ThrowsOnStringification) { + throw std::runtime_error( "Invalid" ); + } +}; + +TEST_CASE( "Stringifying bla bla bla" ) { + ThrowsOnStringification tos; + CHECK( tos == tos ); +} |