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

Fixed toString for NSString* in Xcode 4.4

Commit
0dc9e43c02daad6fd09f549db3b7933777b6a4db
Author
Phil Nash ·
Parents
61756974d024

Files · Download .tar.gz

Changes

 include/internal/catch_objc.hpp                    | 41 +--------
 include/internal/catch_objc_arc.hpp                | 47 +++++++++++
 include/internal/catch_tostring.hpp                | 19 +++++
 .../CatchSelfTest.xcodeproj/project.pbxproj        |  2 +
 .../XCode4/OCTest/OCTest.xcodeproj/project.pbxproj |  6 ++
 projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm   |  2 +-
 single_include/catch.hpp                           | 98 +++++++++++++---------
 7 files changed, 135 insertions(+), 80 deletions(-)

diff --git a/include/internal/catch_objc.hpp b/include/internal/catch_objc.hpp
index 36e870e8..d4709acf 100644
--- a/include/internal/catch_objc.hpp
+++ b/include/internal/catch_objc.hpp
@@ -8,7 +8,8 @@
 #ifndef TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
 #define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
 
-#import <Foundation/Foundation.h>
+#include "catch_objc_arc.hpp"
+
 #import <objc/runtime.h>
 
 #include <string>
@@ -18,38 +19,6 @@
 // header for non obj-usage
 #include "internal/catch_test_case_info.hpp"
 
-#ifdef __has_feature
-#define CATCH_ARC_ENABLED __has_feature(objc_arc)
-#else
-#define CATCH_ARC_ENABLED 0
-#endif
-
-void arcSafeRelease( NSObject* obj );
-id performOptionalSelector( id obj, SEL sel );
-
-#if !CATCH_ARC_ENABLED
-    inline void arcSafeRelease( NSObject* obj ) {
-        [obj release];
-    }
-    inline id performOptionalSelector( id obj, SEL sel ) {
-        if( [obj respondsToSelector: sel] )
-            return [obj performSelector: sel];
-        return nil;
-    }
-    #define CATCH_UNSAFE_UNRETAINED
-#else
-    inline void arcSafeRelease( NSObject* ){}
-    inline id performOptionalSelector( id obj, SEL sel ) {
-    #pragma clang diagnostic push
-    #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
-        if( [obj respondsToSelector: sel] )
-            return [obj performSelector: sel];
-    #pragma clang diagnostic pop     
-        return nil;
-    }
-    #define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
-#endif
-
 ///////////////////////////////////////////////////////////////////////////////
 // This protocol is really only here for (self) documenting purposes, since
 // all its methods are optional.
@@ -147,10 +116,6 @@ namespace Catch {
         return noTestMethods;
     }
     
