This repo demonstrates an issue when generating mocks with Cuckoo for protocols with conformance to other protocols. At time of writing, Cuckoo claims to support "inheritance (grandparent methods)", but it seems that this support currently does not extend to protocol conformance.
- Cuckoo version: 2.0.18
- Xcode version: 16.1
- Swift version: 6.0.2
- MacOS version: 15.5
When building this project, you will encounter errors like:
Type 'MockChildProtocolWithNoArgs' does not conform to protocol 'ParentProtocolWithNoArgs'
Type 'ChildProtocolWithNoArgsStub' does not conform to protocol 'ParentProtocolWithNoArgs'
Type 'MockChildProtocolWithArg' does not conform to protocol 'ParentProtocolWithArg'
Type 'ChildProtocolWithArgStub' does not conform to protocol 'ParentProtocolWithArg'
Type 'MockChildProtocolWithAssociatedType' does not conform to protocol 'ParentProtocolWithAssociatedType'
Type 'ChildProtocolWithAssociatedTypeStub' does not conform to protocol 'ParentProtocolWithAssociatedType'
These errors occur in Tests/CuckooProtocolInheritanceExampleTests/GeneratedMocks.swift.
The mocks generated by Cuckoo for protocols that inherit from other protocols do not automatically implement the requirements of the parent protocols.
For example, ChildProtocolWithNoArgs inherits from ParentProtocolWithNoArgs, but the generated mock only implements childFunction() and omits parentFunction().
This leads to a failure to conform to the parent protocol.
I've included a few types of parent function signature, just to be sure that it's not limited to an edge case with a particular parent protocol function signature type.
- Clone this repository.
- Run
swift testor test the project in Xcode. - Observe the build errors in
GeneratedMocks.swiftas described above.
- Protocols are defined in
Sources/CuckooProtocolInheritanceExample/ParentProtocols.swiftandChildProtocols.swift. - Cuckoo is configured via
Cuckoofile.toml. - The mocks generation script is a pre-action on the
CuckooProtocolInheritanceExampletarget build action.
- To work around this in my own code, I'm currently resorting to re-defining parent protocol conformances in child protocols, but this leads to undesirable code duplication and is not a pattern I would like to continue.