-
-
Notifications
You must be signed in to change notification settings - Fork 48
Add inherited types macro parameter #144
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
Open
ThomasDutartre
wants to merge
5
commits into
Matejkob:main
Choose a base branch
from
MaxenceMottard:add-inherited-types-macro-parameter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add inherited types macro parameter #144
ThomasDutartre
wants to merge
5
commits into
Matejkob:main
from
MaxenceMottard:add-inherited-types-macro-parameter
Conversation
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
18b1511 to
6d23806
Compare
6d23806 to
6edc036
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #144 +/- ##
==========================================
+ Coverage 95.56% 95.78% +0.22%
==========================================
Files 22 22
Lines 1330 1401 +71
==========================================
+ Hits 1271 1342 +71
Misses 59 59 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
MaxenceMottard
approved these changes
Jul 9, 2025
Contributor
Author
|
@Matejkob If you're ok with the idea of this PR, i will add the documentation before merge |
|
@ThomasDutartre should the new open access Level not be part of the SpyAccessLevel enum ? |
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.
🚀 Enhancement: Spy Class Inheritance Support with
inheritedTypeApproach n°3 of this issue : #47
I started my work from the pr of @MaxenceMottard
#136
📋 Summary
This pull request adds support for class inheritance in the
@Spyablemacro via the newinheritedTypeparameter, allowing a spy class to inherit from another spy class. This feature also includes special handling of theopenaccess level to support modular architectures.🎯 Main Objective: Spy Class Inheritance
Identified Need
Enable a generated spy class to inherit from another spy class to create coherent test hierarchies:
Concrete Use Cases
🏗️ Technical Challenge: Modular Architectures
Separate Package Problem
In certain architectures, tests are not in the same package as the protocols. We therefore need to offer the possibility of inheriting spy classes between packages.
Discovered Edge Case:
openAccess LevelTo be able to override an init from a class that comes from another package, the class must be
open. That's why I added support foropen.However, Swift does not allow
openinitializers:✅ Implemented Solution
1. New
inheritedTypeParameterAdded a simple parameter for spy class inheritance:
2. Smart
openInitializer HandlingThe macro automatically detects when access level is
openand generates the initializer aspublic:3. Current Limitation: Single Inheritance Only
For now, only single type inheritance is supported. Multiple inheritance is not supported at this time, supporting a single protocol is our only path forward.
🔧 Technical Changes
Main Modified Files
Spyable.swiftinheritedType: String?parameterAccessLevelModifierRewriter.swiftopen+InitializerDeclSyntaxopen→publicfor initializersExtractor.swiftextractInheritedType()method to extract inherited typeSpyFactory.swiftoverridewhen necessarySpyableMacro.swiftComprehensive Tests Added
UT_AccessLevelModifierRewriter.swift: 12 tests for access level handlingUT_SpyableMacro.swift: 6 tests for new use cases withinheritedType🎯 Enabled Use Cases
1. Simple Inheritance
2. Inheritance Chain
3. Modular Architecture with
open