diff --git a/Bundle/GoogleTests.mm b/Bundle/GoogleTests.mm index 069a123..52ac0d8 100644 --- a/Bundle/GoogleTests.mm +++ b/Bundle/GoogleTests.mm @@ -85,6 +85,7 @@ void OnTestPartResult(const TestPartResult& test_part_result) { * Google Test cases or individual tests via Xcode. */ @interface GoogleTestLoader : NSObject ++ (void)registerTestClasses; @end /** @@ -95,6 +96,11 @@ @interface GoogleTestCase : XCTestCase @implementation GoogleTestCase ++ (void)initialize +{ + [GoogleTestLoader registerTestClasses]; +} + /** * Associates generated Google Test classes with the test bundle. * @@ -172,11 +178,15 @@ @implementation GoogleTestLoader + (void)load { NSBundle *bundle = [NSBundle bundleForClass:self]; [[NSNotificationCenter defaultCenter] addObserverForName:NSBundleDidLoadNotification object:bundle queue:nil usingBlock:^(NSNotification *notification) { - [self registerTestClasses]; + [GoogleTestCase initialize]; }]; } + (void)registerTestClasses { + if ([GoogleTestFilterMap count]) { + return; + } + // Pass the command-line arguments to Google Test to support the --gtest options NSArray *arguments = [[NSProcessInfo processInfo] arguments]; @@ -241,6 +251,10 @@ + (void)registerTestClasses { methodName = [@"_" stringByAppendingString:methodName]; } + // Google Test set test method name in parameterized tests to /. + // Replace / with a _ to create a valid method name. + methodName = [methodName stringByReplacingOccurrencesOfString:@"/" withString:@"_"]; + NSString *testKey = [NSString stringWithFormat:@"%@.%@", className, methodName]; NSString *testFilter = [NSString stringWithFormat:@"%@.%@", testCaseName, testName]; testFilterMap[testKey] = testFilter;