-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Tests: Convert some tests BasicsTests to Swift Testing #8093
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
base: main
Are you sure you want to change the base?
Tests: Convert some tests BasicsTests to Swift Testing #8093
Conversation
public func isRunninginCI(file: StaticString = #filePath, line: UInt = #line) -> Bool { | ||
return (ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] != nil || ProcessInfo.processInfo.environment["CI"] != nil) | ||
} | ||
|
||
public func XCTSkipIfCI(file: StaticString = #filePath, line: UInt = #line) throws { |
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.
The idiomatic way to do this with SwiftTesting would be a trait, something like this:
extension Trait where Self == Testing.ConditionTrait {
static var skipInCI: Self {
disabled("the test is being run on CI", ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] != nil || ProcessInfo.processInfo.environment["CI"] != nil)
}
}
Ready for review, though it may be blocked as not all pipeline builds run with Swift 6.0! |
Looks like the Selft-hosted macOS pipeline is now running the nightly build |
) | ||
struct AsyncProcessTests { | ||
@Test | ||
func basics() throws { | ||
do { | ||
let process = AsyncProcess(args: "echo", "hello") | ||
try process.launch() | ||
let result = try process.waitUntilExit() |
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 line is presumably actually blocking the thread, which is dangerous in Swift Testing because tests run on the shared thread pool. Consider switching over to an asynchronous suspension.
|
||
// Check that there's no error if we try to create the directory again. | ||
try! makeDirectories(dirPath) | ||
#expect(throws: Never.self) { |
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.
Just throw the error.
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.
Here, I want to explicitly indicate a test intentions is to not have an exception raised. Otherwise, future test authors might be include to catch and handle the error!
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.
You should probably never catch thrown errors in tests unless the test is itself testing that an error should be thrown. In general, allow the error to propagate out so that the testing library (XCTest or Swift Testing) can gather optimal metadata for it.
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.
I understand, but how do we handle the case where we explicitly want to validate that an error did not occur?
@swift-ci please test |
9bb616d
to
7eebb04
Compare
@swift-ci please test |
7eebb04
to
4593699
Compare
@swift-ci please test |
4593699
to
d252933
Compare
@swift-ci please test |
Add a canary swift testing tests to ensure we do not regress. This test will be removed sometime after swiftlang#8092, swiftlang#8093 or swiftlang#8100 are merged (cherry picked from commit 257e671)
Add a canary swift testing tests to ensure we do not regress. This test will be removed sometime after swiftlang#8092, swiftlang#8093 or swiftlang#8100 are merged (cherry picked from commit 257e671)
Add a canary swift testing tests to ensure we do not regress. This test will be removed sometime after swiftlang#8092, swiftlang#8093 or swiftlang#8100 are merged (cherry picked from commit 257e671)
Add a canary swift testing tests to ensure we do not regress. This test will be removed sometime after swiftlang#8092, swiftlang#8093 or swiftlang#8100 are merged
Add a canary swift testing tests to ensure we do not regress. This test will be removed sometime after swiftlang#8092, swiftlang#8093 or swiftlang#8100 are merged (cherry picked from commit 257e671) Re-adds swiftlang#8222, after it was reverted in swiftlang#8266 Depends on swiftlang/swift#79074
@swift-ci please test linux |
Convert some BasicsTests from XCTest to Swift Testing to make use of parallelism and, in some cases, test parameterization. Not all Test Suites in BasicsTests have been converted as some use helpers in swift-tools-core-support, which don't have a matching swift testing helper.
d252933
to
7e995b7
Compare
@swift-ci please test |
@swift-ci please test windows |
@swift-ci test |
Convert some BasicsTests from XCTest to Swift Testing to make use of parallelism and, in some cases, test parameterization
Motivation:
The XCTest run, by default, sequentially. Convert most of the WorkspaceTests from XCTests to Swift Testing to make use of parallelism, and in some cases, parameterized test cases.
Not all Test Suites in BasicsTests have been converted as some use helpers in swift-tools-core-support, which don't have a matching swift testing helper.
Modifications:
Convert XCTests to Swift Testing
Result:
Ran the equivalent of
and ensured there were no test-related failures.
Blocked by #8137
Requires swiftlang/swift#78300
Might conflict with #8210