-
Notifications
You must be signed in to change notification settings - Fork 86
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
Concurrency safe handler #276
Conversation
mockReturn = ".void" | ||
} else if let val = defaultVal { | ||
mockReturn = ".val(\(val))" | ||
struct Renderer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the implementation because the processing became more complex.
let fixtureContents = formattedDstContent.components(separatedBy: .whitespacesAndNewlines).filter{!$0.isEmpty} | ||
XCTAssert(fixtureContents == outputContents, "output:\n" + output) | ||
let fixtureContents = dstContent.components(separatedBy: .whitespacesAndNewlines).filter{!$0.isEmpty} | ||
XCTAssert(outputContents.contains(subArray: fixtureContents), "output:\n" + output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of examining all lines, we check whether the output lines contain the fixture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much! LGTM from my side, but I left some questions for posterity.
@@ -23,12 +23,12 @@ final class NominalModel: Model { | |||
let accessLevel: String | |||
let identifier: String | |||
let declKindOfMockAnnotatedBaseType: NominalTypeDeclKind | |||
let inheritedTypes: [String] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[question]
I am sorry but could you elaborate why you delete inheritedTypes
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is never used.
It might be back in the future if needed.
fileprivate func warnIfNotSendable<each T>(function: String = #function, _: repeat each T) { | ||
print("At \(function), the captured arguments are not Sendable, it is not concurrency-safe.") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not confident this print statement is needed or not, as mocking library.
I think print is not time-efficient. It might be good to opt-in this warning in another PR. What do you think of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is called only if there is an issue with the user's implementation, so it can be resolved if the user fixes the problem.
As an escape hatch, I want to make it possible to disable it with:
/// @mockable(history: fooFunc = false)
(Probably it cannot be done now.)
var requiresSendable: Bool { | ||
return inheritedTypes.contains(.sendable) || inheritedTypes.contains(.error) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[question]
Actor
protocol is not written here. Is it okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock of an Actor
protocol automatically becomes an actor
, so it is not necessary to make the mock implementation Sendable
.
Issue: #249
When the mock protocol requires
Sendable
, correctly implement the mock functions asSendable
. To provide a concurrency-safe implementation, we also add some helper functions and types.This PR does not address stored properties or computed properties (Do it later).
As shown below, various function
Handler
s are required to beSendable
.