Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Add a way to change fallback stringifier

This allows reuse of projects existing stringification machinery

Closes #1024
Commit
34d7a33574357ef2fe9fbc402f08a5e351b40744
Author
Martin Hořeňovský ·
Parents
082c3b84bc64

Files · Download .tar.gz

Changes

 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)<br>
 [Console width](#console-width)<br>
 [stdout](#stdout)<br>
+[Fallback stringifier](#fallback-stringifier)<br>
 [Other toggles](#other-toggles)<br>
 [Windows header clutter](#windows-header-clutter)<br>
 [Enabling stringification](#enabling-stringification)<br>
@@ -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<!::Catch::Detail::IsStreamInsertable<Fake>::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
         }
     };