diff options
author | Sundeep <sskhandp@google.com> | 2019-09-10 09:19:41 -0700 |
---|---|---|
committer | dmaclach <dmaclach@gmail.com> | 2019-09-10 09:19:41 -0700 |
commit | 7d49314feeab0a4c96abd6c6b704d445899f1fa5 (patch) | |
tree | 83fc346a3ed783226eb93e3e44504fae28213428 | |
parent | 2a736c162f20a83e0990917e8e80980653adbe87 (diff) |
Fix failure due to adding same method more than once (#245)
-rw-r--r-- | UnitTesting/GTMGoogleTestRunner.mm | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/UnitTesting/GTMGoogleTestRunner.mm b/UnitTesting/GTMGoogleTestRunner.mm index 302bc28..6465d07 100644 --- a/UnitTesting/GTMGoogleTestRunner.mm +++ b/UnitTesting/GTMGoogleTestRunner.mm @@ -175,7 +175,10 @@ NSString *SelectorNameFromGTestName(NSString *testName) { 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)) { + // We may be called more than once for the same testName. Check before adding new method to avoid + // failure from adding multiple methods with the same name. + if (!class_getInstanceMethod(cls, selector) && + !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]; |