-
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 most WorkspaceTests to Swift Testing #8092
base: main
Are you sure you want to change the base?
Convert most WorkspaceTests to Swift Testing #8092
Conversation
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 |
// Test `ManifestAccessError.Kind.isADirectory` | ||
XCTAssertThrowsError( | ||
|
||
#expect{ |
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.
As above
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 changed this to
#expect(throws: ToolsVersionSpecificationWriter.ManifestAccessError(.isADirectory, at: manifestFilePath.parentDirectory)) {
try ToolsVersionSpecificationWriter.rewriteSpecification(
manifestDirectory: manifestFilePath.parentDirectory.parentDirectory, // /pkg/
toolsVersion: toolsVersion,
fileSystem: inMemoryFileSystem
)
}
and got the following compilation error
/Users/bkhouri/Documents/git/public/swiftlang/swift-package-manager/Tests/WorkspaceTests/ToolsVersionSpecificationRewriterTests.swift:153:9: error: macro 'expect(throws:_:sourceLocation:performing:)' requires that 'ToolsVersionSpecificationWriter.ManifestAccessError' conform to 'Equatable'
151 | return isExpectedKind && isExpectedDescription
152 | }
153 | #expect(throws: ToolsVersionSpecificationWriter.ManifestAccessError(.isADirectory, at: manifestFilePath.parentDirectory)) {
| `- error: macro 'expect(throws:_:sourceLocation:performing:)' requires that 'ToolsVersionSpecificationWriter.ManifestAccessError' conform to 'Equatable'
154 | try ToolsVersionSpecificationWriter.rewriteSpecification(
155 | manifestDirectory: manifestFilePath.parentDirectory.parentDirectory, // /pkg/
Testing.expect:1:40: note: where 'E' = 'ToolsVersionSpecificationWriter.ManifestAccessError'
1 | @freestanding(expression) public macro expect<E, R>(throws error: E, _ comment: @autoclosure () -> Testing.Comment? = nil, sourceLocation: Testing.SourceLocation = #_sourceLocation, performing expression: () async throws -> R) = #externalMacro(module: "TestingMacros", type: "ExpectMacro") where E : Equatable, E : Error
| `- note: where 'E' = 'ToolsVersionSpecificationWriter.ManifestAccessError'
[5/6] Compiling WorkspaceTests ToolsVersionSpecificationRewriterTests.swift
Am I doing something wrong here? If feels odd modifying the production code just to make the test compile. is this the norm in Swift?
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.
It means this Error
type doesn't conform to Equatable
, so we can't just compare instances of it. You have three choices:
- Modify the error type to be
Equatable
(may not be possible depending on the cases), - Use
#expect(throws: ToolsVersionSpecificationWriter.ManifestAccessError.self)
so it only filters on type rather than exact error (which is often sufficient for test purposes), or - Continue using
#expect {} throws: {}
, except I'm deprecating 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 would like to validate the exact error as it's more precise test. So I'll leave it as is for now and update once it's deprecated .
6d94d63
to
f47210e
Compare
@swift-ci test |
f47210e
to
9f5c767
Compare
@swift-ci test self hosted |
9f5c767
to
9fa6a3b
Compare
@swift-ci test self hosted |
1 similar comment
@swift-ci test self hosted |
This PR is blocked by #8137 |
Convert most of the WorkspaceTests from XCTests to Swift Testing to make use of parallelism and, in some cases, test parameterization. Not all Test Suites in WorkspaceTests have been converted as some use helpers in swift-tools-core-support, which don't have a matching Swift Testing helper.
9fa6a3b
to
b43eea7
Compare
@swift-ci please test |
Please test with following pull request: @swift-ci Please smoke test |
Please test with following pull request: @swift-ci Please test |
2 similar comments
Please test with following pull request: @swift-ci Please test |
Please test with following pull request: @swift-ci Please test |
@swift-ci please test windows |
Please test with following pull request: @swift-ci Please smoke test Linux platform |
Please test with following pull request: @swift-ci Please test Linux |
Convert most of the WorkspaceTests from XCTests 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 WorkspaceTests 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