Skip to content

Commit 6306c40

Browse files
committed
Added specific test project for system swiftinterface tests
Add multiple tests for various system modules
1 parent bf42a2a commit 6306c40

File tree

4 files changed

+71
-14
lines changed

4 files changed

+71
-14
lines changed

Sources/SKTestSupport/INPUTS/SwiftPMPackage/Sources/lib/lib.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
public struct Lib {
2-
let a: /*Lib.a.string*/String
3-
42
public func /*Lib.foo:def*/foo() {}
53

6-
public init() {
7-
self.a = "lib"
8-
}
4+
public init() {}
95
}
106

117
func topLevelFunction() {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// swift-tools-version:5.1
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "SystemSwiftInterface",
7+
platforms: [.macOS(.v10_15)],
8+
products: [],
9+
dependencies: [],
10+
targets: [
11+
.target(
12+
name: "lib",
13+
dependencies: []),
14+
/*Package.swift:targets*/
15+
]
16+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public func libFunc() async {
2+
let a: /*lib.string*/String = "test"
3+
let i: /*lib.integer*/Int = 2
4+
await /*lib.withTaskGroup*/withTaskGroup(of: Void.self) { group in
5+
group.addTask {
6+
print(a)
7+
print(i)
8+
}
9+
}
10+
}

Tests/SourceKitLSPTests/SwiftInterfaceTests.swift

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Foundation
14+
import ISDBTestSupport
1415
import LanguageServerProtocol
1516
import LSPTestSupport
1617
import LSPLogging
@@ -114,25 +115,59 @@ final class SwiftInterfaceTests: XCTestCase {
114115
"""))
115116
}
116117

117-
func testDefinitionInSystemModuleInterface() throws {
118-
guard let ws = try staticSourceKitSwiftPMWorkspace(name: "SwiftPMPackage") else { return }
119-
try ws.buildAndIndex(withSystemSymbols: true)
120-
let stringRef = ws.testLoc("Lib.a.string")
121-
try ws.openDocument(stringRef.url, language: .swift)
118+
/// Used by testDefinitionInSystemModuleInterface
119+
func testSystemSwiftInterface(
120+
_ testLoc: TestLocation,
121+
ws: SKSwiftPMTestWorkspace,
122+
swiftInterfaceFile: String,
123+
linePrefix: String
124+
) throws {
125+
try ws.openDocument(testLoc.url, language: .swift)
122126
let definition = try ws.sk.sendSync(DefinitionRequest(
123-
textDocument: stringRef.docIdentifier,
124-
position: stringRef.position))
127+
textDocument: testLoc.docIdentifier,
128+
position: testLoc.position))
125129
guard case .locations(let jump) = definition else {
126130
XCTFail("Response is not locations")
127131
return
128132
}
129133
let location = try XCTUnwrap(jump.first)
130-
XCTAssertTrue(location.uri.pseudoPath.hasSuffix("/Swift.String.swiftinterface"))
134+
XCTAssertTrue(location.uri.pseudoPath.hasSuffix(swiftInterfaceFile))
131135
// load contents of swiftinterface
132136
let contents = try XCTUnwrap(location.uri.fileURL.flatMap({ try String(contentsOf: $0, encoding: .utf8) }))
133137
let lineTable = LineTable(contents)
134138
let line = lineTable[location.range.lowerBound.line]
135-
XCTAssert(line.hasPrefix("@frozen public struct String"))
139+
XCTAssert(line.hasPrefix(linePrefix))
140+
ws.closeDocument(testLoc.url)
141+
}
142+
143+
func testDefinitionInSystemModuleInterface() throws {
144+
guard let ws = try staticSourceKitSwiftPMWorkspace(name: "SystemSwiftInterface") else { return }
145+
try ws.buildAndIndex(withSystemSymbols: true)
146+
let stringRef = ws.testLoc("lib.string")
147+
let intRef = ws.testLoc("lib.integer")
148+
let withTaskGroupRef = ws.testLoc("lib.withTaskGroup")
149+
150+
// Test stdlib with one submodule
151+
try testSystemSwiftInterface(
152+
stringRef,
153+
ws: ws,
154+
swiftInterfaceFile: "/Swift.String.swiftinterface",
155+
linePrefix: "@frozen public struct String"
156+
)
157+
// Test stdlib with two submodules
158+
try testSystemSwiftInterface(
159+
intRef,
160+
ws: ws,
161+
swiftInterfaceFile: "/Swift.Math.Integers.swiftinterface",
162+
linePrefix: "@frozen public struct Int"
163+
)
164+
// Test concurrency
165+
try testSystemSwiftInterface(
166+
withTaskGroupRef,
167+
ws: ws,
168+
swiftInterfaceFile: "/_Concurrency.swiftinterface",
169+
linePrefix: "@inlinable public func withTaskGroup"
170+
)
136171
}
137172

138173
func testSwiftInterfaceAcrossModules() throws {

0 commit comments

Comments
 (0)