From 34d7a33574357ef2fe9fbc402f08a5e351b40744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sun, 11 Feb 2018 16:31:12 +0100 Subject: [PATCH] Add a way to change fallback stringifier This allows reuse of projects existing stringification machinery Closes #1024 --- docs/configuration.md | 14 ++++++++++++++ include/internal/catch_tostring.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/docs/configuration.md b/docs/configuration.md index 22ec5716..b024b2fd 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -7,6 +7,7 @@ [Terminal colour](#terminal-colour)
[Console width](#console-width)
[stdout](#stdout)
+[Fallback stringifier](#fallback-stringifier)
[Other toggles](#other-toggles)
[Windows header clutter](#windows-header-clutter)
[Enabling stringification](#enabling-stringification)
@@ -73,6 +74,19 @@ Catch does not use ```std::cout```, ```std::cerr``` and ```std::clog``` directly This can be useful on certain platforms that do not provide the standard iostreams, such as certain embedded systems. +## Fallback stringifier + +By default Catch's stringification machinery falls back to a "{?}". To +let projects reuse their own existing stringification machinery, this +fallback can be overriden by defining `CATCH_CONFIG_FALLBACK_STRINGIFIER` +to a name of a function that should perform the stringification instead. + +The provided function must return std::string and must accept any type +(e.g. via overloading). + +_Note that if the provided function does not handle a type and this type +requires to be stringified, the compilation will fail._ + ## Other toggles diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index 1e644a93..89909906 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -88,7 +88,11 @@ namespace Catch { static typename std::enable_if::value, std::string>::type convert( const Fake& value ) { +#if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER) return Detail::convertUnstreamable( value ); +#else + return CATCH_CONFIG_FALLBACK_STRINGIFIER( value ); +#endif } };