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