Stubber icon indicating copy to clipboard operation
Stubber copied to clipboard

functionAddress doesn't work in Xcode 12

Open danielsaidi opened this issue 5 years ago • 4 comments

Hi,

I just downloaded Xcode 12 beta 2 and found that functionAddress no longer works when running Stubber-based tests. It generates a new address for the same function each time it's called, which makes registrations an inspections fail.

I have tried tweaking the implementation, but to no avail. Do you have any idea how to make it work? I'd be happy to help in any way I can, but I'm currently at a loss.

danielsaidi avatar Jul 13 '20 15:07 danielsaidi

I solved this by creating a MockReference which has a unique id and points to a function. Each mock can then create a ref for each function it mocks and use it when invoking, instead of a memory address.

You can check it out here: https://github.com/danielsaidi/Mockery/blob/v0.4/Sources/Mockery/MockReference.swift

danielsaidi avatar Jul 16 '20 22:07 danielsaidi

I faced the same problem as this issue. Does Stubber have plans to be fixed the problem ?? Or, I should patch a source code locally on my machine with reference to https://github.com/devxoul/Stubber/issues/9#issuecomment-659705573 ??

k-kohey avatar Oct 01 '20 08:10 k-kohey

I have run with the above mentioned function reference approach since I last wrote. It works flawlessly, even though it involves a little more code (one line per reference). However, with Swift no longer providing stable memory addresses, I see no other clean way to refer to functions.

The manual reference approach also brings many benefits compared to the memory address-based on, such as being able to run mock-based tests on multiple architectures, in release mode and also use mocks from other libraries, which is a huge win if you use multiple libraries with interdependencies.

If the people behind Stubber would like to use this approach as well, I'd be happy to create a PR.

danielsaidi avatar Oct 02 '20 06:10 danielsaidi

Hi guys, sorry for delay. #10 is a patch for the bug. Could you please test with xcode-12-function-pointer branch? Thanks!

devxoul avatar Oct 05 '20 07:10 devxoul