Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Testing test identifier from test context #125

Merged
merged 13 commits into from
Sep 6, 2024

Conversation

stephencelis
Copy link
Member

It can be useful to distinguish between tests in addition to knowing the test context, so let's surface some of that data.

One example use case, preventing global state from bleeding between tests in our Dependencies library: pointfreeco/swift-dependencies#269

/// Testing framework, or Xcode's XCTest framework.
public enum TestContext {
/// The Swift Testing framework.
case swiftTesting
case swiftTesting(Testing)
Copy link
Member Author

Choose a reason for hiding this comment

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

Technically this is a breaking change for folks referring directly to this .swiftTesting case, so we could introduce a new set of alternate APIs here instead.

If someone was merely switching over the cases in their test helper it should be source compatible, though.

Comment on lines 8 to 13
#expect(TestContext.current == .swiftTesting)
switch TestContext.current {
case .swiftTesting:
#expect(true)
default:
Issue.record()
}
Copy link
Member Author

Choose a reason for hiding this comment

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

An example API breakage and fix.

@stephencelis stephencelis merged commit 0e10568 into main Sep 6, 2024
13 checks passed
@stephencelis stephencelis deleted the testing-test-context branch September 6, 2024 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants