Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide option to skip generating mocks for parent protocols outside package #409

Closed
juyan opened this issue Jan 15, 2022 · 3 comments
Closed

Comments

@juyan
Copy link

juyan commented Jan 15, 2022

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.

@MatyasKriz
Copy link
Collaborator

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.

@juyan
Copy link
Author

juyan commented Jan 26, 2022

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

@MatyasKriz
Copy link
Collaborator

Hey, in Cuckoo 2.0 the regex exclusion is applied after inheritance is resolved, so it is possible to do the thing you're proposing here. 🙂 Thanks for the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants