Cuckoo icon indicating copy to clipboard operation
Cuckoo copied to clipboard

Provide option to skip generating mocks for parent protocols outside package

Open juyan opened this issue 3 years ago • 2 comments

Overview

It looks like the generated mock file will contain mocks for inherited protocols by design. Can we improve the generator to exclude them? Or is there a way to do this that I'm unaware of.

Example

Swift Package "Base":

public protocol BaseProtocol {
    func getBar() -> Int
}

Swift Package "Middle":

public protocol MiddleProtocol: BaseProtocol {
    func getFoo() -> Int
}

Now run the generator using the following command:

cuckoo_generator generate --glob Base/Sources/Base/* --glob Middle/Sources/Middle/* --output Middle/Tests/MiddleTests/MiddleTestMocks.swift --testable Middle

We would get both MockMiddleProtocol and MockBaseProtocol inside the file MiddleTestMocks.swift.

Expected Behavior

Using the above example, I'm looking for a way to not contain MockBaseProtocol inside BaseMiddleMocks. This can probably be configurable via a new command line argument like supportGlob. It indicates the file necessary to generate the correct mocks that contains parent methods but does not generate mock for parent protocols themselves.

cuckoo_generator generate --glob Middle/Sources/Middle/* --supportGlob Base/Sources/Base/* --output Middle/Tests/MiddleTests/MiddleTestMocks.swift --testable Middle

Looking forward to see other's thoughts. Thanks.

juyan avatar Jan 15 '22 07:01 juyan

Hey there, @juyan. Does excluding the MiddleProtocol on its own do what you need? I'm not against adding support for this case, but I'd refrain from adding more CLI flags if possible.

MatyasKriz avatar Jan 24 '22 18:01 MatyasKriz

@MatyasKriz sorry there was something wrong in my example and I fixed it. Please take a look again, hope it makes more sense now.

juyan avatar Jan 26 '22 05:01 juyan