From 946d09bca9eb65e12d2d5aca95e5b0db99339ff1 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Thu, 19 Sep 2024 14:25:02 -0400 Subject: [PATCH 01/20] Attachments! This PR introduces a new experimental feature, attachments. With this feature, you can "attach" values that conform to a new `Test.Attachable` protocol to a test. With the right command-line incantation (TBD), Swift Testing will automatically write attachments to disk for you. > ![NOTE] > This PR does not teach Xcode or VS Code how to handle attachments produced by > Swift Testing, nor does it add the necessary command-line arguments to the > `swift test` command-line tool. This PR is one of a series that I'll be posting to build out this feature. As always, keep in mind that symbols marked `@_spi(Experimental)` are subject to change or removal without notice. Resolves #714. Resolves rdar://88648735. --- Documentation/ABI/JSON.md | 6 +- .../Testing/ABI/EntryPoints/EntryPoint.swift | 17 ++ .../v0/Encoded/ABIv0.EncodedAttachment.swift | 32 +++ .../ABI/v0/Encoded/ABIv0.EncodedEvent.swift | 12 + .../ABI/v0/Encoded/ABIv0.EncodedMessage.swift | 3 + .../Testing/Attachments/Test.Attachable.swift | 72 +++++ .../Testing/Attachments/Test.Attachment.swift | 258 ++++++++++++++++++ Sources/Testing/CMakeLists.txt | 3 + Sources/Testing/Events/Event.swift | 12 + .../Event.ConsoleOutputRecorder.swift | 2 + .../Event.HumanReadableOutputRecorder.swift | 17 ++ .../Events/Recorder/Event.Symbol.swift | 14 + Sources/Testing/Running/Configuration.swift | 27 ++ Sources/Testing/Running/Runner.swift | 3 + Sources/Testing/Support/FileHandle.swift | 52 ++++ Tests/TestingTests/AttachmentTests.swift | 155 +++++++++++ .../TestSupport/TestingAdditions.swift | 9 +- 17 files changed, 690 insertions(+), 4 deletions(-) create mode 100644 Sources/Testing/ABI/v0/Encoded/ABIv0.EncodedAttachment.swift create mode 100644 Sources/Testing/Attachments/Test.Attachable.swift create mode 100644 Sources/Testing/Attachments/Test.Attachment.swift create mode 100644 Tests/TestingTests/AttachmentTests.swift diff --git a/Documentation/ABI/JSON.md b/Documentation/ABI/JSON.md index 23dd5b1dc..571376ef0 100644 --- a/Documentation/ABI/JSON.md +++ b/Documentation/ABI/JSON.md @@ -193,8 +193,8 @@ sufficient information to display the event in a human-readable format. } ::= "runStarted" | "testStarted" | "testCaseStarted" | - "issueRecorded" | "testCaseEnded" | "testEnded" | "testSkipped" | - "runEnded" ; additional event kinds may be added in the future + "issueRecorded" | "valueAttached" | "testCaseEnded" | "testEnded" | + "testSkipped" | "runEnded" ; additional event kinds may be added in the future ::= { "isKnown": , ; is this a known issue or not? @@ -207,7 +207,7 @@ sufficient information to display the event in a human-readable format. } ::= "default" | "skip" | "pass" | "passWithKnownIssue" | - "fail" | "difference" | "warning" | "details" + "fail" | "difference" | "warning" | "details" | "attachment" ```