Skip to content

Commit c49849b

Browse files
authored
Merge pull request #323 from benlangmuir/test-resources
[test] Put shared test projects INPUTS into bundle resources
2 parents 79865c7 + a763252 commit c49849b

File tree

61 files changed

+84
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+84
-80
lines changed

Documentation/Development.md

Lines changed: 2 additions & 2 deletions

Package.swift

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.3
22

33
import PackageDescription
44

@@ -30,12 +30,12 @@ let package = Package(
3030
.target(
3131
name: "sourcekit-lsp",
3232
dependencies: [
33-
"ArgumentParser",
3433
"LanguageServerProtocolJSONRPC",
3534
"SourceKitLSP",
36-
"SwiftToolsSupport-auto",
37-
]
38-
),
35+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
36+
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
37+
],
38+
exclude: ["CMakeLists.txt"]),
3939

4040
.target(
4141
name: "SourceKitLSP",
@@ -47,9 +47,9 @@ let package = Package(
4747
"SKCore",
4848
"SourceKitD",
4949
"SKSwiftPMWorkspace",
50-
"SwiftToolsSupport-auto",
51-
]
52-
),
50+
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
51+
],
52+
exclude: ["CMakeLists.txt"]),
5353

5454
.target(
5555
name: "CSKTestSupport",
@@ -58,11 +58,14 @@ let package = Package(
5858
name: "SKTestSupport",
5959
dependencies: [
6060
"CSKTestSupport",
61-
"ISDBTestSupport",
6261
"LSPTestSupport",
6362
"SourceKitLSP",
64-
"tibs", // Never imported, needed at runtime
65-
"SwiftToolsSupport-auto",
63+
.product(name: "ISDBTestSupport", package: "IndexStoreDB"),
64+
.product(name: "tibs", package: "IndexStoreDB"), // Never imported, needed at runtime
65+
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
66+
],
67+
resources: [
68+
.copy("INPUTS"),
6669
]
6770
),
6871
.testTarget(
@@ -79,15 +82,16 @@ let package = Package(
7982
"BuildServerProtocol",
8083
"LanguageServerProtocol",
8184
"SKCore",
82-
"SwiftPM-auto",
83-
]
84-
),
85+
.product(name: "SwiftPM-auto", package: "SwiftPM")
86+
],
87+
exclude: ["CMakeLists.txt"]),
88+
8589
.testTarget(
8690
name: "SKSwiftPMWorkspaceTests",
8791
dependencies: [
8892
"SKSwiftPMWorkspace",
8993
"SKTestSupport",
90-
"SwiftToolsSupport-auto",
94+
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
9195
]
9296
),
9397

