mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-03 22:05:39 +02:00
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
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
Reference in New Issue
Block a user