erikdoe / ocmock

Mock objects for Objective-C
http://ocmock.org
Apache License 2.0
2.16k stars 606 forks source link

Add support for unretained and unsafeunretained arguments for stubs. #419

Open dmaclach opened 4 years ago

dmaclach commented 4 years ago

Allows marking an argument in a stub as being either 'unsafe' or 'unsafeunretained'. An unsafe object argument is retained by the stub, but not by invocations on the mock. An unsafe unretained object argument is not retained by the stub or by invocations on the mock.

This allows for mocking of methods that do not retain their arguments. This should simplify testing of methods that are called in dealloc, and give people a way out of other retain-loop problems.

Fix for #347 , #346 and may help with some of the discussion on #398

imhuntingwabbits commented 4 years ago

Excellent. I haven't done a very thorough pass but this looks exactly like the evolution I was asking for in #398.

dmaclach commented 4 years ago

As always thanks for looking at these Erik.

dmaclach commented 4 years ago

Found an issue where calling "isKindOfClass" on proxies was causing issues. Replaced with [OCMArg isUnretained] which calls objc_getClass instead.

erikdoe commented 4 years ago

So, I looked at this again in detail. I get the intent, but I don't understand the implementation. It's easier to comment directly in the code, which is what I'll do below.

I'll also comment on a few other points.

dmaclach commented 4 years ago

I hadn't realized that my last push had put this in a horribly mixed up state. I think it's much cleaner now.

erikdoe commented 3 years ago

Apologies but I have moved this change to OCMock 3.9 for now. The 3.8 release has taken much longer than I had hoped and there are a number of good changes in it already, which I'd like to get out soon. This PR still needs some work. The conflicts aren't too bad but there are a number of details (naming and otherwise) which I'd want to address before merging.