diff --git a/Sources/Testing/Attachments/Attachment.swift b/Sources/Testing/Attachments/Attachment.swift index 93ae53c73..034f5e03c 100644 --- a/Sources/Testing/Attachments/Attachment.swift +++ b/Sources/Testing/Attachments/Attachment.swift @@ -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) diff --git a/Tests/TestingTests/AttachmentTests.swift b/Tests/TestingTests/AttachmentTests.swift index 8d38603e0..4013882a1 100644 --- a/Tests/TestingTests/AttachmentTests.swift +++ b/Tests/TestingTests/AttachmentTests.swift @@ -30,6 +30,20 @@ struct AttachmentTests { attachment.attach() } + @Test func description() { + let attachableValue = MySendableAttachable(string: "") + 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: "") + 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)