Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Sources/Testing/Attachments/Attachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ public struct AnyAttachable: AttachableContainer, Copyable, Sendable {
}
}

// MARK: - Describing an attachment

extension Attachment where AttachableValue: ~Copyable {
public var description: String {
let typeInfo = TypeInfo(describing: AttachableValue.self)
return #""\#(preferredName)": instance of '\#(typeInfo.unqualifiedName)'"#
}
}

extension Attachment: CustomStringConvertible {
public var description: String {
#""\#(preferredName)": \#(String(describingForTest: attachableValue))"#
}
}

// MARK: - Getting an attachable value from an attachment

@_spi(Experimental)
Expand Down
14 changes: 14 additions & 0 deletions Tests/TestingTests/AttachmentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ struct AttachmentTests {
attachment.attach()
}

@Test func description() {
let attachableValue = MySendableAttachable(string: "<!doctype html>")
let attachment = Attachment(attachableValue, named: "AttachmentTests.saveValue.html")
#expect(String(describing: attachment).contains(#""\#(attachment.preferredName)""#))
#expect(attachment.description.contains("MySendableAttachable("))
}

@Test func moveOnlyDescription() {
let attachableValue = MyAttachable(string: "<!doctype html>")
let attachment = Attachment(attachableValue, named: "AttachmentTests.saveValue.html")
#expect(attachment.description.contains(#""\#(attachment.preferredName)""#))
#expect(attachment.description.contains("'MyAttachable'"))
}

#if !SWT_NO_FILE_IO
func compare(_ attachableValue: borrowing MySendableAttachable, toContentsOfFileAtPath filePath: String) throws {
let file = try FileHandle(forReadingAtPath: filePath)
Expand Down