Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make compatible with xctool and Xcode 7 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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)

@@ -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];
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.

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.

3 participants