Skip to content

Commit bff4a1e

Browse files
committed
Support statically defined tags
To remove namespacing ambiguity, support statically defined tags only.
1 parent 147f7d2 commit bff4a1e

File tree

2 files changed

+18
-58
lines changed

2 files changed

+18
-58
lines changed

Sources/SourceKitLSP/Swift/SwiftTestingScanner.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,17 @@ struct TestingAttributeData {
9696
}
9797
}.flatMap(\.arguments)
9898
.compactMap {
99-
if let stringLiteral = $0.expression.as(StringLiteralExprSyntax.self) {
100-
return stringLiteral.representedLiteralValue
101-
} else if let memberAccess = $0.expression.as(MemberAccessExprSyntax.self) {
99+
if let memberAccess = $0.expression.as(MemberAccessExprSyntax.self) {
102100
var components = memberAccess.components[...]
103101
if components.starts(with: ["Testing", "Tag"]) {
104102
components = components.dropFirst(2)
105103
} else if components.starts(with: ["Tag"]) {
106104
components = components.dropFirst(1)
107105
}
108-
return components.joined(separator: ".")
106+
107+
// Tags.foo resolves to ".foo", Tags.Nested.foo resolves to "Nested.foo"
108+
let prefix = components.count == 1 ? "." : ""
109+
return "\(prefix)\(components.joined(separator: "."))"
109110
}
110111
return nil
111112
}

Tests/SourceKitLSPTests/DocumentTestDiscoveryTests.swift

Lines changed: 13 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -585,62 +585,15 @@ final class DocumentTestDiscoveryTests: XCTestCase {
585585
)
586586
}
587587

588-
func testSwiftTestingTestWithStringTags() async throws {
588+
func testSwiftTestingTestWithTags() async throws {
589589
let testClient = try await TestSourceKitLSPClient()
590590
let uri = DocumentURI.for(.swift)
591591

592592
let positions = testClient.openDocument(
593593
"""
594594
import Testing
595595
596-
1️⃣@Suite(.tags("Suites"))
597-
struct MyTests {
598-
2️⃣@Test(.tags("one", "two"))
599-
func oneIsTwo() {
600-
#expect(1 == 2)
601-
}3️⃣
602-
}4️⃣
603-
""",
604-
uri: uri
605-
)
606-
607-
let tests = try await testClient.send(DocumentTestsRequest(textDocument: TextDocumentIdentifier(uri)))
608-
XCTAssertEqual(
609-
tests,
610-
[
611-
TestItem(
612-
id: "MyTests",
613-
label: "MyTests",
614-
disabled: false,
615-
style: TestStyle.swiftTesting,
616-
location: Location(uri: uri, range: positions["1️⃣"]..<positions["4️⃣"]),
617-
children: [
618-
TestItem(
619-
id: "MyTests/oneIsTwo()",
620-
label: "oneIsTwo()",
621-
disabled: false,
622-
style: TestStyle.swiftTesting,
623-
location: Location(uri: uri, range: positions["2️⃣"]..<positions["3️⃣"]),
624-
children: [],
625-
tags: [TestTag(id: "one"), TestTag(id: "two")]
626-
)
627-
],
628-
tags: [TestTag(id: "Suites")]
629-
)
630-
]
631-
)
632-
}
633-
634-
635-
func testSwiftTestingTestWithMemberTags() async throws {
636-
let testClient = try await TestSourceKitLSPClient()
637-
let uri = DocumentURI.for(.swift)
638-
639-
let positions = testClient.openDocument(
640-
"""
641-
import Testing
642-
643-
1️⃣@Suite(.tags("Suites"))
596+
1️⃣@Suite(.tags(.green))
644597
struct MyTests {
645598
2️⃣@Test(.tags(.red, .blue))
646599
func oneIsTwo() {
@@ -669,10 +622,10 @@ final class DocumentTestDiscoveryTests: XCTestCase {
669622
style: TestStyle.swiftTesting,
670623
location: Location(uri: uri, range: positions["2️⃣"]..<positions["3️⃣"]),
671624
children: [],
672-
tags: [TestTag(id: "red"), TestTag(id: "blue")]
625+
tags: [TestTag(id: ".red"), TestTag(id: ".blue")]
673626
)
674627
],
675-
tags: [TestTag(id: "Suites")]
628+
tags: [TestTag(id: ".green")]
676629
)
677630
]
678631
)
@@ -687,6 +640,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
687640
import Testing
688641
689642
extension Tag {
643+
@Tag static var suite: Self
690644
@Tag static var foo: Self
691645
@Tag static var bar: Self
692646
@Tag static var baz: Self
@@ -696,7 +650,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
696650
}
697651
}
698652
699-
1️⃣@Suite(.tags("Suites"))
653+
1️⃣@Suite(.tags(.suite))
700654
struct MyTests {
701655
2️⃣@Test(.tags(.foo, Nested.foo, Testing.Tag.bar, Tag.baz))
702656
func oneIsTwo() {
@@ -725,10 +679,15 @@ final class DocumentTestDiscoveryTests: XCTestCase {
725679
style: TestStyle.swiftTesting,
726680
location: Location(uri: uri, range: positions["2️⃣"]..<positions["3️⃣"]),
727681
children: [],
728-
tags: [TestTag(id: "foo"), TestTag(id: "Nested.foo"), TestTag(id: "bar"), TestTag(id: "baz")]
682+
tags: [
683+
TestTag(id: ".foo"),
684+
TestTag(id: "Nested.foo"),
685+
TestTag(id: ".bar"),
686+
TestTag(id: ".baz")
687+
]
729688
)
730689
],
731-
tags: [TestTag(id: "Suites")]
690+
tags: [TestTag(id: ".suite")]
732691
)
733692
]
734693
)

0 commit comments

Comments
 (0)