8000 Don't call `+[QuickConfiguration initialize]` method manually by ikesyo · Pull Request #873 · Quick/Quick · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Don't call +[QuickConfiguration initialize] method manually #873

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

Merged
merged 3 commits into from
Apr 21, 2019

Conversation

ikesyo
Copy link
Member
@ikesyo ikesyo commented Apr 20, 2019

Fixes #853.

This fixes a runtime crash when a subclass of QuickSpec is subclassed and the subclass has a Swift struct property. This avoids nested calls of +[QuickConfiguration initialize] and objc_getClassList.

@ikesyo ikesyo marked this pull request as ready for review April 20, 2019 15:37
@ikesyo ikesyo closed this Apr 20, 2019
@ikesyo ikesyo reopened this Apr 20, 2019
@ikesyo
Copy link
Member Author
ikesyo commented Apr 20, 2019

Reopened to trigger CI.

This fixes a runtime crash when a subclass of QuickSpec is subclassed and the subclass has a Swift struct property. This avoids nested calls of `+[QuickConfiguration initialize]` and `objc_getClassList`.
@ikesyo ikesyo changed the title Don't call +initialize method manually Don't call +[QuickConfiguration initialize] method manually Apr 20, 2019
@@ -26,7 +26,7 @@ @implementation QuickSpec
included an expectation outside of a "it", "describe", or "context" block.
*/
+ (void)initialize {
[QuickConfiguration initialize];
[QuickConfiguration class];
Copy link
Member Author

Choose a reason for hiding this comment

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

By accessing the class, let the Objective-C runtime call +initialize method of the class.

@ikesyo ikesyo requested a review from a team April 20, 2019 15:56
@phatblat
Copy link
Member

The new test case is great, allowed me to confirm that the change in this PR does resolve the test issue. However, I still get a crash in gzafra/QuickCrashTest#1

Screen Shot 2019-04-20 at 9 57 30 AM
Screen Shot 2019-04-20 at 9 57 27 AM

@phatblat
Copy link
Member

FYI, Travis does has a "Trigger build" button now so you shouldn't need to close/reopen the PR just to trigger a build.
Screen Shot 2019-04-20 at 10 14 29 AM

@ikesyo
Copy link
Member Author
ikesyo commented Apr 21, 2019

However, I still get a crash in gzafra/QuickCrashTest#1

Thanks @phatblat, I also confirmed that. So the right direction would be to avoid using +initialize to gather examples for each spec classes.

@ikesyo
Copy link
Member Author
ikesyo commented Apr 21, 2019

So the right direction would be to avoid using +initialize to gather examples for each spec classes.

It seems that replacing initialize with defaultTestSuite did fix the issue.

diff --git a/Sources/QuickObjectiveC/QuickSpec.m b/Sources/QuickObjectiveC/QuickSpec.m
index 1418fec..080cf52 100644
--- a/Sources/QuickObjectiveC/QuickSpec.m
+++ b/Sources/QuickObjectiveC/QuickSpec.m
@@ -25,7 +25,7 @@ static QuickSpec *currentSpec = nil;
  If an exception occurs when compiling the examples, report it to the user. Chances are they
  included an expectation outside of a "it", "describe", or "context" block.
  */
-+ (void)initialize {
++ (XCTestSuite *)defaultTestSuite {
     [QuickConfiguration class];
 
     World *world = [World sharedWorld];
@@ -48,6 +48,8 @@ static QuickSpec *currentSpec = nil;
         }
         [self testInvocations];
     }];
+
+    return [super defaultTestSuite];
 }
 
 /**

defaultTestSuite is used in SwiftPM-Darwin integration (that was originally because we can't implement +initialize in Swift):

/// This method is used as a hook for the following two purposes
///
/// 1. Performing all configurations
/// 2. Gathering examples for each spec classes
///
/// On Linux, those are done in `LinuxMain.swift` and `Quick.QCKMain`. But
/// SwiftPM on macOS does not have the mechanism (test cases are automatically
/// discovered powered by Objective-C runtime), so we needed the alternative
/// way.
override open class var defaultTestSuite: XCTestSuite {
configureDefaultTestSuite()
return super.defaultTestSuite
}

Copy link
Member
@phatblat phatblat left a comment

Choose a reason for hiding this comment

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

That's the ticket! 🎫 Nice work! 🎉

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.

Quick crashes after upgrading XCode 10.2
2 participants
0