-
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
Convert some tests BasicsTests to Swift Testing #8093
base: main
Are you sure you want to change the base?
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?
8ad2798
to
c3e455d
Compare
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 updated the PR, but I have a few more comments to address. This update will allow me to mark some comments are resolved, ensuring I don't miss a comment.
6f9d5a0
to
abfba54
Compare
b29877c
to
67bad81
Compare
This PR is blocked by #8137 |
67bad81
to
9bb616d
Compare
@swift-ci please test |
@swift-ci please test |
9bb616d
to
7eebb04
Compare
@swift-ci please test |
7eebb04
to
4593699
Compare
@swift-ci please test |
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.
4593699
to
d252933
Compare
@swift-ci please 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