mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-02 13:25:41 +02:00
Remove Obj-C(++) support
This commit is contained in:
@@ -84,8 +84,6 @@ set(INTERNAL_HEADERS
|
||||
${SOURCES_DIR}/matchers/catch_matchers_vector.hpp
|
||||
${SOURCES_DIR}/catch_message.hpp
|
||||
${SOURCES_DIR}/internal/catch_meta.hpp
|
||||
${SOURCES_DIR}/catch_objc.hpp
|
||||
${SOURCES_DIR}/catch_objc_arc.hpp
|
||||
${SOURCES_DIR}/internal/catch_option.hpp
|
||||
${SOURCES_DIR}/internal/catch_output_redirect.hpp
|
||||
${SOURCES_DIR}/internal/catch_platform.hpp
|
||||
|
@@ -1,212 +0,0 @@
|
||||
/*
|
||||
* Created by Phil on 14/11/2010.
|
||||
* Copyright 2010 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_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
|
||||
|
||||
#include <catch2/catch_objc_arc.hpp>
|
||||
|
||||
#import <objc/runtime.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
// NB. Any general catch headers included here must be included
|
||||
// in catch.hpp first to make sure they are included by the single
|
||||
// header for non obj-usage
|
||||
#include <catch2/catch_test_case_info.hpp>
|
||||
#include <catch2/internal/catch_string_manip.hpp>
|
||||
#include <catch2/catch_tostring.hpp>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// This protocol is really only here for (self) documenting purposes, since
|
||||
// all its methods are optional.
|
||||
@protocol OcFixture
|
||||
|
||||
@optional
|
||||
|
||||
-(void) setUp;
|
||||
-(void) tearDown;
|
||||
|
||||
@end
|
||||
|
||||
namespace Catch {
|
||||
|
||||
class OcMethod : public ITestInvoker {
|
||||
|
||||
public:
|
||||
OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {}
|
||||
|
||||
virtual void invoke() const {
|
||||
id obj = [[m_cls alloc] init];
|
||||
|
||||
performOptionalSelector( obj, @selector(setUp) );
|
||||
performOptionalSelector( obj, m_sel );
|
||||
performOptionalSelector( obj, @selector(tearDown) );
|
||||
|
||||
arcSafeRelease( obj );
|
||||
}
|
||||
private:
|
||||
virtual ~OcMethod() {}
|
||||
|
||||
Class m_cls;
|
||||
SEL m_sel;
|
||||
};
|
||||
|
||||
namespace Detail{
|
||||
|
||||
|
||||
inline std::string getAnnotation( Class cls,
|
||||
std::string const& annotationName,
|
||||
std::string const& testCaseName ) {
|
||||
NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
|
||||
SEL sel = NSSelectorFromString( selStr );
|
||||
arcSafeRelease( selStr );
|
||||
id value = performOptionalSelector( cls, sel );
|
||||
if( value )
|
||||
return [(NSString*)value UTF8String];
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
inline std::size_t registerTestMethods() {
|
||||
std::size_t noTestMethods = 0;
|
||||
int noClasses = objc_getClassList( nullptr, 0 );
|
||||
|
||||
Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
|
||||
objc_getClassList( classes, noClasses );
|
||||
|
||||
for( int c = 0; c < noClasses; c++ ) {
|
||||
Class cls = classes[c];
|
||||
{
|
||||
u_int count;
|
||||
Method* methods = class_copyMethodList( cls, &count );
|
||||
for( u_int m = 0; m < count ; m++ ) {
|
||||
SEL selector = method_getName(methods[m]);
|
||||
std::string methodName = sel_getName(selector);
|
||||
if( startsWith( methodName, "Catch_TestCase_" ) ) {
|
||||
std::string testCaseName = methodName.substr( 15 );
|
||||
std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
|
||||
std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
|
||||
const char* className = class_getName( cls );
|
||||
|
||||
getMutableRegistryHub().registerTest( makeTestCaseInfo( new OcMethod( cls, selector ), className, NameAndTags( name.c_str(), desc.c_str() ), SourceLineInfo("",0) ) );
|
||||
noTestMethods++;
|
||||
}
|
||||
}
|
||||
free(methods);
|
||||
}
|
||||
}
|
||||
return noTestMethods;
|
||||
}
|
||||
|
||||
|
||||
namespace Matchers {
|
||||
namespace Impl {
|
||||
namespace NSStringMatchers {
|
||||
|
||||
struct StringHolder : MatcherBase<NSString*>{
|
||||
StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
|
||||
StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
|
||||
StringHolder() {
|
||||
arcSafeRelease( m_substr );
|
||||
}
|
||||
|
||||
bool match( NSString* str ) const override {
|
||||
return false;
|
||||
}
|
||||
|
||||
NSString* CATCH_ARC_STRONG m_substr;
|
||||
};
|
||||
|
||||
struct Equals : StringHolder {
|
||||
Equals( NSString* substr ) : StringHolder( substr ){}
|
||||
|
||||
bool match( NSString* str ) const override {
|
||||
return (str != nil || m_substr == nil ) &&
|
||||
[str isEqualToString:m_substr];
|
||||
}
|
||||
|
||||
std::string describe() const override {
|
||||
return "equals string: " + Catch::Detail::stringify( m_substr );
|
||||
}
|
||||
};
|
||||
|
||||
struct Contains : StringHolder {
|
||||
Contains( NSString* substr ) : StringHolder( substr ){}
|
||||
|
||||
bool match( NSString* str ) const override {
|
||||
return (str != nil || m_substr == nil ) &&
|
||||
[str rangeOfString:m_substr].location != NSNotFound;
|
||||
}
|
||||
|
||||
std::string describe() const override {
|
||||
return "contains string: " + Catch::Detail::stringify( m_substr );
|
||||
}
|
||||
};
|
||||
|
||||
struct StartsWith : StringHolder {
|
||||
StartsWith( NSString* substr ) : StringHolder( substr ){}
|
||||
|
||||
bool match( NSString* str ) const override {
|
||||
return (str != nil || m_substr == nil ) &&
|
||||
[str rangeOfString:m_substr].location == 0;
|
||||
}
|
||||
|
||||
std::string describe() const override {
|
||||
return "starts with: " + Catch::Detail::stringify( m_substr );
|
||||
}
|
||||
};
|
||||
struct EndsWith : StringHolder {
|
||||
EndsWith( NSString* substr ) : StringHolder( substr ){}
|
||||
|
||||
bool match( NSString* str ) const override {
|
||||
return (str != nil || m_substr == nil ) &&
|
||||
[str rangeOfString:m_substr].location == [str length] - [m_substr length];
|
||||
}
|
||||
|
||||
std::string describe() const override {
|
||||
return "ends with: " + Catch::Detail::stringify( m_substr );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace NSStringMatchers
|
||||
} // namespace Impl
|
||||
|
||||
inline Impl::NSStringMatchers::Equals
|
||||
Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
|
||||
|
||||
inline Impl::NSStringMatchers::Contains
|
||||
Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
|
||||
|
||||
inline Impl::NSStringMatchers::StartsWith
|
||||
StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
|
||||
|
||||
inline Impl::NSStringMatchers::EndsWith
|
||||
EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
|
||||
|
||||
} // namespace Matchers
|
||||
|
||||
using namespace Matchers;
|
||||
|
||||
} // namespace Catch
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix
|
||||
#define OC_TEST_CASE2( name, desc, uniqueSuffix ) \
|
||||
+(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \
|
||||
{ \
|
||||
return @ name; \
|
||||
} \
|
||||
+(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \
|
||||
{ \
|
||||
return @ desc; \
|
||||
} \
|
||||
-(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
|
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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 ) {
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
|
||||
#endif
|
||||
if( [obj respondsToSelector: sel] )
|
||||
return [obj performSelector: sel];
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
return nil;
|
||||
}
|
||||
#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
|
||||
#define CATCH_ARC_STRONG __strong
|
||||
#endif
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED
|
@@ -21,10 +21,6 @@
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
#ifdef __OBJC__
|
||||
#include <catch2/catch_objc_arc.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless
|
||||
@@ -323,30 +319,6 @@ namespace Catch {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __OBJC__
|
||||
template<>
|
||||
struct StringMaker<NSString*> {
|
||||
static std::string convert(NSString * nsstring) {
|
||||
if (!nsstring)
|
||||
return "nil";
|
||||
return std::string("@") + [nsstring UTF8String];
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct StringMaker<NSObject*> {
|
||||
static std::string convert(NSObject* nsObject) {
|
||||
return ::Catch::Detail::stringify([nsObject description]);
|
||||
}
|
||||
|
||||
};
|
||||
namespace Detail {
|
||||
inline std::string stringify( NSString* nsstring ) {
|
||||
return StringMaker<NSString*>::convert( nsstring );
|
||||
}
|
||||
|
||||
} // namespace Detail
|
||||
#endif // __OBJC__
|
||||
|
||||
} // namespace Catch
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
|
@@ -20,8 +20,6 @@ namespace Catch {
|
||||
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
|
||||
}
|
||||
|
||||
#ifndef __OBJC__
|
||||
|
||||
#if defined(CATCH_CONFIG_WCHAR) && defined(CATCH_PLATFORM_WINDOWS) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN)
|
||||
// Standard C/C++ Win32 Unicode wmain entry point
|
||||
extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) {
|
||||
@@ -37,24 +35,4 @@ int main (int argc, char * argv[]) {
|
||||
return Catch::Session().run( argc, argv );
|
||||
}
|
||||
|
||||
#else // __OBJC__
|
||||
|
||||
// Objective-C entry point
|
||||
int main (int argc, char * const argv[]) {
|
||||
#if !CATCH_ARC_ENABLED
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
#endif
|
||||
|
||||
Catch::registerTestMethods();
|
||||
int result = Catch::Session().run( argc, (char**)argv );
|
||||
|
||||
#if !CATCH_ARC_ENABLED
|
||||
[pool drain];
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // __OBJC__
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED
|
||||
|
@@ -11,10 +11,6 @@
|
||||
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
||||
#include <catch2/internal/catch_enforce.hpp>
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import "Foundation/Foundation.h"
|
||||
#endif
|
||||
|
||||
namespace Catch {
|
||||
|
||||
ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() {
|
||||
@@ -27,15 +23,6 @@ namespace Catch {
|
||||
#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
|
||||
std::string ExceptionTranslatorRegistry::translateActiveException() const {
|
||||
try {
|
||||
#ifdef __OBJC__
|
||||
// In Objective-C try objective-c exceptions first
|
||||
@try {
|
||||
return tryTranslators();
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
return Catch::Detail::stringify( [exception description] );
|
||||
}
|
||||
#else
|
||||
// Compiling a mixed mode project with MSVC means that CLR
|
||||
// exceptions will be caught in (...) as well. However, these
|
||||
// do not fill-in std::current_exception and thus lead to crash
|
||||
@@ -48,7 +35,6 @@ namespace Catch {
|
||||
return "Non C++ exception. Possibly a CLR exception.";
|
||||
}
|
||||
return tryTranslators();
|
||||
#endif
|
||||
}
|
||||
catch( TestFailureException& ) {
|
||||
std::rethrow_exception(std::current_exception());
|
||||
|
@@ -37,15 +37,6 @@ namespace Matchers {
|
||||
virtual bool match(ObjectT const& arg) const = 0;
|
||||
};
|
||||
|
||||
#if defined(__OBJC__)
|
||||
// Hack to fix Catch GH issue #1661. Could use id for generic Object support.
|
||||
// use of const for Object pointers is very uncommon and under ARC it causes some kind of signature mismatch that breaks compilation
|
||||
template<>
|
||||
struct MatcherMethod<NSString*> {
|
||||
virtual bool match(NSString* arg) const = 0;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user