Add CuckooPluginModular for per-module mock generation#595
Merged
Conversation
MatyasKriz
reviewed
Mar 18, 2026
MatyasKriz
reviewed
Mar 18, 2026
MatyasKriz
left a comment
Collaborator
There was a problem hiding this comment.
Looks great! I appreciate you taking the time to improve the project like this. Especially the automatic source detection might be nice for small projects.
One more thing, though – please mention this new modular build tool in README, so that users don't miss it. 🙂
Contributor
Author
|
@MatyasKriz Thank you for the review and feedbacks! I'll address them as soon as I have some time. |
f517ecb to
e63d7f8
Compare
SylvainRX
commented
Apr 3, 2026
SylvainRX
left a comment
Contributor
Author
There was a problem hiding this comment.
Hello @MatyasKriz !
I pushed changes addressing your comments, and updated the readme as well.
Please let me know if there's thing I can keep improving on.
Thanks!
MatyasKriz
approved these changes
Jun 3, 2026
MatyasKriz
left a comment
Collaborator
There was a problem hiding this comment.
Sorry for the delay, looks good! The documentation is a nice touch as well. 👏
- Create new CuckooPluginPerModule plugin that generates separate mock files per module dependency - Add content-equality guards in GenerateCommand to prevent unnecessary file rewrites - Skip writing output files when content unchanged This allows test targets to depend only on specific module mocks rather than all mocks in a single file, while maintaining the original plugin for existing users.
Enables test targets to override shared module mock generation by introducing CUCKOO_COMPOUND_MODULE_NAME (TARGET/MODULE format). - Plugin: - Pass CUCKOO_COMPOUND_MODULE_NAME env var for each dependency - Generate build command for test target itself (not just deps) - Generator: - Prioritize compound module key over plain module name - Support suppressor pattern (empty sources = empty output) This allows Cuckoofile.toml to specify different mock sources for the same module when used in different test targets, fixing issues where shared dependencies generate unwanted mocks.
Rename CuckooPluginPerModule plugin to CuckooPluginModular Refactor module filtering Revert the write logic for mock generation (get rid of the large string comparison)
I deemed the compound module concept as useless for now. If we want to import protocol with an identical name from different targets, we should work on prefixing them with their target name in the generated mocks.
e63d7f8 to
e678ce2
Compare
Contributor
Author
|
Thank you @MatyasKriz ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
CuckooPluginModularbuild tool plugin that generates separate mock files per module dependency, improving modularity for multi-target Swift Packages.Related issue: #555
Motivation
The existing
CuckooPluginSingleFilegenerates all mocks into a singleGeneratedMocks.swiftfile in derived data. In a Swift Package with multiple targets, each test target compiles independently and may not have visibility into types from unrelated modules, making a single shared mock file problematic.Changes
New Plugin: CuckooPluginModular
Generator/Plugin/Modular/CUCKOO_MODULE_NAMEenvironment variableGeneratedMocks_<ModuleName>.swiftCuckoofile.tomlto have a[modules.<TestTargetName>]entry to control which files are mocked and which imports are addedCuckoofile.tomlentry is required for each module; modules without a matching entry produce an empty fileUsage
Package.swift:
Cuckoofile.toml:
Breaking Changes
None. All changes are backward compatible with existing plugins and configurations.