Skip to content

Commit 22d7705

Browse files
authored
Change the default JSON schema version to v0. (#530)
This PR changes the default JSON schema version for event stream output to version 0 (the version documented in #479.) Previously, if a caller did not specify a version number for the event stream, it would default to encoding "snapshots" of various values from the testing library. Xcode 16 Beta 1 uses this legacy format, so to continue supporting newer betas of Xcode 16 transitionally, this PR temporarily enables a "-1" JSON schema version that continues to emit snapshot encodings. This JSON schema version will be removed (along with the snapshots code in general) in a future update once Xcode has migrated. Resolves #527. ### 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.
1 parent ad95db1 commit 22d7705

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

Diff for: Sources/Testing/EntryPoints/ABIv0/ABIv0.Record+Streaming.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ extension ABIv0.Record {
5757
/// External adopters are not necessarily written in Swift and are expected to
5858
/// decode the JSON produced for this type in implementation-specific ways.
5959
///
60-
/// - Warning: This type will be removed when the ABI version 0 JSON schema is
61-
/// finalized.
60+
/// - Warning: This type supports early Xcode 16 betas and will be removed in a
61+
/// future update.
6262
struct EventAndContextSnapshot {
6363
/// A snapshot of the event.
6464
var event: Event.Snapshot
@@ -86,8 +86,8 @@ extension EventAndContextSnapshot: Codable {}
8686
/// performs additional postprocessing before writing JSON data to ensure it
8787
/// does not contain any newline characters.
8888
///
89-
/// - Warning: This function will be removed when the ABI version 0 JSON schema
90-
/// is finalized.
89+
/// - Warning: This function supports early Xcode 16 betas and will be removed
90+
/// in a future update.
9191
func eventHandlerForStreamingEventSnapshots(
9292
to eventHandler: @escaping @Sendable (_ eventAndContextJSON: UnsafeRawBufferPointer) -> Void
9393
) -> Event.Handler {

Diff for: Sources/Testing/EntryPoints/ABIv0/Encoded/ABIv0.EncodedTest.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ extension ABIv0 {
8181
let testIsParameterized = test.isParameterized
8282
isParameterized = testIsParameterized
8383
if testIsParameterized {
84-
_testCases = test.testCases?.map(EncodedTestCase.init(encoding:))
84+
_testCases = test.uncheckedTestCases?.map(EncodedTestCase.init(encoding:))
8585
}
8686
}
8787
name = test.name

Diff for: Sources/Testing/EntryPoints/EntryPoint.swift

+9-7
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ public struct __CommandLineArguments_v0: Sendable {
220220
/// The version of the event stream schema to use when writing events to
221221
/// ``experimentalEventStreamOutput``.
222222
///
223-
/// If the value of this property is `nil`, events are encoded verbatim (using
224-
/// ``Event/Snapshot``.) Otherwise, the corresponding stable schema is used
225-
/// (e.g. ``ABIv0/Record`` for `0`.)
223+
/// The corresponding stable schema is used to encode events to the event
224+
/// stream (for example, ``ABIv0/Record`` is used if the value of this
225+
/// property is `0`.)
226226
///
227-
/// - Warning: The behavior of this property will change when the ABI version
228-
/// 0 JSON schema is finalized.
227+
/// If the value of this property is `nil`, the testing library assumes that
228+
/// the newest available schema should be used.
229229
public var experimentalEventStreamVersion: Int?
230230

231231
/// The value(s) of the `--filter` argument.
@@ -482,9 +482,11 @@ public func configurationForEntryPoint(from args: __CommandLineArguments_v0) thr
482482
/// - Throws: If `version` is not a supported ABI version.
483483
func eventHandlerForStreamingEvents(version: Int?, forwardingTo eventHandler: @escaping @Sendable (UnsafeRawBufferPointer) -> Void) throws -> Event.Handler {
484484
switch version {
485-
case nil:
485+
case -1:
486+
// Legacy support for Xcode 16 betas. Support for this undocumented version
487+
// will be removed in a future update. Do not use it.
486488
eventHandlerForStreamingEventSnapshots(to: eventHandler)
487-
case 0:
489+
case nil, 0:
488490
ABIv0.Record.eventHandler(forwardingTo: eventHandler)
489491
case let .some(unsupportedVersion):
490492
throw _EntryPointError.invalidArgument("--experimental-event-stream-version", value: "\(unsupportedVersion)")

Diff for: Sources/Testing/Test.swift

+17
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,23 @@ public struct Test: Sendable {
128128
}
129129
}
130130

131+
/// Equivalent to ``testCases``, but without requiring that the test cases be
132+
/// evaluated first.
133+
///
134+
/// Most callers should not use this property and should prefer ``testCases``
135+
/// since it will help catch logic errors in the testing library. Use this
136+
/// property if you are interested in the test's test cases, but the test has
137+
/// not been evaluated by an instance of ``Runner/Plan`` (e.g. if you are
138+
/// implementing `swift test list`.)
139+
var uncheckedTestCases: (some Sequence<Test.Case>)? {
140+
testCasesState.flatMap { testCasesState in
141+
if case let .evaluated(testCases) = testCasesState {
142+
return testCases
143+
}
144+
return nil
145+
}
146+
}
147+
131148
/// Evaluate this test's cases if they have not been evaluated yet.
132149
///
133150
/// The arguments of a test are captured into a closure so they can be lazily

0 commit comments

Comments
 (0)