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

Convert most WorkspaceTests to Swift Testing #8092

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bkhouri
Copy link
Contributor

@bkhouri bkhouri commented Nov 1, 2024

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

for _ in $(seq 0 100); 
do
    swift test --enable-swift-testing --disable-xctest
done

and ensured there were no test-related failures.

Blocked by #8137
Requires swiftlang/swift#78300

@bkhouri bkhouri changed the title [DRAFT] Convert most WorkspaceTests to Swift Testing Convert most WorkspaceTests to Swift Testing Nov 7, 2024
@bkhouri
Copy link
Contributor Author

bkhouri commented Nov 7, 2024

Ready for review, though it may be blocked as not all pipeline builds run with Swift 6.0!

@bkhouri
Copy link
Contributor Author

bkhouri commented Nov 8, 2024

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
https://ci.swift.org/job/swift-package-manager-with-xcode-self-hosted-PR-osx/4511/execution/node/49/log/

// Test `ManifestAccessError.Kind.isADirectory`
XCTAssertThrowsError(

#expect{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

Copy link
Contributor Author

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?

Copy link
Contributor

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:

  1. Modify the error type to be Equatable (may not be possible depending on the cases),
  2. Use #expect(throws: ToolsVersionSpecificationWriter.ManifestAccessError.self) so it only filters on type rather than exact error (which is often sufficient for test purposes), or
  3. Continue using #expect {} throws: {}, except I'm deprecating it. :)

Copy link
Contributor Author

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 .

@bkhouri bkhouri force-pushed the t/main/bkhouri_convert_Workspacetests_XCtests_to_swift_testing branch from 6d94d63 to f47210e Compare November 13, 2024 05:08
@plemarquand
Copy link
Contributor

@swift-ci test

@bkhouri bkhouri marked this pull request as draft November 14, 2024 17:55
@bkhouri bkhouri force-pushed the t/main/bkhouri_convert_Workspacetests_XCtests_to_swift_testing branch from f47210e to 9f5c767 Compare November 20, 2024 18:20
@shahmishal
Copy link
Member

@swift-ci test self hosted

@bkhouri bkhouri force-pushed the t/main/bkhouri_convert_Workspacetests_XCtests_to_swift_testing branch from 9f5c767 to 9fa6a3b Compare November 22, 2024 01:43
@shahmishal
Copy link
Member

@swift-ci test self hosted

1 similar comment
@shahmishal
Copy link
Member

@swift-ci test self hosted

@bkhouri
Copy link
Contributor Author

bkhouri commented Nov 22, 2024

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.
@bkhouri bkhouri force-pushed the t/main/bkhouri_convert_Workspacetests_XCtests_to_swift_testing branch from 9fa6a3b to b43eea7 Compare December 3, 2024 16:24
@bkhouri
Copy link
Contributor Author

bkhouri commented Dec 19, 2024

@swift-ci please test

@bkhouri bkhouri marked this pull request as ready for review December 19, 2024 01:25
@bkhouri
Copy link
Contributor Author

bkhouri commented Dec 19, 2024

Please test with following pull request:
swiftlang/swift#78300

@swift-ci Please smoke test

@bkhouri
Copy link
Contributor Author

bkhouri commented Dec 19, 2024

Please test with following pull request:
swiftlang/swift#78300

@swift-ci Please test

2 similar comments
@bkhouri
Copy link
Contributor Author

bkhouri commented Dec 19, 2024

Please test with following pull request:
swiftlang/swift#78300

@swift-ci Please test

@bkhouri
Copy link
Contributor Author

bkhouri commented Dec 20, 2024

Please test with following pull request:
swiftlang/swift#78300

@swift-ci Please test

@bkhouri
Copy link
Contributor Author

bkhouri commented Dec 20, 2024

@swift-ci please test windows

@bkhouri
Copy link
Contributor Author

bkhouri commented Dec 20, 2024

Please test with following pull request:
swiftlang/swift#78300

@swift-ci Please smoke test Linux platform

@bkhouri
Copy link
Contributor Author

bkhouri commented Dec 20, 2024

Please test with following pull request:
swiftlang/swift#78300

@swift-ci Please test Linux

@bkhouri bkhouri added the test suite improvements to SwiftPM test suite label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test suite improvements to SwiftPM test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants