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

[6.0] Set an environment variable in swift test to indicate which testing library is in use. #7577

Merged

Conversation

grynspan
Copy link
Contributor

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

… 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.
@grynspan grynspan added bug swift test Changes impacting `swift test` tool swift 6.0 Related to Swift 6.0 release branch labels May 17, 2024
@grynspan grynspan self-assigned this May 17, 2024
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan changed the title Set an environment variable in swift test to indicate which testing library is in use. [6.0] Set an environment variable in swift test to indicate which testing library is in use. May 17, 2024
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan
Copy link
Contributor Author

@swift-ci please test Windows

@grynspan
Copy link
Contributor Author

Will cherry-pick over the unit test from the main branch PR on Monday.

@grynspan
Copy link
Contributor Author

Eh, I've got time now.

@grynspan
Copy link
Contributor Author

Wait… I already did the thing. MERGING.

@grynspan grynspan merged commit 423ffae into release/6.0 May 17, 2024
5 checks passed
@grynspan grynspan deleted the jgrynspan/128272138-envvar-for-active-test-library-6.0 branch May 17, 2024 23:38
@@ -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)
Copy link
Contributor

@jakepetroules jakepetroules May 21, 2024

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.

#7584

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug swift test Changes impacting `swift test` tool swift 6.0 Related to Swift 6.0 release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants