From 182f17ea25a3a9e7170312d6b1598d30735558fd Mon Sep 17 00:00:00 2001 From: thomasvl Date: Wed, 29 Oct 2014 15:37:02 +0000 Subject: Fix up GTMGoogleTestRunner for Xcode 6.1. - We now add selectors to the class because Xcode 6.1 appears to take the test name from the selector instead of from the -[XCTest name] method. --- UnitTesting/GTMGoogleTestRunner.mm | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'UnitTesting') diff --git a/UnitTesting/GTMGoogleTestRunner.mm b/UnitTesting/GTMGoogleTestRunner.mm index 4539aa0..494a073 100644 --- a/UnitTesting/GTMGoogleTestRunner.mm +++ b/UnitTesting/GTMGoogleTestRunner.mm @@ -60,6 +60,8 @@ #import #endif // GTM_USING_XCTEST +#import + #include "third_party/gtest/include/gtest/gtest.h" using ::testing::EmptyTestEventListener; @@ -114,6 +116,13 @@ class GoogleTestPrinter : public EmptyTestEventListener { SenTestCase *test_case_; }; +NSString *SelectorNameFromGTestName(NSString *testName) { + NSRange dot = [testName rangeOfString:@"."]; + return [NSString stringWithFormat:@"%@::%@", + [testName substringToIndex:dot.location], + [testName substringFromIndex:dot.location + 1]]; +} + } // namespace // GTMGoogleTestRunner is a GTMTestCase that makes a sub test suite populated @@ -158,7 +167,23 @@ class GoogleTestPrinter : public EmptyTestEventListener { } - (id)initWithName:(NSString *)testName { - if ((self = [super initWithSelector:@selector(runGoogleTest)])) { + // Xcode 6.1 started taking the testName from the selector instead of calling + // -name. + // So we will add selectors to GTMGoogleTestRunner. + // They should all be unique because the selectors are named cppclass.method + // Filed as radar 18798444. + Class cls = [self class]; + NSString *selectorTestName = SelectorNameFromGTestName(testName); + SEL selector = sel_registerName([selectorTestName UTF8String]); + Method method = class_getInstanceMethod(cls, @selector(runGoogleTest)); + IMP implementation = method_getImplementation(method); + const char *encoding = method_getTypeEncoding(method); + if (!class_addMethod(cls, selector, implementation, encoding)) { + // If we can't add a method, we should blow up here. + [NSException raise:NSInternalInconsistencyException + format:@"Unable to add %@ to %@.", testName, cls]; + } + if ((self = [super initWithSelector:selector])) { testName_ = testName; } return self; -- cgit v1.2.3