-
Notifications
You must be signed in to change notification settings - Fork 145
Decode EncodedEvent -> Event #1684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2026 Apple Inc. and the Swift project authors | ||
| // Licensed under Apache License v2.0 with Runtime Library Exception | ||
| // | ||
| // See https://swift.org/LICENSE.txt for license information | ||
| // See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
| // | ||
|
|
||
| @testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing | ||
|
|
||
| @Suite struct `ABI.EncodedEventTests` { | ||
| #if canImport(Foundation) | ||
| /// Creates an EncodedEvent from a JSON string. | ||
| /// | ||
| /// - Throws: If the JSON doesn't represent a valid EncodedEvent. | ||
| private func encodedEvent( | ||
| _ json: String, | ||
| ) throws -> ABI.EncodedEvent<ABI.CurrentVersion> { | ||
| var json = json | ||
| return try json.withUTF8 { json in | ||
| try JSON.decode(ABI.EncodedEvent<ABI.CurrentVersion>.self, from: UnsafeRawBufferPointer(json)) | ||
| } | ||
| } | ||
|
|
||
| @Test func `Decoded event always has nil testID and testCaseID`() throws { | ||
| let event = try encodedEvent( | ||
| """ | ||
| { | ||
| "kind": "testStarted", | ||
| "instant": {"absolute": 123, "since1970": 456}, | ||
| "messages": [], | ||
| "testID": "SomeValidTestID/testFunc()" | ||
| } | ||
| """) | ||
| let decoded = try #require(Event(decoding: event)) | ||
|
|
||
| #expect(decoded.testID == nil) | ||
| #expect(decoded.testCaseID == nil) | ||
| } | ||
|
|
||
| @Test(arguments: [ | ||
| "runStarted", | ||
| "runEnded", | ||
| "testStarted", | ||
| "testEnded", | ||
| "testCaseStarted", | ||
| "testCaseEnded", | ||
| // Following `kind`s need SkipInfo which nominally requires _sourceLocation. | ||
| // However, an empty placeholder SkipInfo can be provided when decoding. | ||
| // vvv | ||
| "testCaseCancelled", | ||
| "testSkipped", | ||
| "testCancelled", | ||
| ]) func `Successfully decode events which don't require associated info`(kind: String) throws { | ||
| let event = try encodedEvent( | ||
| """ | ||
| { | ||
| "kind": "\(kind)", | ||
| "instant": {"absolute": 123, "since1970": 456}, | ||
| "messages": [], | ||
| } | ||
| """) | ||
|
|
||
| #expect(Event(decoding: event) != nil) | ||
| } | ||
|
|
||
| @Test(arguments: [ | ||
| "issueRecorded", // Needs issue details | ||
| "valueAttached", // Needs attachment details | ||
| ]) func `Events without required associated info fail to decode`(kind: String) throws { | ||
| let event = try encodedEvent( | ||
| """ | ||
| { | ||
| "kind": "\(kind)", | ||
| "instant": {"absolute": 123, "since1970": 456}, | ||
| "messages": [], | ||
| } | ||
| """) | ||
|
|
||
| #expect(Event(decoding: event) == nil) | ||
| } | ||
|
|
||
| @Test func `Decode issueRecorded`() throws { | ||
| let event = try encodedEvent( | ||
| """ | ||
| { | ||
| "kind": "issueRecorded", | ||
| "instant": {"absolute": 0, "since1970": 0}, | ||
| "messages": [], | ||
| "issue": {"isKnown": true} | ||
| } | ||
| """) | ||
| let decoded = try #require(Event(decoding: event)) | ||
|
|
||
| guard case .issueRecorded(let issue) = decoded.kind else { | ||
|
jerryjrchen marked this conversation as resolved.
|
||
| Issue.record("Expected issueRecorded but got wrong kind \(decoded.kind)") | ||
| return | ||
| } | ||
| #expect(issue.isKnown) | ||
| } | ||
|
|
||
| @Test func `Decode valueAttached`() throws { | ||
| let event = try encodedEvent( | ||
| """ | ||
| { | ||
| "kind": "valueAttached", | ||
| "instant": {"absolute": 0, "since1970": 0}, | ||
| "messages": [], | ||
| "attachment": {"path": "/tmp/important-cheese.txt"} | ||
| } | ||
| """) | ||
| let decoded = try #require(Event(decoding: event)) | ||
|
|
||
| guard case .valueAttached = decoded.kind else { | ||
| Issue.record("Expected valueAttached but got wrong kind \(decoded.kind)") | ||
| return | ||
| } | ||
| } | ||
| #endif | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it'll just be follow-on work to fill in these missing property values, I take it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test.Case.IDisn't stable yet, so we can't really decode it right now.Test.IDmay need to be modified to allow it to take a flat string instead of aSourceLocation, but I think it's feasible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok to have as nil for the time being because interop does not look at this field.