8
8
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9
9
//
10
10
11
- internal import _Testing_ExperimentalInfrastructure
12
-
13
11
/// An event that occurred during testing.
14
12
@_spi ( ForToolsIntegrationOnly)
15
13
public struct Event : Sendable {
@@ -272,60 +270,6 @@ extension Event {
272
270
}
273
271
}
274
272
275
- /// The implementation of ``fallbackEventHandler``.
276
- ///
277
- /// - Parameters:
278
- /// - abi: The ABI version to use for decoding `recordJSON`.
279
- /// - recordJSON: The JSON encoding of an event record.
280
- ///
281
- /// - Throws: Any error that prevented handling the encoded record.
282
- private static func _fallbackEventHandler< V> ( _ abi: V . Type , _ recordJSON: UnsafeRawBufferPointer ) throws where V: ABI . Version {
283
- let record = try JSON . decode ( ABI . Record< ABI . CurrentVersion> . self , from: recordJSON)
284
- guard case let . event( event) = record. kind else {
285
- return
286
- }
287
- switch event. kind {
288
- case . issueRecorded:
289
- Issue ( event) ? . record ( )
290
- case . valueAttached:
291
- if let attachment = event. attachment {
292
- Attachment . record ( attachment, sourceLocation: attachment. _sourceLocation ?? . __here( ) )
293
- }
294
- default :
295
- // Not handled here.
296
- break
297
- }
298
- }
299
-
300
- /// The fallback event handler to set when Swift Testing is the active testing
301
- /// library.
302
- ///
303
- /// ## See Also
304
- ///
305
- /// - `swift_testing_getFallbackEventHandler()`
306
- /// - `swift_testing_setFallbackEventHandler()`
307
- static let fallbackEventHandler : FallbackEventHandler = { recordJSONSchemaVersionNumber, recordJSONBaseAddress, recordJSONByteCount, _ in
308
- let abi = String ( validatingCString: recordJSONSchemaVersionNumber)
309
- . flatMap ( VersionNumber . init)
310
- . flatMap ( ABI . version ( forVersionNumber: ) )
311
- if let abi {
312
- let recordJSON = UnsafeRawBufferPointer ( start: recordJSONBaseAddress, count: recordJSONByteCount)
313
- try ! Self . _fallbackEventHandler ( abi, recordJSON)
314
- }
315
- }
316
-
317
- /// The implementation of ``installFallbackEventHandler()``.
318
- private static let _installFallbackHandler : Bool = {
319
- _Testing_ExperimentalInfrastructure. installFallbackEventHandler ( Self . fallbackEventHandler)
320
- } ( )
321
-
322
- /// Install the testing library's fallback event handler.
323
- ///
324
- /// - Returns: Whether or not the handler was installed.
325
- static func installFallbackHandler( ) -> Bool {
326
- _installFallbackHandler
327
- }
328
-
329
273
/// Post this event to the currently-installed event handler.
330
274
///
331
275
/// - Parameters:
@@ -348,19 +292,8 @@ extension Event {
348
292
if configuration. eventHandlingOptions. shouldHandleEvent ( self ) {
349
293
configuration. handleEvent ( self , in: context)
350
294
}
351
- } else if let fallbackEventHandler = _Testing_ExperimentalInfrastructure. fallbackEventHandler ( ) ,
352
- castCFunction ( fallbackEventHandler, to: UnsafeRawPointer . self) != castCFunction ( Self . fallbackEventHandler, to: UnsafeRawPointer . self) {
353
- // Some library other than Swift Testing has set a fallback event handler.
354
- // Encode the event as JSON and call it.
355
- let fallbackEventHandler = ABI . CurrentVersion. eventHandler ( encodeAsJSONLines: false ) { recordJSON in
356
- fallbackEventHandler (
357
- String ( describing: ABI . CurrentVersion. versionNumber) ,
358
- recordJSON. baseAddress!,
359
- recordJSON. count,
360
- nil
361
- )
362
- }
363
- fallbackEventHandler ( self , context)
295
+ } else if postToFallbackHandler ( in: context) {
296
+ // The fallback event handler handled this event.
364
297
} else {
365
298
// The current task does NOT have an associated configuration. This event
366
299
// will be lost! Post it to every registered event handler to avoid that.
0 commit comments