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

implement stringify for std::nullopt_t

Commit
3a5cde55b7a27a6d94ce994a8362b2425211bd5e
Author
Martin Jeřábek ·
Committer
Martin Hořeňovský
Parents
2a19ae16b875

Files · Download .tar.gz

Changes

 src/catch2/catch_tostring.hpp                        | 6 ++++++
 tests/SelfTest/UsageTests/ToStringOptional.tests.cpp | 4 ++++
 2 files changed, 10 insertions(+)

diff --git a/src/catch2/catch_tostring.hpp b/src/catch2/catch_tostring.hpp
index 788d824c..f3fb0beb 100644
--- a/src/catch2/catch_tostring.hpp
+++ b/src/catch2/catch_tostring.hpp
@@ -398,6 +398,12 @@ namespace Catch {
             }
         }
     };
+    template <>
+    struct StringMaker<std::nullopt_t> {
+        static std::string convert(const std::nullopt_t&) {
+            return "{ }";
+        }
+    };
 }
 #endif // CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER
 
diff --git a/tests/SelfTest/UsageTests/ToStringOptional.tests.cpp b/tests/SelfTest/UsageTests/ToStringOptional.tests.cpp
index 9fd9d6b4..3671771a 100644
--- a/tests/SelfTest/UsageTests/ToStringOptional.tests.cpp
+++ b/tests/SelfTest/UsageTests/ToStringOptional.tests.cpp
@@ -28,4 +28,8 @@ TEST_CASE( "std::vector<std::optional<int> > -> toString", "[toString][optional]
     REQUIRE( "{ 0, { }, 2 }" == ::Catch::Detail::stringify( type{ 0, {}, 2 } ) );
 }
 
+TEST_CASE( "std::nullopt -> toString", "[toString][optional][approvals]" ) {
+    REQUIRE( "{ }" == ::Catch::Detail::stringify( std::nullopt ) );
+}
+
 #endif // CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL