Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SourceKitLSP/Swift/SwiftTestingScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
}

let name =
node.name.text + "(" + node.signature.parameterClause.parameters.map { "\($0.firstName):" }.joined() + ")"

Choose a reason for hiding this comment

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

So, this is still not quite correct because of optional leading/trailing backticks. See swiftlang/swift-syntax#1936.

swift-testing has logic to trim these off that you may need to adopt.

Copy link
Contributor Author

@plemarquand plemarquand Apr 30, 2024

Choose a reason for hiding this comment

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

Seems like the best course of action is to leverage swiftlang/swift-syntax#2576 when its ready. @ahoppen In the short term is it worth stripping the backticks in the TestItem initializer until the proper solution is merged?

Choose a reason for hiding this comment

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

Long-term yes, short-term we'll need you to remove them manually I think. (Whether or not it's "worth it" is subjective, but swift-testing's own test suite checks for this sort of thing.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ahoppen @grynspan I think its worth merging this on its own and addressing the backticks in a follow up.

Copy link

Choose a reason for hiding this comment

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

That's fine—let's just not forget.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #1211 as a stopgap until swiftlang/swift-syntax#2576 is ready

node.name.text + "(" + node.signature.parameterClause.parameters.map { "\($0.firstName.trimmed):" }.joined() + ")"

let range = snapshot.range(of: node.positionAfterSkippingLeadingTrivia..<node.endPositionBeforeTrailingTrivia)
let testItem = TestItem(
Expand Down
90 changes: 90 additions & 0 deletions Tests/SourceKitLSPTests/DocumentTestDiscoveryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,96 @@ final class DocumentTestDiscoveryTests: XCTestCase {
)
}

func testParameterizedSwiftTestingTestWithAnonymousArgument() async throws {
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.swift)

let positions = testClient.openDocument(
"""
import Testing

1️⃣struct MyTests {
2️⃣@Test(arguments: [0, 1, 2])
func numbersAreOne(_ x: Int) {
#expect(x == 1)
}3️⃣
}4️⃣
""",
uri: uri
)

let tests = try await testClient.send(DocumentTestsRequest(textDocument: TextDocumentIdentifier(uri)))
XCTAssertEqual(
tests,
[
TestItem(
id: "MyTests",
label: "MyTests",
disabled: false,
style: TestStyle.swiftTesting,
location: Location(uri: uri, range: positions["1️⃣"]..<positions["4️⃣"]),
children: [
TestItem(
id: "MyTests/numbersAreOne(_:)",
label: "numbersAreOne(_:)",
disabled: false,
style: TestStyle.swiftTesting,
location: Location(uri: uri, range: positions["2️⃣"]..<positions["3️⃣"]),
children: [],
tags: []
)
],
tags: []
)
]
)
}

func testParameterizedSwiftTestingTestWithCommentInSignature() async throws {
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.swift)

let positions = testClient.openDocument(
"""
import Testing

1️⃣struct MyTests {
2️⃣@Test(arguments: [0, 1, 2])
func numbersAreOne(x /* hello */: Int) {
#expect(x == 1)
}3️⃣
}4️⃣
""",
uri: uri
)

let tests = try await testClient.send(DocumentTestsRequest(textDocument: TextDocumentIdentifier(uri)))
XCTAssertEqual(
tests,
[
TestItem(
id: "MyTests",
label: "MyTests",
disabled: false,
style: TestStyle.swiftTesting,
location: Location(uri: uri, range: positions["1️⃣"]..<positions["4️⃣"]),
children: [
TestItem(
id: "MyTests/numbersAreOne(x:)",
label: "numbersAreOne(x:)",
disabled: false,
style: TestStyle.swiftTesting,
location: Location(uri: uri, range: positions["2️⃣"]..<positions["3️⃣"]),
children: [],
tags: []
)
],
tags: []
)
]
)
}

func testSwiftTestingSuiteWithNoTests() async throws {
let testClient = try await TestSourceKitLSPClient()
let uri = DocumentURI.for(.swift)
Expand Down