Skip to content

Commit 14b81cf

Browse files
committed
Fixup DocumentTestDiscoveryTests, make TestStyle an enum
1 parent bc86ff8 commit 14b81cf

File tree

6 files changed

+135
-274
lines changed

6 files changed

+135
-274
lines changed

Sources/LanguageServerProtocol/SupportTypes/TestItem.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ public struct TestTag: Codable, Equatable, Sendable {
1919
}
2020
}
2121

22+
/// An enum representing the different styles of tests that can be found in a document.
23+
public enum TestStyle: String, Codable, Sendable {
24+
/// XCTest: https://developer.apple.com/documentation/xctest
25+
case xcTest = "XCTest"
26+
27+
/// Swift Testing: https://swiftpackageindex.com/apple/swift-testing/main/documentation/testing
28+
case swiftTesting = "swift-testing"
29+
}
30+
2231
/// A test item that can be shown an a client's test explorer or used to identify tests alongside a source file.
2332
///
2433
/// A `TestItem` can represent either a test suite or a test itself, since they both have similar capabilities.
@@ -43,7 +52,7 @@ public struct TestItem: ResponseType, Equatable {
4352
public var disabled: Bool
4453

4554
/// The type of test, eg. the testing framework that was used to declare the test.
46-
public var style: String
55+
public var style: TestStyle
4756

4857
/// The location of the test item in the source code.
4958
public var location: Location
@@ -62,7 +71,7 @@ public struct TestItem: ResponseType, Equatable {
6271
description: String? = nil,
6372
sortText: String? = nil,
6473
disabled: Bool,
65-
style: String,
74+
style: TestStyle,
6675
location: Location,
6776
children: [TestItem],
6877
tags: [TestTag]

Sources/SourceKitLSP/Swift/SwiftTestingScanner.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
257257
id: (parentTypeNames + typeNames).joined(separator: "/"),
258258
label: attributeData?.displayName ?? typeNames.last!,
259259
disabled: (attributeData?.isDisabled ?? false) || allTestsDisabled,
260-
style: TestStyle.swiftTesting,
260+
style: .swiftTesting,
261261
location: Location(uri: snapshot.uri, range: range),
262262
children: memberScanner.result.map(\.testItem),
263263
tags: attributeData?.tags.map(TestTag.init(id:)) ?? []
@@ -330,7 +330,7 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
330330
id: (parentTypeNames + [name]).joined(separator: "/"),
331331
label: attributeData.displayName ?? name,
332332
disabled: attributeData.isDisabled || allTestsDisabled,
333-
style: TestStyle.swiftTesting,
333+
style: .swiftTesting,
334334
location: Location(uri: snapshot.uri, range: range),
335335
children: [],
336336
tags: attributeData.tags.map(TestTag.init(id:))

Sources/SourceKitLSP/Swift/SyntacticSwiftXCTestScanner.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ final class SyntacticSwiftXCTestScanner: SyntaxVisitor {
7272
id: "\(containerName)/\(function.name.text)()",
7373
label: "\(function.name.text)()",
7474
disabled: false,
75-
style: TestStyle.xcTest,
75+
style: .xcTest,
7676
location: Location(uri: snapshot.uri, range: range),
7777
children: [],
7878
tags: []
@@ -106,7 +106,7 @@ final class SyntacticSwiftXCTestScanner: SyntaxVisitor {
106106
id: node.name.text,
107107
label: node.name.text,
108108
disabled: false,
109-
style: TestStyle.xcTest,
109+
style: .xcTest,
110110
location: Location(uri: snapshot.uri, range: range),
111111
children: testMethods,
112112
tags: []

Sources/SourceKitLSP/TestDiscovery.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ import LanguageServerProtocol
1616
import SemanticIndex
1717
import SwiftSyntax
1818

19-
public enum TestStyle {
20-
public static let xcTest = "XCTest"
21-
public static let swiftTesting = "swift-testing"
22-
}
23-
2419
fileprivate extension SymbolOccurrence {
2520
/// Assuming that this is a symbol occurrence returned by the index, return whether it can constitute the definition
2621
/// of a test case.
@@ -155,7 +150,7 @@ extension SourceKitLSPServer {
155150
id: id,
156151
label: testSymbolOccurrence.symbol.name,
157152
disabled: false,
158-
style: TestStyle.xcTest,
153+
style: .xcTest,
159154
location: location,
160155
children: children.map(\.testItem),
161156
tags: []
@@ -221,7 +216,7 @@ extension SourceKitLSPServer {
221216
testsFromSyntacticIndex
222217
.compactMap { (item) -> AnnotatedTestItem? in
223218
let testItem = item.testItem
224-
if testItem.style == TestStyle.swiftTesting {
219+
if testItem.style == .swiftTesting {
225220
// Swift-testing tests aren't part of the semantic index. Always include them.
226221
return item
227222
}
@@ -297,7 +292,7 @@ extension SourceKitLSPServer {
297292

298293
if let index = workspace.index(checkedFor: indexCheckLevel) {
299294
var syntacticSwiftTestingTests: [AnnotatedTestItem] {
300-
syntacticTests?.filter { $0.testItem.style == TestStyle.swiftTesting } ?? []
295+
syntacticTests?.filter { $0.testItem.style == .swiftTesting } ?? []
301296
}
302297

303298
let testSymbols =

0 commit comments

Comments
 (0)