-    inline std::string toString( NSString* const& nsstring ) {
-        return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
-    }
-    
     namespace Matchers {
         namespace Impl {
         namespace NSStringMatchers {
@@ -161,7 +126,7 @@ namespace Catch {
                     arcSafeRelease( m_substr );
                 }
                 
-                NSString* m_substr;            
+                NSString* m_substr;
             };
             
             struct Equals : StringHolder {
diff --git a/include/internal/catch_objc_arc.hpp b/include/internal/catch_objc_arc.hpp
new file mode 100644
index 00000000..38f4a160
--- /dev/null
+++ b/include/internal/catch_objc_arc.hpp
@@ -0,0 +1,47 @@
+/*
+ *  Created by Phil on 1/08/2012.
+ *  Copyright 2012 Two Blue Cubes Ltd. All rights reserved.
+ *
+ *  Distributed under the Boost Software License, Version 1.0. (See accompanying
+ *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+#ifndef TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED
+#define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED
+
+#import <Foundation/Foundation.h>
+
+#ifdef __has_feature
+#define CATCH_ARC_ENABLED __has_feature(objc_arc)
+#else
+#define CATCH_ARC_ENABLED 0
+#endif
+
+void arcSafeRelease( NSObject* obj );
+id performOptionalSelector( id obj, SEL sel );
+
+#if !CATCH_ARC_ENABLED
+inline void arcSafeRelease( NSObject* obj ) {
+    [obj release];
+}
+inline id performOptionalSelector( id obj, SEL sel ) {
+    if( [obj respondsToSelector: sel] )
+        return [obj performSelector: sel];
+    return nil;
+}
+#define CATCH_UNSAFE_UNRETAINED
+#define CATCH_ARC_STRONG
+#else
+inline void arcSafeRelease( NSObject* ){}
+inline id performOptionalSelector( id obj, SEL sel ) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
+    if( [obj respondsToSelector: sel] )
+        return [obj performSelector: sel];
+#pragma clang diagnostic pop
+    return nil;
+}
+#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
+#define CATCH_ARC_STRONG __strong
+#endif
+
+#endif // TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED
diff --git a/include/internal/catch_tostring.hpp b/include/internal/catch_tostring.hpp
index 9b4cf9b3..455e186a 100644
--- a/include/internal/catch_tostring.hpp
+++ b/include/internal/catch_tostring.hpp
@@ -11,6 +11,10 @@
 #include "catch_common.h"
 #include <sstream>
 
+#ifdef __OBJC__
+#include "catch_objc_arc.hpp"
+#endif
+
 namespace Catch {
 namespace Detail {
 
@@ -131,6 +135,21 @@ inline std::string toString( std::nullptr_t ) {
 }
 #endif
 
+#ifdef __OBJC__
+    //    inline std::string toString( NSString* const& nsstring ) {
+    //        return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
+    //    }
+    inline std::string toString( NSString const * const& nsstring ) {
+        return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
+    }
+    inline std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) {
+        return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
+    }
+    inline std::string toString( NSObject* const& nsObject ) {
+        return toString( [nsObject description] );
+    }
+#endif
+
 } // end namespace Catch
 
 #endif // TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj
index 99e642a0..a3f0aeb0 100644
--- a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj
+++ b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj
@@ -92,6 +92,7 @@
 		4AB77CB51551AEA200857BF0 /* catch_ptr.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_ptr.hpp; sourceTree = "<group>"; };
 		4AB77CB71553B72B00857BF0 /* catch_section_info.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_section_info.hpp; sourceTree = "<group>"; };
 		4AB77CB81553BB3800857BF0 /* catch_running_test.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_running_test.hpp; sourceTree = "<group>"; };
+		4ABEA80415C90D2B009F0424 /* catch_objc_arc.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_objc_arc.hpp; sourceTree = "<group>"; };
 		4AC91CCE155CF02800DC5117 /* catch_expression.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_expression.hpp; sourceTree = "<group>"; };
 		4AC91CD0155D8DA600DC5117 /* catch_expression_builder.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_expression_builder.hpp; sourceTree = "<group>"; };
 		4AE1840A14EE4F230066340D /* catch_self_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_self_test.cpp; path = ../../../SelfTest/catch_self_test.cpp; sourceTree = "<group>"; };
@@ -287,6 +288,7 @@
 			isa = PBXGroup;
 			children = (
 				4A6D0C59149B3E3D00DB3EAA /* catch_objc.hpp */,
+				4ABEA80415C90D2B009F0424 /* catch_objc_arc.hpp */,
 			);
 			name = "Objective-C";
 			sourceTree = "<group>";
diff --git a/projects/XCode4/OCTest/OCTest.xcodeproj/project.pbxproj b/projects/XCode4/OCTest/OCTest.xcodeproj/project.pbxproj
index 3e5f8aee..d6db4ae8 100644
--- a/projects/XCode4/OCTest/OCTest.xcodeproj/project.pbxproj
+++ b/projects/XCode4/OCTest/OCTest.xcodeproj/project.pbxproj
@@ -39,6 +39,8 @@
 		4A63D2C414E454CC00F615CB /* TestObj.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestObj.h; sourceTree = "<group>"; };
 		4A63D2C514E454CC00F615CB /* TestObj.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestObj.m; sourceTree = "<group>"; };
 		4AA0D951154C0A7A004B4193 /* catch_objc.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_objc.hpp; path = ../../../include/internal/catch_objc.hpp; sourceTree = "<group>"; };
+		4ABEA80615C90E10009F0424 /* catch_objc_arc.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_objc_arc.hpp; path = ../../../include/internal/catch_objc_arc.hpp; sourceTree = "<group>"; };
+		4ABEA80815C90E38009F0424 /* catch_tostring.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_tostring.hpp; path = ../../../include/internal/catch_tostring.hpp; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -88,6 +90,8 @@
 		4AA0D94F154C0A63004B4193 /* Catch */ = {
 			isa = PBXGroup;
 			children = (
+				4ABEA80815C90E38009F0424 /* catch_tostring.hpp */,
+				4ABEA80615C90E10009F0424 /* catch_objc_arc.hpp */,
 				4AA0D951154C0A7A004B4193 /* catch_objc.hpp */,
 			);
 			name = Catch;
@@ -204,6 +208,7 @@
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				CLANG_ENABLE_OBJC_ARC = YES;
+				HEADER_SEARCH_PATHS = ../../../single_include;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Debug;
@@ -212,6 +217,7 @@
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				CLANG_ENABLE_OBJC_ARC = YES;
+				HEADER_SEARCH_PATHS = ../../../single_include;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Release;
diff --git a/projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm b/projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm
index 032660f3..9fdb17a7 100644
--- a/projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm
+++ b/projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm
@@ -68,7 +68,7 @@ void useObject( const T* object ){}
 
 OC_TEST_CASE( "OCTest/matchers", "Matches work with OC types (NSString so far)" )
 {
-    REQUIRE_THAT( @"This is a string", Equals( @"This is a string" ) );
+    REQUIRE_THAT( @"This is a string", Equals( @"This isnt a string" ) );
     REQUIRE_THAT( @"This is a string", Contains( @"is a" ) );
     REQUIRE_THAT( @"This is a string", StartsWith( @"This" ) );
     REQUIRE_THAT( @"This is a string", EndsWith( @"string" ) );
diff --git a/single_include/catch.hpp b/single_include/catch.hpp
index 50331889..2ded49bd 100644
--- a/single_include/catch.hpp
+++ b/single_include/catch.hpp
@@ -1,5 +1,5 @@
 /*
- *  Generated: 2012-07-28 20:36:23.213113
+ *  Generated: 2012-08-01 08:15:06.796335
  *  ----------------------------------------------------------
  *  This file has been merged from multiple headers. Please don't edit it directly
  *  Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
@@ -553,6 +553,47 @@ private:
 
 #include <sstream>
 
+#ifdef __OBJC__
+// #included from: catch_objc_arc.hpp
+
+#import <Foundation/Foundation.h>
+
+#ifdef __has_feature
+#define CATCH_ARC_ENABLED __has_feature(objc_arc)
+#else
+#define CATCH_ARC_ENABLED 0
+#endif
+
+void arcSafeRelease( NSObject* obj );
+id performOptionalSelector( id obj, SEL sel );
+
+#if !CATCH_ARC_ENABLED
+inline void arcSafeRelease( NSObject* obj ) {
+    [obj release];
+}
+inline id performOptionalSelector( id obj, SEL sel ) {
+    if( [obj respondsToSelector: sel] )
+        return [obj performSelector: sel];
+    return nil;
+}
+#define CATCH_UNSAFE_UNRETAINED
+#define CATCH_ARC_STRONG
+#else
+inline void arcSafeRelease( NSObject* ){}
+inline id performOptionalSelector( id obj, SEL sel ) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
+    if( [obj respondsToSelector: sel] )
+        return [obj performSelector: sel];
+#pragma clang diagnostic pop
+    return nil;
+}
+#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
+#define CATCH_ARC_STRONG __strong
+#endif
+
+#endif
+
 namespace Catch {
 namespace Detail {
 
@@ -673,6 +714,21 @@ inline std::string toString( std::nullptr_t ) {
 }
 #endif
 
+#ifdef __OBJC__
+    //    inline std::string toString( NSString* const& nsstring ) {
+    //        return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
+    //    }
+    inline std::string toString( NSString const * const& nsstring ) {
+        return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
+    }
+    inline std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) {
+        return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
+    }
+    inline std::string toString( NSObject* const& nsObject ) {
+        return toString( [nsObject description] );
+    }
+#endif
+
 } // end namespace Catch
 
 // #included from: catch_resultinfo.hpp
@@ -2084,7 +2140,6 @@ namespace Catch {
 #ifdef __OBJC__
 // #included from: internal/catch_objc.hpp
 
-#import <Foundation/Foundation.h>
 #import <objc/runtime.h>
 
 #include <string>
@@ -2093,38 +2148,6 @@ namespace Catch {
 // in catch.hpp first to make sure they are included by the single
 // header for non obj-usage
 
-#ifdef __has_feature
-#define CATCH_ARC_ENABLED __has_feature(objc_arc)
-#else
-#define CATCH_ARC_ENABLED 0
-#endif
-
-void arcSafeRelease( NSObject* obj );
-id performOptionalSelector( id obj, SEL sel );
-
-#if !CATCH_ARC_ENABLED
-    inline void arcSafeRelease( NSObject* obj ) {
-        [obj release];
-    }
-    inline id performOptionalSelector( id obj, SEL sel ) {
-        if( [obj respondsToSelector: sel] )
-            return [obj performSelector: sel];
-        return nil;
-    }
-    #define CATCH_UNSAFE_UNRETAINED
-#else
-    inline void arcSafeRelease( NSObject* ){}
-    inline id performOptionalSelector( id obj, SEL sel ) {
-    #pragma clang diagnostic push
-    #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
-        if( [obj respondsToSelector: sel] )
-            return [obj performSelector: sel];
-    #pragma clang diagnostic pop
-        return nil;
-    }
-    #define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
-#endif
-
 ///////////////////////////////////////////////////////////////////////////////
 // This protocol is really only here for (self) documenting purposes, since
 // all its methods are optional.
@@ -2222,13 +2245,6 @@ namespace Catch {
         return noTestMethods;
     }
 
-    inline std::string toString( NSString* const& nsstring ) {
-        return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
-    }
-    inline std::string toString( NSObject* const& nsObject ) {
-        return toString( [nsObject description] );
-    }
-
     namespace Matchers {
         namespace Impl {
         namespace NSStringMatchers {