-
Notifications
You must be signed in to change notification settings - Fork 102
Provide an opt-out conditional for lazy attachment encoding. #811
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
This PR provides a compile-time conditional, `SWT_NO_LAZY_ATTACHMENTS`, which when set causes Swift Testing's new experimental attachments feature to always eagerly encode/serialize/whatever attachments even if they're copyable and sendable. We anticipate using this functionality in Embedded Swift in the future. Note that support for Embedded Swift is not (yet!) a planned feature.
@swift-ci test |
// BUG: the borrow checker thinks that withErrorRecording() is consuming | ||
// attachableValue, so get around it with an additional do/catch clause. |
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'm wondering if we ought to propagate caught Errors in this initializer? Unlike the other one, where encoding the attachment is deferred, and it does make sense to catch it and record an Issue, this one might be better to propagate and let the test author decide how to handle 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.
I thought about it, but my reasoning was that:
- Errors adding attachments are probably going to be pretty rare;
- You'd have to
try
for non-sendable or move-only attachments, but not if the attachment is sendable and copyable, which is inconsistent and potentially confusing; and - An error that occurs when creating an attachment is probably not a test failure, but an infrastructure failure, so it should not cause a test to halt execution—which it would unless you wrote
try?
, in which case we lose the 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.
Had one tangential comment, but this PR looks good
This PR provides a compile-time conditional,
SWT_NO_LAZY_ATTACHMENTS
, which when set causes Swift Testing's new experimental attachments feature to always eagerly encode/serialize/whatever attachments even if they're copyable and sendable.We anticipate using this functionality in Embedded Swift in the future. Note that support for Embedded Swift is not (yet!) a planned feature.
"Why not make Attachment generic?"
I've got a separate branch that tries to do this. It has a significantly more complex implementation and is brittle because we need to type-erase the attachable value in order to pass it into the event-handling machinery (which entails having a bunch of special-casing since
any Test.Attachable
does not conform toTest.Attachable
.)Attachment
is already meant to represent a type-erasedAttachable
value.Checklist: