devxoul / Stubber

A minimal method stub for Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

functionAddress doesn't work in Xcode 12

danielsaidi opened this issue · 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.

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

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 #9 (comment) ??

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.

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