swiftlang / swiftlang/sourcekit-lsp
`workspace/tests` returns unnecessarily disambiguated test items
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 3.9k
- Forks
- 390
- Avg merge
- 9d 5h
- Merged PRs (30d)
- 3
Description
Swift version
swift-driver version: 1.120.4 Apple Swift version 6.1 (swiftlang-6.1.0.108.3 clang-1700.0.11.1
Platform
macOS
Editor
Visual Studio Code
Description
When you have more than one XCTest test in an extension of an XCTestCase, the workspace/tests request will incorrectly return XCTests with the filename and line appended to the end of the ID for all tests in the extension. This only happens with background indexing enabled.
This disambiguation is really only supposed to be for swift-testing tests that share the same ID signature (i.e. @Test foo(_ x:Int) and @Test foo(_ x:String), which both have an id of foo(_:)).
Steps to Reproduce
Add the following test to WorkspaceTestDiscoveryTests.swift and run it:
func testXCTestExtensionWithMultipleMethodsAndBackgroundIndexing() async throws {
let project = try await SwiftPMTestProject(
files: [
"Tests/MyLibraryTests/MyTests.swift": """
import XCTest
1️⃣final class MyTests: XCTestCase {}6️⃣
extension MyTests {
2️⃣func testOne() {}3️⃣
4️⃣func testOneTwo() {}5️⃣
}
""",
],
manifest: packageManifestWithTestTarget,
enableBackgroundIndexing: true
)
let tests = try await project.testClient.send(WorkspaceTestsRequest())
XCTAssertEqual(
tests,
[
TestItem(
id: "MyLibraryTests.MyTests",
label: "MyTests",
location: try project.location(from: "1️⃣", to: "6️⃣", in: "MyTests.swift"),
children: [
TestItem(
id: "MyLibraryTests.MyTests/testOne()",
label: "testOne()",
location: try project.location(from: "2️⃣", to: "3️⃣", in: "MyTests.swift")
),
TestItem(
id: "MyLibraryTests.MyTests/testOneTwo()",
label: "testOneTwo()",
location: try project.location(from: "4️⃣", to: "5️⃣", in: "MyTests.swift")
)
]
)
]
)
}
This produces a TestItem with two children that have IDs MyLibraryTests.MyTests/testOne():MyTests.swift:4:4 MyLibraryTests.MyTests/testOneTwo():MyTests.swift:5:4
Expected:
MyLibraryTests.MyTests/testOne() MyLibraryTests.MyTests/testOneTwo()
Logging
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in WorkspaceTestDiscoveryTests.swift with testXCTestExtensionWithMultipleMethodsAndBackgroundIndexing and run it with background indexing enabled. Trace the WorkspaceTestsRequest test discovery path and update the behavior so XCTest extension methods keep IDs such as MyLibraryTests.MyTests/testOne(); the test is done when both expected child IDs are returned without filename and line suffixes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- devtools, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100