Open IuliiaMishina opened 2 years ago
I have also experienced the same issue with SwiftMocky 4.0.1 and Xcode 13.3.1. In our project we have abstraction as below:
public protocol Proxy: AnyObject {
var shouldShowBadge: (() -> Bool)? { get set }
}
When accessing closure from Mock dependency in production code there is a crash. I have managed to find out that changing code inside mock from this:
public var shouldShowBadge: (() -> Bool)? {
get { invocations.append(.p_shouldShowBadge_get); return __p_shouldShowBadge ?? optionalGivenGetterValue(.p_shouldShowBadge_get, "ProxyMock - stub value for shouldShowBadge was not defined") }
set { invocations.append(.p_shouldShowBadge_set(.value(newValue))); __p_shouldShowBadge = newValue }
}
private var __p_shouldShowBadge: (() -> Bool)?
to this:
public var shouldShowBadge: (() -> Bool)? {
get {
invocations.append(.p_shouldShowBadge_get)
if let __p_shouldShowBadge = __p_shouldShowBadge {
return __p_shouldShowBadge
} else {
return optionalGivenGetterValue(.p_shouldShowBadge_get, "ProxyMock - stub value for shouldShowBadge was not defined") }
}
set { invocations.append(.p_shouldShowBadge_set(.value(newValue))); __p_shouldShowBadge = newValue }
}
private var __p_shouldShowBadge: (() -> Bool)?
solved crash related to memory management. Maybe there is a new compiler optimisation which does not work well with ??
operator in such case.
Looks fixed on Xcode 14.0
After updating to Xcode 13.3 I am not able to mock closures inside protocol anymore using
given
method. Whenever I am trying to call a mocked closure I receive EXC_BAD_ACCESS:Here's the sample code that producing this exception:
The
TestProtocol
andSwiftyMockyClosureTest
are in different targets. If I change the closure to be mutable and mock the property like this:It works, but breaks immutability of this property. In my case it's not applicable. Do you have any idea how to avoid this happening, or it's rather a bug in SwiftyMocky itself?
Thanks, Iuliia