swift-testing icon indicating copy to clipboard operation
swift-testing copied to clipboard

Create a separate library containing a fallback event handler.

Open grynspan opened this issue 3 months ago • 6 comments

This PR adds an experimental helper library that contains a hook function called the "fallback event handler". When Swift Testing posts an event such as "issue recorded", but Swift Testing itself isn't the running testing library (i.e. XCTest is actually running), it calls the fallback event handler and passes the event (JSON-encoded) to it.

Because the hook function is exported from a separate library, XCTest can (in theory, anyway) set the fallback event handler to a function that decodes the JSON-encoded event and translates it into the corresponding XCTest event.

Swift Testing sets the fallback event handler itself when it starts running so that, conversely, if a testing library such as XCTest were to generate an event and determine it isn't running, it could post that event to the same event handler and have Swift Testing pick it up and translate it into a Swift Testing event.

So that if you have code that calls #expect() from within XCTest, or if you have code that calls XCTAssert() from within Swift Testing, it'll "just work™".

Checklist:

  • [x] Code and documentation should follow the style of the Style Guide.
  • [x] If public symbols are renamed or modified, DocC references should be updated.

grynspan avatar Aug 20 '25 20:08 grynspan

@swift-ci test

grynspan avatar Aug 20 '25 20:08 grynspan

@swift-ci test

grynspan avatar Aug 20 '25 21:08 grynspan

@swift-ci test

grynspan avatar Aug 21 '25 13:08 grynspan

@swift-ci test

grynspan avatar Aug 21 '25 14:08 grynspan

@swift-ci test

grynspan avatar Aug 26 '25 21:08 grynspan

@swift-ci test

grynspan avatar Aug 26 '25 21:08 grynspan