Merged
Conversation
This PR exposes the internal `ABI.Version` protocol as tools SPI. It includes
`ABI.VersionNumber` (which represents a Swift toolchain version in this context)
as well as the basic interfaces of `ABI.Record`, `ABI.EncodedTest`, and
`ABI.EncodedEvent` (but not individual fields thereof; we need to audit those
individually for usability/stability).
A tool can now use the exposed interfaces to handle an event stream that
produces JSON records rather than instances of `Event`:
```swift
func open<V: ABI.Version> handle(_ recordJSON: UnsafeRawBufferPointer, using _: V.Type) throws {
let record = try JSONDecoder().decode(ABI.Record<V>.self, from: Data(recordJSON))
switch record.kind {
case let .test(test):
// Test discovered!
case let .event(event):
// Event to handle!
}
}
```
In practice, the caller probably already knows the version number here, but just
in case, here's how you get it dynamically:
```swift
func handle(_ recordJSON: UnsafeRawBufferPointer) throws {
let versionNumber = try ABI.VersionNumber(fromRecordJSON: recordJSON)
guard let abi = ABI.version(fromVersionNumber: versionNumber) else {
throw ...
}
try handle(recordJSON, using: abi)
}
```
There's also `ABI.Version.eventHandler(forwardingTo:)` that automatically handles
the conversion from `Event` to `ABI.Record` for tools that want a single code
path to handle a built-in copy of Swift Testing and package copies that they
don't directly link against.
harlanhaskins
approved these changes
Feb 24, 2026
Contributor
harlanhaskins
left a comment
There was a problem hiding this comment.
This is an excellent first step, and very thorough.
…ation on code paths that don't end up using JSON
grynspan
added a commit
that referenced
this pull request
Feb 24, 2026
Follow-up to #1587. Exposes `ABI.EncodedInstant` as SPI along with some conversion helpers to get a Foundation `Date` or suspending clock instant from an instance thereof. A value of this type is associated with each event in the event stream.
2 tasks
grynspan
added a commit
that referenced
this pull request
Feb 25, 2026
Follow-up to #1587. Exposes `ABI.EncodedSourceLocation` as SPI along with some conversion helpers to go to/from a `SourceLocation` instance. A value of this type is associated with many events in the event stream.
2 tasks
…serialization on code paths that don't end up using JSON" This reverts commit 6949686.
grynspan
added a commit
that referenced
this pull request
Feb 25, 2026
Follow-up to #1587. Exposes `ABI.EncodedAttachment` as SPI. A value of this type is associated with the `valueAttached` event kind. The type already conforms to `Attachable` so it can be directly plumbed back into Swift Testing, and XCTest internally knows how to convert an `Attachable` value to an `XCTAttachment`.
grynspan
added a commit
that referenced
this pull request
Feb 25, 2026
Follow-up to #1587. Exposes `ABI.EncodedAttachment` as SPI. A value of this type is associated with the `valueAttached` event kind. The type already conforms to `Attachable` so it can be directly plumbed back into Swift Testing, and XCTest internally knows how to convert an `Attachable` value to an `XCTAttachment`.
2 tasks
stmontgomery
approved these changes
Feb 25, 2026
grynspan
added a commit
that referenced
this pull request
Feb 25, 2026
Follow-up to #1587. Exposes `ABI.EncodedSourceLocation` as SPI along with some conversion helpers to go to/from a `SourceLocation` instance. A value of this type is associated with many events in the event stream.
grynspan
added a commit
that referenced
this pull request
Feb 25, 2026
Follow-up to #1587. Exposes `ABI.EncodedAttachment` as SPI. A value of this type is associated with the `valueAttached` event kind. The type already conforms to `Attachable` so it can be directly plumbed back into Swift Testing, and XCTest internally knows how to convert an `Attachable` value to an `XCTAttachment`.
grynspan
added a commit
that referenced
this pull request
Feb 25, 2026
Follow-up to #1587. Exposes `ABI.EncodedInstant` as SPI along with some conversion helpers to get a Foundation `Date` or suspending clock instant from an instance thereof. A value of this type is associated with each event in the event stream.
grynspan
added a commit
that referenced
this pull request
Feb 25, 2026
Follow-up to #1587. Exposes `ABI.EncodedAttachment` as SPI. A value of this type is associated with the `valueAttached` event kind. The type already conforms to `Attachable` so it can be directly plumbed back into Swift Testing, and XCTest internally knows how to convert an `Attachable` value to an `XCTAttachment`.
grynspan
added a commit
that referenced
this pull request
Mar 5, 2026
Follow-up to #1587. Exposes `ABI.EncodedSourceLocation` as SPI along with some conversion helpers to go to/from a `SourceLocation` instance. A value of this type is associated with many events in the event stream. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
grynspan
added a commit
that referenced
this pull request
Mar 5, 2026
Follow-up to #1587. Exposes `ABI.EncodedInstant` as SPI along with some conversion helpers to get a Foundation `Date` or suspending clock instant from an instance thereof. A value of this type is associated with each event in the event stream. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR exposes the internal
ABI.Versionprotocol as tools SPI. It includesABI.VersionNumber(which represents a Swift toolchain version in this context) as well as the basic interfaces ofABI.Record,ABI.EncodedTest, andABI.EncodedEvent(but not individual fields thereof; we need to audit those individually for usability/stability).A tool can now use the exposed interfaces to handle an event stream that produces JSON records rather than instances of
Event:In practice, the caller probably already knows the version number here, but just in case, here's how you get it dynamically:
There's also
ABI.Version.eventHandler(forwardingTo:)that automatically handles the conversion fromEventtoABI.Recordfor tools that want a single code path to handle a built-in copy of Swift Testing and package copies that they don't directly link against.Checklist: