aboutsummaryrefslogtreecommitdiff
path: root/UnitTesting
diff options
context:
space:
mode:
authorGravatar thomasvl <thomasvl@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2014-10-29 15:37:02 +0000
committerGravatar thomasvl <thomasvl@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2014-10-29 15:37:02 +0000
commit182f17ea25a3a9e7170312d6b1598d30735558fd (patch)
treed4e64aacdffaa01687c18a54d91f014e2a541dbd /UnitTesting
parentd23d29b6967f0310478eaa1f33180d02b6780a89 (diff)
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.
Diffstat (limited to 'UnitTesting')
-rw-r--r--UnitTesting/GTMGoogleTestRunner.mm27
1 files changed, 26 insertions, 1 deletions
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 <SenTestingKit/SenTestingKit.h>
#endif // GTM_USING_XCTEST
+#import <objc/runtime.h>
+
#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;