Description
We are currently attempting to update to Cuckoo 2.x but found a regression/blocker that prevents us from doing so. We initially contributed a solution for @available in #423. However, during migration to 2.x we observed that the original issue is back.
Original description (from the linked PR):
Problem
In case of a cross-platform codebase where some APIs are marked with e.g. @available(tvOS, unavailable) the Cuckoo generated code can not be compiled due to error Cannot override 'tvOSUnavailableAPI' which has been marked unavailable when building for the "forbidden" platform.
Like with this type to mock:
class TestClass {
@available(tvOS, unavailable)
var tvOSUnavailableAPI: Bool = true
}
I am happy to take any feedback.
I didn't know how to add unit tests for this project (seems a bit unconventional 😅), but happy to do so if I get some instructions how the setup works.
Proposed solution
I have built a POC where I extracted the platform value ("tvOS" from the above example) and wrapped the affected API with #if !os(unavailablePlatform).
In case of multiple unavailable platforms:
class TestClass {
@available(tvOS, unavailable)
@available(macCatalyst, unavailable)
var tvOSUnavailableAPI: Bool = true
var generallyAvailableApi: String = "hello"
}
it would result like this: #if !os(tvOS) && !os(macCatalyst) (see below)
#if !os(macCatalyst) && !os(tvOS)
@available(macCatalyst, unavailable)
@available(tvOS, unavailable)
override var tvOSUnavailableAPI: Bool {
...
}
}
#endif
Description
We are currently attempting to update to Cuckoo 2.x but found a regression/blocker that prevents us from doing so. We initially contributed a solution for
@availablein #423. However, during migration to 2.x we observed that the original issue is back.Original description (from the linked PR):
Problem
In case of a cross-platform codebase where some APIs are marked with e.g.
@available(tvOS, unavailable)the Cuckoo generated code can not be compiled due to errorCannot override 'tvOSUnavailableAPI' which has been marked unavailablewhen building for the "forbidden" platform.Like with this type to mock:
I am happy to take any feedback.
I didn't know how to add unit tests for this project (seems a bit unconventional 😅), but happy to do so if I get some instructions how the setup works.
Proposed solution
I have built a POC where I extracted the platform value (
"tvOS"from the above example) and wrapped the affected API with#if !os(unavailablePlatform).In case of multiple unavailable platforms:
it would result like this:
#if !os(tvOS) && !os(macCatalyst)(see below)