Cuckoo icon indicating copy to clipboard operation
Cuckoo copied to clipboard

Support calling objective-c methods and closures with nil

Open dekpient opened this issue 5 years ago • 1 comments

Hello, I'm trying to fix 2 issues I found when trying to use Cuckoo/OCMock in a project. I'm currently unable to cover a few code branches because of them.

  1. Calling mock.say(nil) currently fails with -[_NSArrayM insertObject:atIndex:]: object cannot be nil (NSInvalidArgumentException) because NSInvocation+OCMockWrapper doesn't do a null check.
  2. Using objectiveArgumentClosure and calling the closure with nil fails with -[NSNull count]: unrecognized selector sent to instance 0x7fff8002ebb0 (NSInvalidArgumentException). I think it's cause TrustMe doesn't support nullable types. I propose objectiveOptionalArgumentClosure (or maybe objcArgumentClosureWithOptional ?). 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

dekpient avatar Dec 08 '20 09:12 dekpient

Hey, @dekpient. Thanks for the PR and thanks for using the OCMock integration!

It's a nice find with the nil, I'll take a look at the code and see what we can do with the second problem you're proposing a solution to.

MatyasKriz avatar Jan 11 '21 17:01 MatyasKriz