Skip to content

Commit ab9513e

Browse files
authored
Merge pull request #1560 from plemarquand/add-more-doc-discovery-tests
Add more test discovery tests
2 parents 331ae2b + d0a99c7 commit ab9513e

File tree

1 file changed

+158
-44
lines changed

1 file changed

+158
-44
lines changed

Tests/SourceKitLSPTests/DocumentTestDiscoveryTests.swift

Lines changed: 158 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
245245
)
246246
}
247247

248-
func testNestedSwiftTestingSuites() async throws {
248+
func testSwiftTestingNestedSuites() async throws {
249249
let testClient = try await TestSourceKitLSPClient()
250250
let uri = DocumentURI(for: .swift)
251251

@@ -295,7 +295,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
295295
)
296296
}
297297

298-
func testParameterizedSwiftTestingTest() async throws {
298+
func testSwiftTestingParameterizedTest() async throws {
299299
let testClient = try await TestSourceKitLSPClient()
300300
let uri = DocumentURI(for: .swift)
301301

@@ -335,7 +335,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
335335
)
336336
}
337337

338-
func testParameterizedSwiftTestingTestWithAnonymousArgument() async throws {
338+
func testSwiftTestingParameterizedTestWithAnonymousArgument() async throws {
339339
let testClient = try await TestSourceKitLSPClient()
340340
let uri = DocumentURI(for: .swift)
341341

@@ -378,7 +378,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
378378
)
379379
}
380380

381-
func testParameterizedSwiftTestingTestWithCommentInSignature() async throws {
381+
func testSwiftTestingParameterizedTestWithCommentInSignature() async throws {
382382
let testClient = try await TestSourceKitLSPClient()
383383
let uri = DocumentURI(for: .swift)
384384

@@ -559,7 +559,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
559559
)
560560
}
561561

562-
func testDisabledSwiftTestingTest() async throws {
562+
func testSwiftTestingTestDisabledTest() async throws {
563563
let testClient = try await TestSourceKitLSPClient()
564564
let uri = DocumentURI(for: .swift)
565565

@@ -633,7 +633,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
633633
)
634634
}
635635

