File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Overlays/_Testing_Foundation/Attachments Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ extension Attachment where AttachableValue == _AttachableURLWrapper {
4747 ///
4848 /// When you call this initializer and pass it the URL of a file, it reads or
4949 /// maps the contents of that file into memory. When you call this initializer
50- /// and pass it the URL of a directory, it creates a temporary zip file of the
50+ /// and pass it the URL of a directory, it creates a temporary ZIP file of the
5151 /// directory before reading or mapping it into memory. These operations may
5252 /// take some time, so this initializer suspends the calling task until they
5353 /// are complete.
Original file line number Diff line number Diff line change @@ -76,6 +76,29 @@ extension SalesReport: Encodable, Attachable {}
7676 your test target imports the [ Foundation] ( https://developer.apple.com/documentation/foundation )
7777 module.
7878
79+ ### Attach files and directories
80+
81+ If you have a file you want to save as an attachment, you can attach it using
82+ its file URL. The testing library needs to read or map the file before attaching it
83+ to your test, and those operations can fail, so you need to explicitly create an
84+ instance of `` Attachment `` before you record it.
85+
86+ ``` swift
87+ import Foundation
88+
89+ @Test func `sales report adds up`() async throws {
90+ let salesReport = await generateSalesReport ()
91+ try salesReport.validate ()
92+ let salesReportURL = try salesReport.save ()
93+ let attachment = try await Attachment (contentsOf : salesReportURL)
94+ Attachment.record (attachment)
95+ }
96+ ```
97+
98+ You can also attach a directory to a test using its file URL. When you attach a
99+ directory to a test, the testing library creates a ZIP file containing the
100+ directory's contents, then attaches that ZIP file in place of the directory.
101+
79102### Attach images
80103
81104You can attach instances of the following system-provided image types to a test:
You can’t perform that action at this time.
0 commit comments