@@ -101,9 +105,10 @@ let package = Package(
101105
"LanguageServerProtocol",
102106
"LanguageServerProtocolJSONRPC",
103107
"SKSupport",
104-
"SwiftToolsSupport-auto",
105-
]
106-
),
108+
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
109+
],
110+
exclude: ["CMakeLists.txt"]),
111+
107112
.testTarget(
108113
name: "SKCoreTests",
109114
dependencies: [
@@ -119,9 +124,10 @@ let package = Package(
119124
"Csourcekitd",
120125
"LSPLogging",
121126
"SKSupport",
122-
"SwiftToolsSupport-auto",
123-
]
124-
),
127+
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
128+
],
129+
exclude: ["CMakeLists.txt"]),
130+
125131
.testTarget(
126132
name: "SourceKitDTests",
127133
dependencies: [
@@ -134,14 +140,14 @@ let package = Package(
134140
// Csourcekitd: C modules wrapper for sourcekitd.
135141
.target(
136142
name: "Csourcekitd",
137-
dependencies: []
138-
),
143+
dependencies: [],
144+
exclude: ["CMakeLists.txt"]),
139145

140146
// Logging support used in LSP modules.
141147
.target(
142148
name: "LSPLogging",
143-
dependencies: []
144-
),
149+
dependencies: [],
150+
exclude: ["CMakeLists.txt"]),
145151

146152
.testTarget(
147153
name: "LSPLoggingTests",
@@ -164,8 +170,9 @@ let package = Package(
164170
dependencies: [
165171
"LanguageServerProtocol",
166172
"LSPLogging",
167-
]
168-
),
173+
],
174+
exclude: ["CMakeLists.txt"]),
175+
169176
.testTarget(
170177
name: "LanguageServerProtocolJSONRPCTests",
171178
dependencies: [
@@ -177,8 +184,9 @@ let package = Package(
177184
// LanguageServerProtocol: The core LSP types, suitable for any LSP implementation.
178185
.target(
179186
name: "LanguageServerProtocol",
180-
dependencies: []
181-
),
187+
dependencies: [],
188+
exclude: ["CMakeLists.txt"]),
189+
182190
.testTarget(
183191
name: "LanguageServerProtocolTests",
184192
dependencies: [
@@ -192,17 +200,18 @@ let package = Package(
192200
name: "BuildServerProtocol",
193201
dependencies: [
194202
"LanguageServerProtocol"
195-
]
196-
),
203+
],
204+
exclude: ["CMakeLists.txt"]),
197205

198206
// SKSupport: Data structures, algorithms and platform-abstraction code that might be generally
199207
// useful to any Swift package. Similar in spirit to SwiftPM's Basic module.
200208
.target(
201209
name: "SKSupport",
202210
dependencies: [
203-
"SwiftToolsSupport-auto"
204-
]
205-
),
211+
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
212+
],
213+
exclude: ["CMakeLists.txt"]),
214+
206215
.testTarget(
207216
name: "SKSupportTests",
208217
dependencies: [
@@ -225,15 +234,15 @@ import Foundation
225234
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
226235
// Building standalone.
227236
package.dependencies += [
228-
.package(url: "https://github.com/apple/indexstore-db.git", .branch("main")),
229-
.package(url: "https://github.com/apple/swift-package-manager.git", .branch("main")),
237+
.package(name: "IndexStoreDB", url: "https://github.com/apple/indexstore-db.git", .branch("main")),
238+
.package(name: "SwiftPM", url: "https://github.com/apple/swift-package-manager.git", .branch("main")),
230239
.package(url: "https://github.com/apple/swift-tools-support-core.git", .branch("main")),
231240
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.3.0")),
232241
]
233242
} else {
234243
package.dependencies += [
235-
.package(path: "../indexstore-db"),
236-
.package(path: "../swiftpm"),
244+
.package(name: "IndexStoreDB", path: "../indexstore-db"),
245+
.package(name: "SwiftPM", path: "../swiftpm"),
237246
.package(path: "../swiftpm/swift-tools-support-core"),
238247
.package(path: "../swift-argument-parser")
239248
]

Sources/SKTestSupport/SKSwiftPMTestWorkspace.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,11 @@ extension SKSwiftPMTestWorkspace {
137137

138138
extension XCTestCase {
139139

140-
public func staticSourceKitSwiftPMWorkspace(name: String, testFile: String = #file) throws -> SKSwiftPMTestWorkspace? {
140+
public func staticSourceKitSwiftPMWorkspace(name: String) throws -> SKSwiftPMTestWorkspace? {
141141
let testDirName = testDirectoryName
142142
let toolchain = ToolchainRegistry.shared.default!
143143
let workspace = try SKSwiftPMTestWorkspace(
144-
projectDir: inputsDirectory(testFile: testFile)
145-
.appendingPathComponent(name, isDirectory: true),
144+
projectDir: XCTestCase.sklspInputsDirectory.appendingPathComponent(name, isDirectory: true),
146145
tmpDir: URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
147146
.appendingPathComponent("sk-test-data/\(testDirName)", isDirectory: true),
148147
toolchain: toolchain)

Sources/SKTestSupport/SKTibsTestWorkspace.swift

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,15 @@ extension SKTibsTestWorkspace {
109109

110110
extension XCTestCase {
111111

112-
/// The path the the test INPUTS directory.
113-
public func inputsDirectory(testFile: String = #file) -> URL {
114-
return URL(fileURLWithPath: testFile)
115-
.deletingLastPathComponent()
116-
.deletingLastPathComponent()
117-
.appendingPathComponent("INPUTS", isDirectory: true)
118-
}
119-
120112
public func staticSourceKitTibsWorkspace(
121113
name: String,
122114
clientCapabilities: ClientCapabilities = .init(),
123115
tmpDir: URL? = nil,
124-
removeTmpDir: Bool = true,
125-
testFile: String = #file
116+
removeTmpDir: Bool = true
126117
) throws -> SKTibsTestWorkspace? {
127118
let testDirName = testDirectoryName
128119
let workspace = try SKTibsTestWorkspace(
129-
immutableProjectDir: inputsDirectory(testFile: testFile)
120+
immutableProjectDir: XCTestCase.sklspInputsDirectory
130121
.appendingPathComponent(name, isDirectory: true),
131122
persistentBuildDir: XCTestCase.productsDirectory
132123
.appendingPathComponent("sk-tests/\(testDirName)", isDirectory: true),
@@ -152,13 +143,11 @@ extension XCTestCase {
152143
public func mutableSourceKitTibsTestWorkspace(
153144
name: String,
154145
clientCapabilities: ClientCapabilities = .init(),
155-
tmpDir: URL? = nil,
156-
testFile: String = #file
146+
tmpDir: URL? = nil
157147
) throws -> SKTibsTestWorkspace? {
158148
let testDirName = testDirectoryName
159149
let workspace = try SKTibsTestWorkspace(
160-
projectDir: inputsDirectory(testFile: testFile)
161-
.appendingPathComponent(name, isDirectory: true),
150+
projectDir: XCTestCase.sklspInputsDirectory.appendingPathComponent(name, isDirectory: true),
162151
tmpDir: tmpDir ?? URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
163152
.appendingPathComponent("sk-test-data/\(testDirName)", isDirectory: true),
164153
toolchain: ToolchainRegistry.shared.default!,
@@ -173,6 +162,29 @@ extension XCTestCase {
173162

174163
return workspace
175164
}
165+
166+
/// The path to the INPUTS directory of shared test projects.
167+
public static var sklspInputsDirectory: URL = {
168+
#if os(macOS)
169+
// FIXME: Use Bundle.module.resourceURL once the fix for SR-12912 is released.
170+
var resources = XCTestCase.productsDirectory
171+
.appendingPathComponent("SourceKitLSP_SKTestSupport.bundle")
172+
.appendingPathComponent("Contents")
173+
.appendingPathComponent("Resources")
174+
if !FileManager.default.fileExists(atPath: resources.path) {
175+
// Xcode and command-line swiftpm differ about the path.
176+
resources.deleteLastPathComponent()
177+
resources.deleteLastPathComponent()
178+
}
179+
#else
180+
let resources = XCTestCase.productsDirectory
181+
.appendingPathComponent("SourceKitLSP_SKTestSupport.resources")
182+
#endif
183+
guard FileManager.default.fileExists(atPath: resources.path) else {
184+
fatalError("missing resources \(resources.path)")
185+
}
186+
return resources.appendingPathComponent("INPUTS", isDirectory: true).standardizedFileURL
187+
}()
176188
}
177189

178190
extension TestLocation {

Tests/SKCoreTests/BuildServerBuildSystemTests.swift

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,20 @@ import XCTest
2020

2121
final class BuildServerBuildSystemTests: XCTestCase {
2222

23-
func testServerInitialize() throws {
24-
let root = AbsolutePath(
25-
inputsDirectory().appendingPathComponent(testDirectoryName, isDirectory: true).path)
26-
let buildFolder = AbsolutePath(NSTemporaryDirectory())
23+
var root: AbsolutePath {
24+
AbsolutePath(XCTestCase.sklspInputsDirectory
25+
.appendingPathComponent(testDirectoryName, isDirectory: true).path)
26+
}
27+
let buildFolder = AbsolutePath(NSTemporaryDirectory())
2728

29+
func testServerInitialize() throws {
2830
let buildSystem = try BuildServerBuildSystem(projectRoot: root, buildFolder: buildFolder)
2931

3032
XCTAssertEqual(buildSystem.indexDatabasePath, AbsolutePath("some/index/db/path", relativeTo: root))
3133
XCTAssertEqual(buildSystem.indexStorePath, AbsolutePath("some/index/store/path", relativeTo: root))
3234
}
3335

3436
func testSettings() throws {
35-
let root = AbsolutePath(
36-
inputsDirectory().appendingPathComponent(testDirectoryName, isDirectory: true).path)
37-
let buildFolder = AbsolutePath(NSTemporaryDirectory())
3837
let buildSystem = try BuildServerBuildSystem(projectRoot: root, buildFolder: buildFolder)
3938

4039
// test settings with a response
@@ -50,9 +49,6 @@ final class BuildServerBuildSystemTests: XCTestCase {
5049
}
5150

5251
func testFileRegistration() throws {
53-
let root = AbsolutePath(
54-
inputsDirectory().appendingPathComponent(testDirectoryName, isDirectory: true).path)
55-
let buildFolder = AbsolutePath(NSTemporaryDirectory())
5652
let buildSystem = try BuildServerBuildSystem(projectRoot: root, buildFolder: buildFolder)
5753

5854
let fileUrl = URL(fileURLWithPath: "/some/file/path")
@@ -65,9 +61,6 @@ final class BuildServerBuildSystemTests: XCTestCase {
6561
}
6662

6763
func testBuildTargets() throws {
68-
let root = AbsolutePath(
69-
inputsDirectory().appendingPathComponent(testDirectoryName, isDirectory: true).path)
70-
let buildFolder = AbsolutePath(NSTemporaryDirectory())
7164
let buildSystem = try BuildServerBuildSystem(projectRoot: root, buildFolder: buildFolder)
7265

7366
let expectation = XCTestExpectation(description: "build target expectation")
@@ -100,9 +93,6 @@ final class BuildServerBuildSystemTests: XCTestCase {
10093
}
10194

10295
func testBuildTargetSources() throws {
103-
let root = AbsolutePath(
104-
inputsDirectory().appendingPathComponent(testDirectoryName, isDirectory: true).path)
105-
let buildFolder = AbsolutePath(NSTemporaryDirectory())
10696
let buildSystem = try BuildServerBuildSystem(projectRoot: root, buildFolder: buildFolder)
10797

10898
let expectation = XCTestExpectation(description: "build target sources expectation")
@@ -133,9 +123,6 @@ final class BuildServerBuildSystemTests: XCTestCase {
133123
}
134124

135125
func testBuildTargetOutputs() throws {
136-
let root = AbsolutePath(
137-
inputsDirectory().appendingPathComponent(testDirectoryName, isDirectory: true).path)
138-
let buildFolder = AbsolutePath(NSTemporaryDirectory())
139126
let buildSystem = try BuildServerBuildSystem(projectRoot: root, buildFolder: buildFolder)
140127

141128
let expectation = XCTestExpectation(description: "build target output expectation")
@@ -160,9 +147,6 @@ final class BuildServerBuildSystemTests: XCTestCase {
160147
}
161148

162149
func testBuildTargetsChanged() throws {
163-
let root = AbsolutePath(
164-
inputsDirectory().appendingPathComponent(testDirectoryName, isDirectory: true).path)
165-
let buildFolder = AbsolutePath(NSTemporaryDirectory())
166150
let buildSystem = try BuildServerBuildSystem(projectRoot: root, buildFolder: buildFolder)
167151

168152
let fileUrl = URL(fileURLWithPath: "/some/file/path")

0 commit comments

Comments
 (0)