Fix unit tests compilation in C++20

There is no more overload of std::ostream::operator<<() for wchar_t in
C++20, i.e. it is explicitly deleted, so we need to define some other
way of printing wchar_t out from Catch macros.

Do it by specializing Catch::StringMaker<> for it and outputting it
either as a (7 bit) ASCII character, if this is what it is, or as a
Unicode character code otherwise, as this will probably be more useful
in case of a test failure.
This commit is contained in:
Vadim Zeitlin 2020-05-10 23:05:41 +02:00
parent 63626acbe4
commit 499252ace8

View File

@ -55,6 +55,31 @@
#define wxDEFAULT_MANTISSA_SIZE_3
#endif
// Many tests use wide characters or wide strings inside Catch macros, which
// requires converting them to string if the check fails. This falls back to
// std::ostream::operator<() by default, which never worked correctly, as there
// never was any overload for wchar_t and so it used something else, but in C++
// 20 this overload is explicitly deleted, so it results in compile-time error.
//
// Hence define this specialization to allow compiling such comparisons.
namespace Catch
{
template <>
struct StringMaker<wchar_t>
{
static std::string convert(wchar_t wc)
{
if ( wc < 0x7f )
return std::string(static_cast<char>(wc), 1);
return wxString::Format("U+%06X", wc).ToStdString();
}
};
} // namespace Catch
// thrown when assert fails in debug build
class TestAssertFailure
{