Support calling objective-c methods and closures with nil#374
Support calling objective-c methods and closures with nil#374dekpient wants to merge 1 commit intoBrightify:masterfrom
Conversation
|
Hey, @dekpient. Thanks for the PR and thanks for using the OCMock integration! It's a nice find with the |
| } | ||
|
|
||
| // TODO add more variants | ||
| public func objectiveOptionalArgumentClosure<IN1, IN2>(from: Any) -> (IN1?, IN2?) -> Void { |
There was a problem hiding this comment.
I think we'll have to try coming up with a more complex solution to this, because as the number of arguments go up, the combinations of optional and non-optional arguments will skyrocket.
There was a problem hiding this comment.
Yeah, I agree. I ended up defining this in my test project just for the specific test cases that I need. Should I split this into 2 PRs so the 1st problem can be fixed? I really need that fix.
There was a problem hiding this comment.
Splitting this up sounds like the better call at the moment. Would you please add the remaining combinations for 2-parameter closures, i.e. (optional, non-optional), (non-optional, optional) as well as an optional counterpart to the 1-parameter closure. We'll need to come up with a more generic solution, but for now this can help make the closures more accessible by showing users how to implement them (only using the right amount of arguments). Thanks!
Also, would you mind creating a test or two for the closures with optional parameters? Just to make sure they work and when replacing with the generic solution to know nothing has been broken.
Afterwards, we can probably merge this and release.
| } | ||
|
|
||
| mock.say(nil) { result, messages in | ||
| XCTAssertEqual("nil now behaves", result) |
d2d44b9 to
a4618f6
Compare
Hello, I'm trying to fix 2 issues I found when trying to use
Cuckoo/OCMockin a project. I'm currently unable to cover a few code branches because of them.mock.say(nil)currently fails with-[_NSArrayM insertObject:atIndex:]: object cannot be nil (NSInvalidArgumentException)becauseNSInvocation+OCMockWrapperdoesn't do a null check.objectiveArgumentClosureand calling the closure withnilfails with-[NSNull count]: unrecognized selector sent to instance 0x7fff8002ebb0 (NSInvalidArgumentException). I think it's causeTrustMedoesn't support nullable types. I proposeobjectiveOptionalArgumentClosure(or maybeobjcArgumentClosureWithOptional?). I can add more of them to support closures with more args if you think this is alright.I also removed the reference to
ObjectiveExamplesTest.swift. It doesn't exist in the project so it's making the build fail.Cheers