636-
func testHiddenSwiftTestingTest() async throws {
636+
func testSwiftTestingHiddenTest() async throws {
637637
let testClient = try await TestSourceKitLSPClient()
638638
let uri = DocumentURI(for: .swift)
639639

@@ -859,43 +859,6 @@ final class DocumentTestDiscoveryTests: XCTestCase {
859859
)
860860
}
861861

862-
func testXCTestTestsWithExtension() async throws {
863-
let testClient = try await TestSourceKitLSPClient()
864-
let uri = DocumentURI(for: .swift)
865-
866-
let positions = testClient.openDocument(
867-
"""
868-
import XCTest
869-
870-
1️⃣final class MyTests: XCTestCase {}2️⃣
871-
872-
extension MyTests {
873-
3️⃣func testOneIsTwo() {}4️⃣
874-
}
875-
""",
876-
uri: uri
877-
)
878-
879-
let tests = try await testClient.send(DocumentTestsRequest(textDocument: TextDocumentIdentifier(uri)))
880-
XCTAssertEqual(
881-
tests,
882-
[
883-
TestItem(
884-
id: "MyTests",
885-
label: "MyTests",
886-
location: Location(uri: uri, range: positions["1️⃣"]..<positions["2️⃣"]),
887-
children: [
888-
TestItem(
889-
id: "MyTests/testOneIsTwo()",
890-
label: "testOneIsTwo()",
891-
location: Location(uri: uri, range: positions["3️⃣"]..<positions["4️⃣"])
892-
)
893-
]
894-
)
895-
]
896-
)
897-
}
898-
899862
func testSwiftTestingNestedTestSuiteWithExtension() async throws {
900863
let testClient = try await TestSourceKitLSPClient()
901864
let uri = DocumentURI(for: .swift)
@@ -1086,7 +1049,87 @@ final class DocumentTestDiscoveryTests: XCTestCase {
10861049
)
10871050
}
10881051

1089-
func testFullyQualifySwiftTestingTestAttribute() async throws {
1052+
func testSwiftTestingEnumSuite() async throws {
1053+
let testClient = try await TestSourceKitLSPClient()
1054+
let uri = DocumentURI(for: .swift)
1055+
1056+
let positions = testClient.openDocument(
1057+
"""
1058+
import Testing
1059+
1060+
1️⃣enum MyTests {
1061+
2️⃣@Test
1062+
static func oneIsTwo() {
1063+
#expect(1 == 2)
1064+
}3️⃣
1065+
}4️⃣
1066+
""",
1067+
uri: uri
1068+
)
1069+
1070+
let tests = try await testClient.send(DocumentTestsRequest(textDocument: TextDocumentIdentifier(uri)))
1071+
XCTAssertEqual(
1072+
tests,
1073+
[
1074+
TestItem(
1075+
id: "MyTests",
1076+
label: "MyTests",
1077+
style: TestStyle.swiftTesting,
1078+
location: Location(uri: uri, range: positions["1️⃣"]..<positions["4️⃣"]),
1079+
children: [
1080+
TestItem(
1081+
id: "MyTests/oneIsTwo()",
1082+
label: "oneIsTwo()",
1083+
style: TestStyle.swiftTesting,
1084+
location: Location(uri: uri, range: positions["2️⃣"]..<positions["3️⃣"])
1085+
)
1086+
]
1087+
)
1088+
]
1089+
)
1090+
}
1091+
1092+
func testSwiftTestingActorSuite() async throws {
1093+
let testClient = try await TestSourceKitLSPClient()
1094+
let uri = DocumentURI(for: .swift)
1095+
1096+
let positions = testClient.openDocument(
1097+
"""
1098+
import Testing
1099+
1100+
1️⃣actor MyTests {
1101+
2️⃣@Test
1102+
static func oneIsTwo() {
1103+
#expect(1 == 2)
1104+
}3️⃣
1105+
}4️⃣
1106+
""",
1107+
uri: uri
1108+
)
1109+
1110+
let tests = try await testClient.send(DocumentTestsRequest(textDocument: TextDocumentIdentifier(uri)))
1111+
XCTAssertEqual(
1112+
tests,
1113+
[
1114+
TestItem(
1115+
id: "MyTests",
1116+
label: "MyTests",
1117+
style: TestStyle.swiftTesting,
1118+
location: Location(uri: uri, range: positions["1️⃣"]..<positions["4️⃣"]),
1119+
children: [
1120+
TestItem(
1121+
id: "MyTests/oneIsTwo()",
1122+
label: "oneIsTwo()",
1123+
style: TestStyle.swiftTesting,
1124+
location: Location(uri: uri, range: positions["2️⃣"]..<positions["3️⃣"])
1125+
)
1126+
]
1127+
)
1128+
]
1129+
)
1130+
}
1131+
1132+
func testSwiftTestingFullyQualifyTestAttribute() async throws {
10901133
let testClient = try await TestSourceKitLSPClient()
10911134
let uri = DocumentURI(for: .swift)
10921135

@@ -1127,6 +1170,77 @@ final class DocumentTestDiscoveryTests: XCTestCase {
11271170
)
11281171
}
11291172

1173+
func testXCTestTestsWithExtension() async throws {
1174+
let testClient = try await TestSourceKitLSPClient()
1175+
let uri = DocumentURI(for: .swift)
1176+
1177+
let positions = testClient.openDocument(
1178+
"""
1179+
import XCTest
1180+
1181+
1️⃣final class MyTests: XCTestCase {}2️⃣
1182+
1183+
extension MyTests {
1184+
3️⃣func testOneIsTwo() {}4️⃣
1185+
}
1186+
""",
1187+
uri: uri
1188+
)
1189+
1190+
let tests = try await testClient.send(DocumentTestsRequest(textDocument: TextDocumentIdentifier(uri)))
1191+
XCTAssertEqual(
1192+
tests,
1193+
[
1194+
TestItem(
1195+
id: "MyTests",
1196+
label: "MyTests",
1197+
location: Location(uri: uri, range: positions["1️⃣"]..<positions["2️⃣"]),
1198+
children: [
1199+
TestItem(
1200+
id: "MyTests/testOneIsTwo()",
1201+
label: "testOneIsTwo()",
1202+
location: Location(uri: uri, range: positions["3️⃣"]..<positions["4️⃣"])
1203+
)
1204+
]
1205+
)
1206+
]
1207+
)
1208+
}
1209+
1210+
func testXCTestInvalidXCTestSuiteConstructions() async throws {
1211+
let testClient = try await TestSourceKitLSPClient()
1212+
let uri = DocumentURI(for: .swift)
1213+
1214+
let positions = testClient.openDocument(
1215+
"""
1216+
import XCTest
1217+
1218+
// This comment contains the string XCTestCase
1219+
final class NSObjectInheritance: NSObject {}
1220+
final class BaseClass {}
1221+
final class MyEmptyTests: BaseClass {}
1222+
1️⃣final class MyTests: XCTestCase {
1223+
static func testStaticFuncIsNotATest() {}
1224+
}2️⃣
1225+
""",
1226+
uri: uri
1227+
)
1228+
1229+
let tests = try await testClient.send(DocumentTestsRequest(textDocument: TextDocumentIdentifier(uri)))
1230+
1231+
XCTAssertEqual(
1232+
tests,
1233+
[
1234+
TestItem(
1235+
id: "MyTests",
1236+
label: "MyTests",
1237+
location: Location(uri: uri, range: positions["1️⃣"]..<positions["2️⃣"]),
1238+
children: []
1239+
)
1240+
]
1241+
)
1242+
}
1243+
11301244
func testAddNewMethodToNotQuiteTestCase() async throws {
11311245
let project = try await IndexedSingleSwiftFileTestProject(
11321246
"""

0 commit comments

Comments
 (0)