Skip to content

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Aug 20, 2025

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:

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

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™".
@grynspan grynspan added this to the Swift 6.x (main) milestone Aug 20, 2025
@grynspan grynspan added enhancement New feature or request tools integration 🛠️ Integration of swift-testing into tools/IDEs issue-handling Related to Issue handling within the testing library attachments/activities 🖇️ Work related to attachments and/or activities labels Aug 20, 2025
@grynspan
Copy link
Contributor Author

@swift-ci test

@@ -203,7 +203,8 @@ sufficient information to display the event in a human-readable format.
}

<attachment> ::= {
"path": <string>, ; the absolute path to the attachment on disk
["path": <string>,] ; the absolute path to the attachment on disk if it has
Copy link
Contributor Author

@grynspan grynspan Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is not set if an attachment wasn't saved to disk already, so it should be optional in the schema.

// MARK: - Converting back to an Issue

extension Issue {
/// Attempt to reconstruct an instance of ``Issue`` from the given encoded
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this code from ExitTest.swift so we can reuse it.

@grynspan
Copy link
Contributor Author

@swift-ci test

1 similar comment
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attachments/activities 🖇️ Work related to attachments and/or activities enhancement New feature or request issue-handling Related to Issue handling within the testing library tools integration 🛠️ Integration of swift-testing into tools/IDEs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants