From 7d49314feeab0a4c96abd6c6b704d445899f1fa5 Mon Sep 17 00:00:00 2001 From: Sundeep Date: Tue, 10 Sep 2019 09:19:41 -0700 Subject: Fix failure due to adding same method more than once (#245) --- UnitTesting/GTMGoogleTestRunner.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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]; -- cgit v1.2.3