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

Fixes nil NSString issue reported in #159

Commit
32e70b223509cb5a166e1110ee56ad19a5238592
Author
Phil Nash ·
Parents
17479c6e4999

Files · Download .tar.gz

Changes

 include/internal/catch_tostring.hpp              | 4 ++++
 projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/include/internal/catch_tostring.hpp b/include/internal/catch_tostring.hpp
index ef9b5efc..f87127e0 100644
--- a/include/internal/catch_tostring.hpp
+++ b/include/internal/catch_tostring.hpp
@@ -161,9 +161,13 @@ inline std::string toString( std::nullptr_t ) {
 
 #ifdef __OBJC__
     inline std::string toString( NSString const * const& nsstring ) {
+        if( !nsstring )
+            return "nil";
         return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
     }
     inline std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) {
+        if( !nsstring )
+            return "nil";
         return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
     }
     inline std::string toString( NSObject* const& nsObject ) {
diff --git a/projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm b/projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm
index 9fdb17a7..1ed7aa5f 100644
--- a/projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm
+++ b/projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm
@@ -74,4 +74,9 @@ OC_TEST_CASE( "OCTest/matchers", "Matches work with OC types (NSString so far)"
     REQUIRE_THAT( @"This is a string", EndsWith( @"string" ) );
 }
 
+OC_TEST_CASE( "OCTest/matchers/nil", "nil NSString should not crash the test" )
+{
+    REQUIRE_THAT( (NSString*)nil, Equals( @"This should fail, but not crash" ) );
+}
+
 @end