-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[6.0] Set an environment variable in swift test
to indicate which testing library is in use.
#7577
[6.0] Set an environment variable in swift test
to indicate which testing library is in use.
#7577
Conversation
… library is in use. This PR sets a new environment variable `"SWIFT_PM_TEST_LIBRARY"` to the name of the active testing library (`"XCTest"` or `"swift-testing"`.) Code in these libraries can then use the presence of this environment variable to adjust their behaviour. Resolves rdar://128272138.
@swift-ci please test |
swift test
to indicate which testing library is in use.swift test
to indicate which testing library is in use.
@swift-ci please test |
@swift-ci please test Windows |
Will cherry-pick over the unit test from the main branch PR on Monday. |
Eh, I've got time now. |
Wait… I already did the thing. MERGING. |
@@ -156,6 +159,10 @@ enum TestingSupport { | |||
env["NO_COLOR"] = "1" | |||
} | |||
|
|||
// Set an environment variable to indicate which library's test product | |||
// is being executed. | |||
env["SWIFT_PM_TEST_LIBRARY"] = String(describing: library) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is convenient for shared libraries which want to have support code that might be run by either an XCTest or SwiftTesting test case.
However, I suggest we name this more generally (for example, APPLE_TEST_LIBRARY
) because it's not SwifPM-specific, and other build tools / IDEs might want to have a uniform way to identify the Apple-provided testing library in use.
I also expect we wouldn't this environment variable if SwiftPM gained direct support for additional testing libraries from other platforms/environments, since those would likely be run via their own test harnesses which might define their own environment variables.
Explanation: Allows swift-testing and XCTest to detect at runtime which testing library SwiftPM is trying to run so that they can adjust their behaviour (e.g.
XCTestScaffold
) appropriately.Scope: Test build products at runtime.
Risk: Low. No obvious risk here to adding a new environment variable nobody is looking for.
Testing: New unit test (tested at desk, but must be temporarily disabled in CI until CI is running a version of SwiftPM that includes the change.)
Original PR: #7573