Skip to content

Conversation

@ExtremeMan
Copy link

Current implementation isn't compatible with xctool and Xcode 7 because xctool couldn't query test cases.
This PR fixes it.

Test plan:

xctool -project GoogleTestExample.xcodeproj/ -scheme demo -sdk iphonesimulator test

# before these changes
[Info] Collecting info for testables... (889 ms)
run-test TestBundle.xctest (iphonesimulator9.0, iPhone 4s, logic-test)
  ✓ -[ExampleObjCTest testExample] (3 ms)
  1 passed, 0 failed, 0 errored, 1 total (3 ms)

# after these changes
[Info] Collecting info for testables... (855 ms)
run-test TestBundle.xctest (iphonesimulator9.0, iPhone 4s, logic-test)
  ✓ -[ExampleObjCTest testExample] (4 ms)
  ✓ -[Counter Increment] (0 ms)
  ✓ -[Counter InitialState] (0 ms)
  3 passed, 0 failed, 0 errored, 3 total (5 ms)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this was done because registerTestClasses could implicitly invoke [GoogleTestCase initialize] and cause duplicated class registration because check if ([GoogleTestFilterMap count]) will fail.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling +initialize is frowned upon in ObjC; I think what you want is

if (self == [GoogleTestCase class]) {
    [self registerTestClasses];     
}

Does that solve it getting called twice?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

I had the bug where registerTestClasses was called twice, this is how I fixed it (I created the pull request also):

    NSArray* loadedClasses = [notification.userInfo objectForKey:NSLoadedClasses];

    if( loadedClasses != nil ) {
        if( [loadedClasses indexOfObject:@"GoogleTestLoader"] != NSNotFound) {
            [self registerTestClasses];
        }
    }

@ExtremeMan
Copy link
Author

Ping @mattstevens.

@eugenegff
Copy link

moving tests registration into +initialize doesn't work properly, as it happens right

  • (void)load {
    NSBundle *bundle = [NSBundle bundleForClass:self]; <--- here

and before C++ .ctors for static global variables (aka Google tests) are run

OTOH, parameterized tests method name sanitizing looks good

@eugenegff
Copy link

Merged method name sanitizing into https://github.com/eugenegff/xcode-googletest fork

eugenegff added a commit to eugenegff/xcode-googletest that referenced this pull request Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants