Comments (4)
Hey, @flopshot. The derivable constraint syntax is not compatible with concrete types, so you can't simply write M1.MatchedType: Int
, it complains that Int
is neither a protocol nor a class. So then we'd have to compare the type to our type database to check whether the type is a class or protocol.
It's certainly possible to implement this behavior to add even stronger generics support. If you're up for it, please start on the feature/swiftsyntax
branch. It's 2.0 release of the library & generator, even though it's not ready for release just yet, but getting close.
Asking about any questions or problems getting the project running is appreciated, as that branch contains a lot of major changes throughout the project, hopefully for the better. 😄 The contributing section in README should still apply, so you can start off there.
from cuckoo.
Thanks for the response.
In the end, we couldn't simply use $0 as! M1.MatchedType
because we may want the stub accept different subclasses in the same test, which wasn't possible with that force cast to the Monomorphic type MatchedType
Also, the compiler error was misleading, because what actually was needed was just to make Request
conform to Matchable
We ended up using type erasure to solve our problem and leave the generated code as is
extension Request : Matchable {
public var matcher: Cuckoo.ParameterMatcher<Request> {
ParameterMatcher<Request>(matchesFunction: { (request: Request) -> Bool in
if let productByChoiceIdsRequestRHS = request as? GetProductsByChoiceIdsRequest,
let productByChoiceIdsRequestLHS = self.self as? GetProductsByChoiceIdsRequest {
return productByChoiceIdsRequestRHS.choiceIds == productByChoiceIdsRequestLHS.choiceIds
}
if let getRecommendationTrayRequestRHS = request as? GetRecommendationTrayRequest,
let getRecommendationTrayRequestLHS = self.self as? GetRecommendationTrayRequest {
return getRecommendationTrayRequestLHS.path == getRecommendationTrayRequestRHS.path &&
getRecommendationTrayRequestLHS.itemsPerPage == getRecommendationTrayRequestRHS.itemsPerPage &&
getRecommendationTrayRequestLHS.categorySlug == getRecommendationTrayRequestRHS.categorySlug &&
getRecommendationTrayRequestLHS.contextIds == getRecommendationTrayRequestRHS.contextIds &&
getRecommendationTrayRequestLHS.excludeChoiceIds == getRecommendationTrayRequestRHS.excludeChoiceIds &&
getRecommendationTrayRequestLHS.clientFilters.keys.sorted() == getRecommendationTrayRequestRHS.clientFilters.keys.sorted()
}
//...
}
Doing this fixed the issue, for using this in our large code base.
Which brings me to my next point, it would be better if the compiler error was more helpful by explicitly saying
Request<T> does not conform to Matchable
instead of
Instance method 'asyncLoadResponse(request:)' requires the types 'GetProductBySlugRequest' and 'Request<Product>' be equivalent
Which I would be happy to make a pull request for, as this was very annoying and led me down a bad path.
If anyone has this problem, the better solutions, though long term, is to use a new class called EquatableRequest<T>
, conform it to Equatable
and simply inherit any requests you'd like to match in tests to EquatableRequest<T>
then you could simple have this single Matchable
conformance
extension EquatableRequest : Matchable {
public var matcher: Cuckoo.ParameterMatcher<Request> {
ParameterMatcher<Request>(matchesFunction: { (request: Request) -> Bool in
request == self.self
}
from cuckoo.
Asking about any questions or problems getting the project running is appreciated, as that branch contains a lot of major changes throughout the project, hopefully for the better. 😄 The contributing section in README should still apply, so you can start off there.
Thanks I will give it a shot next week
from cuckoo.
2.0 has been released and this hopefully fixed? If not, please reopen. 🙂
from cuckoo.
Related Issues (20)
- Add support for Protocols requiring AnyActor conformance HOT 4
- Permission denied: Can't add comments to the list of files HOT 4
- Strip conflicting imports HOT 2
- Compilation fails in Xcode 14.3
- Error when running Cuckoo/run (cuckoo_generator ver. 1.10.2) HOT 4
- Unable to build with SPM install (ld: symbol(s) not found for architecture arm64) HOT 8
- Cuckoo need XCTest.framework in link binary with Libraries section. otherwise it shows error that is "cannot find 'XCTFail' in scope" in MockManager.swift file HOT 1
- Throwing "'some' types are only permitted in properties, subscripts, and functions" when `func` throws & has `some` for its parameter HOT 2
- Compiler custom flags are not supported by Cuckoo generator HOT 2
- Cuckoo does not support block-type closure HOT 2
- Carthage/Checkouts/Cuckoo/Generator/Generator.xcodeproj' does not exist. HOT 9
- Plenty errors in GeneratedMocks.ts for swift 5.8.1 HOT 2
- Error: Expected member name or constructor call after type name HOT 28
- Issue with Cuckoo Generating Mock for a variable's property HOT 1
- Issue with variable name as `extension` HOT 1
- Problem with run script on Xcode 15 HOT 6
- Not able to initialise Mock Object HOT 1
- More descriptive failure messages HOT 1
- 2.0 issues HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cuckoo.