mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 11:43:29 +01:00
Fixed Objective-C mode
This commit is contained in:
parent
8d03cb4915
commit
2d37649377
@ -42,6 +42,7 @@
|
|||||||
#include "internal/catch_interfaces_exception.h"
|
#include "internal/catch_interfaces_exception.h"
|
||||||
#include "internal/catch_approx.hpp"
|
#include "internal/catch_approx.hpp"
|
||||||
#include "internal/catch_compiler_capabilities.h"
|
#include "internal/catch_compiler_capabilities.h"
|
||||||
|
#include "internal/catch_string_manip.h"
|
||||||
|
|
||||||
#ifndef CATCH_CONFIG_DISABLE_MATCHERS
|
#ifndef CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
#include "internal/catch_capture_matchers.h"
|
#include "internal/catch_capture_matchers.h"
|
||||||
|
@ -32,7 +32,7 @@ int main (int argc, char * const argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
Catch::registerTestMethods();
|
Catch::registerTestMethods();
|
||||||
int result = Catch::Session().run( argc, (char* const*)argv );
|
int result = Catch::Session().run( argc, (char**)argv );
|
||||||
|
|
||||||
#if !CATCH_ARC_ENABLED
|
#if !CATCH_ARC_ENABLED
|
||||||
[pool drain];
|
[pool drain];
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
// in catch.hpp first to make sure they are included by the single
|
// in catch.hpp first to make sure they are included by the single
|
||||||
// header for non obj-usage
|
// header for non obj-usage
|
||||||
#include "catch_test_case_info.h"
|
#include "catch_test_case_info.h"
|
||||||
|
#include "catch_string_manip.h"
|
||||||
|
#include "catch_tostring.h"
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// This protocol is really only here for (self) documenting purposes, since
|
// This protocol is really only here for (self) documenting purposes, since
|
||||||
@ -91,7 +93,7 @@ namespace Catch {
|
|||||||
std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
|
std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
|
||||||
const char* className = class_getName( cls );
|
const char* className = class_getName( cls );
|
||||||
|
|
||||||
getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) );
|
getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo("",0) ) );
|
||||||
noTestMethods++;
|
noTestMethods++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,7 +120,7 @@ namespace Catch {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString* m_substr;
|
NSString* CATCH_ARC_STRONG m_substr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Equals : StringHolder {
|
struct Equals : StringHolder {
|
||||||
@ -130,7 +132,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string describe() const override {
|
std::string describe() const override {
|
||||||
return "equals string: " + Catch::toString( m_substr );
|
return "equals string: " + Catch::Detail::stringify( m_substr );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -143,7 +145,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string describe() const override {
|
std::string describe() const override {
|
||||||
return "contains string: " + Catch::toString( m_substr );
|
return "contains string: " + Catch::Detail::stringify( m_substr );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -156,7 +158,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string describe() const override {
|
std::string describe() const override {
|
||||||
return "starts with: " + Catch::toString( m_substr );
|
return "starts with: " + Catch::Detail::stringify( m_substr );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct EndsWith : StringHolder {
|
struct EndsWith : StringHolder {
|
||||||
@ -168,7 +170,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string describe() const override {
|
std::string describe() const override {
|
||||||
return "ends with: " + Catch::toString( m_substr );
|
return "ends with: " + Catch::Detail::stringify( m_substr );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -196,15 +198,18 @@ namespace Catch {
|
|||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define OC_TEST_CASE( name, desc )\
|
#define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix
|
||||||
+(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \
|
#define OC_TEST_CASE2( name, desc, uniqueSuffix ) \
|
||||||
{\
|
+(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \
|
||||||
|
{ \
|
||||||
return @ name; \
|
return @ name; \
|
||||||
}\
|
} \
|
||||||
+(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \
|
+(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \
|
||||||
{ \
|
{ \
|
||||||
return @ desc; \
|
return @ desc; \
|
||||||
} \
|
} \
|
||||||
-(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test )
|
-(void) OC_MAKE_UNIQUE_NAME( Catch_TestCase_test_, uniqueSuffix )
|
||||||
|
|
||||||
|
#define OC_TEST_CASE( name, desc ) OC_TEST_CASE2( name, desc, __LINE__ )
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
|
||||||
|
@ -210,20 +210,4 @@ std::string StringMaker<double>::convert(double value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __OBJC__
|
|
||||||
std::string StringMaker<NSString*>::convert(NSString* nsstring) {
|
|
||||||
if (!nsstring)
|
|
||||||
return "nil";
|
|
||||||
return "@" + toString([nsstring UTF8String]);
|
|
||||||
}
|
|
||||||
std::string StringMaker<NSString * CATCH_ARC_STRONG>::convert(NSString* CATCH_ARC_STRONG nsstring) {
|
|
||||||
if (!nsstring)
|
|
||||||
return "nil";
|
|
||||||
return "@" + toString([nsstring UTF8String]);
|
|
||||||
}
|
|
||||||
std::string StringMaker<NSObject*>::convert(NSObject* nsObject) {
|
|
||||||
return ::Catch::Detail::stringify([nsObject description]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
@ -299,17 +299,26 @@ namespace Catch {
|
|||||||
#ifdef __OBJC__
|
#ifdef __OBJC__
|
||||||
template<>
|
template<>
|
||||||
struct StringMaker<NSString*> {
|
struct StringMaker<NSString*> {
|
||||||
static std::string convert(NSString* nsstring);
|
static std::string convert(NSString * nsstring) {
|
||||||
|
if (!nsstring)
|
||||||
|
return "nil";
|
||||||
|
return std::string("@") + [nsstring UTF8String];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
struct StringMaker<NSString* CATCH_ARC_STRONG> {
|
struct StringMaker<NSObject*> {
|
||||||
static std::string convert(NSString * CATCH_ARC_STRONG nsstring);
|
static std::string convert(NSObject* nsObject) {
|
||||||
|
return ::Catch::Detail::stringify([nsObject description]);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
template<>
|
namespace Detail {
|
||||||
struct StringMaker<NSObject *> {
|
inline std::string stringify( NSString* nsstring ) {
|
||||||
static std::string convert(NSObject* nsObject);
|
return StringMaker<NSString*>::convert( nsstring );
|
||||||
};
|
}
|
||||||
#endif
|
|
||||||
|
} // namespace Detail
|
||||||
|
#endif // __OBJC__
|
||||||
|
|
||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
Loading…
Reference in New Issue
Block a user