99//
1010
1111#if canImport(Foundation) && (!SWT_NO_FILE_IO || !SWT_NO_ABI_ENTRY_POINT)
12- extension ABI . Record {
12+ extension ABI . Version {
1313 /// Post-process encoded JSON and write it to a file.
1414 ///
1515 /// - Parameters:
@@ -43,25 +43,6 @@ extension ABI.Record {
4343 }
4444 }
4545
46- /// Create an event handler that encodes events as JSON and forwards them to
47- /// an ABI-friendly event handler.
48- ///
49- /// - Parameters:
50- /// - encodeAsJSONLines: Whether or not to ensure JSON passed to
51- /// `eventHandler` is encoded as JSON Lines (i.e. that it does not contain
52- /// extra newlines.)
53- /// - eventHandler: The event handler to forward events to. See
54- /// ``ABIv0/EntryPoint-swift.typealias`` for more information.
55- ///
56- /// - Returns: An event handler.
57- ///
58- /// The resulting event handler outputs data as JSON. For each event handled
59- /// by the resulting event handler, a JSON object representing it and its
60- /// associated context is created and is passed to `eventHandler`.
61- ///
62- /// Note that ``configurationForEntryPoint(from:)`` calls this function and
63- /// performs additional postprocessing before writing JSON data to ensure it
64- /// does not contain any newline characters.
6546 static func eventHandler(
6647 encodeAsJSONLines: Bool ,
6748 forwardingTo eventHandler: @escaping @Sendable ( _ recordJSON: UnsafeRawBufferPointer ) -> Void
@@ -75,12 +56,12 @@ extension ABI.Record {
7556 let humanReadableOutputRecorder = Event . HumanReadableOutputRecorder ( )
7657 return { [ eventHandler = eventHandlerCopy] event, context in
7758 if case . testDiscovered = event. kind, let test = context. test {
78- try ? JSON . withEncoding ( of: Self ( encoding: test) ) { testJSON in
59+ try ? JSON . withEncoding ( of: ABI . Record < Self> ( encoding: test) ) { testJSON in
7960 eventHandler ( testJSON)
8061 }
8162 } else {
8263 let messages = humanReadableOutputRecorder. record ( event, in: context, verbosity: 0 )
83- if let eventRecord = Self ( encoding: event, in: context, messages: messages) {
64+ if let eventRecord = ABI . Record < Self> ( encoding: event, in: context, messages: messages) {
8465 try ? JSON . withEncoding ( of: eventRecord, eventHandler)
8566 }
8667 }
@@ -89,63 +70,33 @@ extension ABI.Record {
8970}
9071
9172#if !SWT_NO_SNAPSHOT_TYPES
92- // MARK: - Experimental event streaming
73+ // MARK: - Xcode 16 Beta 1 compatibility
9374
94- /// A type containing an event snapshot and snapshots of the contents of an
95- /// event context suitable for streaming over JSON.
96- ///
97- /// This type is not part of the public interface of the testing library.
98- /// External adopters are not necessarily written in Swift and are expected to
99- /// decode the JSON produced for this type in implementation-specific ways.
100- ///
101- /// - Warning: This type supports early Xcode 16 betas and will be removed in a
102- /// future update.
103- struct EventAndContextSnapshot {
104- /// A snapshot of the event.
105- var event : Event . Snapshot
106-
107- /// A snapshot of the event context.
108- var eventContext : Event . Context . Snapshot
109- }
110-
111- extension EventAndContextSnapshot : Codable { }
75+ extension ABI . Xcode16Beta1 {
76+ static func eventHandler(
77+ encodeAsJSONLines: Bool ,
78+ forwardingTo eventHandler: @escaping @Sendable ( _ recordJSON: UnsafeRawBufferPointer ) -> Void
79+ ) -> Event . Handler {
80+ return { event, context in
81+ if case . testDiscovered = event. kind {
82+ // Discard events of this kind rather than forwarding them to avoid a
83+ // crash in Xcode 16 Beta 1 (which does not expect any events to occur
84+ // before .runStarted.)
85+ return
86+ }
11287
113- /// Create an event handler that encodes events as JSON and forwards them to an
114- /// ABI-friendly event handler.
115- ///
116- /// - Parameters:
117- /// - eventHandler: The event handler to forward events to. See
118- /// ``ABIv0/EntryPoint-swift.typealias`` for more information.
119- ///
120- /// - Returns: An event handler.
121- ///
122- /// The resulting event handler outputs data as JSON. For each event handled by
123- /// the resulting event handler, a JSON object representing it and its
124- /// associated context is created and is passed to `eventHandler`.
125- ///
126- /// Note that ``configurationForEntryPoint(from:)`` calls this function and
127- /// performs additional postprocessing before writing JSON data to ensure it
128- /// does not contain any newline characters.
129- ///
130- /// - Warning: This function supports early Xcode 16 betas and will be removed
131- /// in a future update.
132- func eventHandlerForStreamingEventSnapshots(
133- to eventHandler: @escaping @Sendable ( _ eventAndContextJSON: UnsafeRawBufferPointer ) -> Void
134- ) -> Event . Handler {
135- return { event, context in
136- if case . testDiscovered = event. kind {
137- // Discard events of this kind rather than forwarding them to avoid a
138- // crash in Xcode 16 Beta 1 (which does not expect any events to occur
139- // before .runStarted.)
140- return
141- }
142- let snapshot = EventAndContextSnapshot (
143- event: Event . Snapshot ( snapshotting: event) ,
144- eventContext: Event . Context. Snapshot ( snapshotting: context)
145- )
146- try ? JSON . withEncoding ( of: snapshot) { eventAndContextJSON in
147- eventAndContextJSON. withUnsafeBytes { eventAndContextJSON in
148- eventHandler ( eventAndContextJSON)
88+ struct EventAndContextSnapshot : Codable {
89+ var event : Event . Snapshot
90+ var eventContext : Event . Context . Snapshot
91+ }
92+ let snapshot = EventAndContextSnapshot (
93+ event: Event . Snapshot ( snapshotting: event) ,
94+ eventContext: Event . Context. Snapshot ( snapshotting: context)
95+ )
96+ try ? JSON . withEncoding ( of: snapshot) { eventAndContextJSON in
97+ eventAndContextJSON. withUnsafeBytes { eventAndContextJSON in
98+ eventHandler ( eventAndContextJSON)
99+ }
149100 }
150101 }
151102 }
0 commit comments