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 /src | |
| 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 'src')
| -rw-r--r-- | src/catch2/catch_tostring.cpp | 10 | ||||
| -rw-r--r-- | src/catch2/catch_tostring.hpp | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/catch2/catch_tostring.cpp b/src/catch2/catch_tostring.cpp index f96c3fc1..940e61b5 100644 --- a/src/catch2/catch_tostring.cpp +++ b/src/catch2/catch_tostring.cpp @@ -8,6 +8,7 @@ #include <catch2/catch_tostring.hpp> #include <catch2/interfaces/catch_interfaces_config.hpp> +#include <catch2/interfaces/catch_interfaces_registry_hub.hpp> #include <catch2/internal/catch_context.hpp> #include <catch2/internal/catch_polyfills.hpp> @@ -113,6 +114,15 @@ namespace Detail { rss << std::setw(2) << static_cast<unsigned>(bytes[i]); return rss.str(); } + + std::string makeExceptionHappenedString() { + return "{ stringification failed with an exception: \"" + + translateActiveException() + "\" }"; + + } + + + } // end Detail namespace diff --git a/src/catch2/catch_tostring.hpp b/src/catch2/catch_tostring.hpp index ab91c618..41f89413 100644 --- a/src/catch2/catch_tostring.hpp +++ b/src/catch2/catch_tostring.hpp @@ -139,11 +139,17 @@ namespace Catch { namespace Detail { + std::string makeExceptionHappenedString(); + // This function dispatches all stringification requests inside of Catch. // Should be preferably called fully qualified, like ::Catch::Detail::stringify template <typename T> - std::string stringify(const T& e) { - return ::Catch::StringMaker<std::remove_cv_t<std::remove_reference_t<T>>>::convert(e); + std::string stringify( const T& e ) { + CATCH_TRY { + return ::Catch::StringMaker< + std::remove_cv_t<std::remove_reference_t<T>>>::convert( e ); + } + CATCH_CATCH_ALL { return makeExceptionHappenedString(); } } template<typename E> |