@@ -99,12 +99,15 @@ public struct Attachment<AttachableValue>: ~Copyable where AttachableValue: Atta
99
99
/// disk.
100
100
///
101
101
/// An attachment can only be attached once.
102
- public static func attach (_ attachment : consuming Self , sourceLocation : SourceLocation = #_sourceLocation )
102
+ public static func record (_ attachment : consuming Self , sourceLocation : SourceLocation = #_sourceLocation )
103
103
104
104
/// Attach a value to the current test.
105
105
///
106
106
/// - Parameters:
107
107
/// - attachableValue: The value to attach.
108
+ /// - preferredName: The preferred name of the attachment when writing it to
109
+ /// a test report or to disk. If `nil`, the testing library attempts to
110
+ /// derive a reasonable filename for the attached value.
108
111
/// - sourceLocation: The source location of the call to this function.
109
112
///
110
113
/// When attaching a value of a type that does not conform to both
@@ -119,7 +122,7 @@ public struct Attachment<AttachableValue>: ~Copyable where AttachableValue: Atta
119
122
/// attaches it to the current test.
120
123
///
121
124
/// An attachment can only be attached once.
122
- public static func attach (_ attachment : consuming AttachableValue, sourceLocation : SourceLocation = #_sourceLocation )
125
+ public static func record (_ attachableValue : consuming AttachableValue, named preferredName : String ? = nil , sourceLocation : SourceLocation = #_sourceLocation )
123
126
124
127
/// Call a function and pass a buffer representing the value of this
125
128
/// instance's ``attachableValue-2tnj5`` property to it.
@@ -153,10 +156,11 @@ conform:
153
156
/// A protocol describing a type that can be attached to a test report or
154
157
/// written to disk when a test is run.
155
158
///
156
- /// To attach an attachable value to a test report or test run output, use it to
157
- /// initialize a new instance of ``Attachment``, then call
158
- /// ``Attachment/attach(_:sourceLocation:)``. An attachment can only be attached
159
- /// once.
159
+ /// To attach an attachable value to a test, pass it to ``Attachment/record(_:named:sourceLocation:)``.
160
+ /// To further configure an attachable value before you attach it, use it to
161
+ /// initialize an instance of ``Attachment`` and set its properties before
162
+ /// passing it to ``Attachment/record(_:sourceLocation:)``. An attachable
163
+ /// value can only be attached to a test once.
160
164
///
161
165
/// The testing library provides default conformances to this protocol for a
162
166
/// variety of standard library types. Most user-defined types do not need to
@@ -245,10 +249,11 @@ that refines `Attachable`:
245
249
/// written to disk when a test is run and which contains another value that it
246
250
/// stands in for.
247
251
///
248
- /// To attach an attachable value to a test report or test run output, use it to
249
- /// initialize a new instance of ``Attachment``, then call
250
- /// ``Attachment/attach(_:sourceLocation:)``. An attachment can only be attached
251
- /// once.
252
+ /// To attach an attachable value to a test, pass it to ``Attachment/record(_:named:sourceLocation:)``.
253
+ /// To further configure an attachable value before you attach it, use it to
254
+ /// initialize an instance of ``Attachment`` and set its properties before
255
+ /// passing it to ``Attachment/record(_:sourceLocation:)``. An attachable
256
+ /// value can only be attached to a test once.
252
257
///
253
258
/// A type can conform to this protocol if it represents another type that
254
259
/// cannot directly conform to ``Attachable``, such as a non-final class or a
@@ -452,10 +457,10 @@ version too.
452
457
allows an implementation (such as that of `Encodable & Attachable`) to add a
453
458
path extension to the filename specified by the test author if needed.
454
459
455
- - Making the `Attachment.attach (_:sourceLocation:)` methods a single instance
456
- method of `Attachment` named `attach()`: this was in the initial pitch but the
457
- community discussed several more ergonomic options and we chose
458
- `Attachment.attach (_:sourceLocation:)` instead.
460
+ - Making the `Attachment.record (_:[named:] sourceLocation:)` methods a single
461
+ instance method of `Attachment` named `attach()`: this was in the initial
462
+ pitch but the community discussed several more ergonomic options and we chose
463
+ `Attachment.record (_:sourceLocation:)` instead.
459
464
460
465
## Acknowledgments
461
466
0 commit comments