Skip to content

Commit 9780672

Browse files
committed
Define sources of ClangCrashRecovery inline
1 parent 31cafe7 commit 9780672

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

Sources/SKTestSupport/INPUTS/ClangCrashRecovery/main.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

Sources/SKTestSupport/INPUTS/ClangCrashRecovery/project.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

Tests/SourceKitDTests/CrashRecoveryTests.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,11 @@ final class CrashRecoveryTests: XCTestCase {
135135
}
136136
}
137137

138-
/// Crashes clangd and waits for it to restart
139-
/// - Parameters:
140-
/// - ws: The workspace for which the clangd server shall be crashed
141-
/// - document: The URI of a C/C++/... document in the workspace
142-
private func crashClangd(for ws: SKTibsTestWorkspace, document docUri: DocumentURI) async throws {
143-
let clangdServer = await ws.testClient.server._languageService(
138+
private func crashClangd(for testClient: TestSourceKitLSPClient, document docUri: DocumentURI) async throws {
139+
let clangdServer = await testClient.server._languageService(
144140
for: docUri,
145141
.cpp,
146-
in: ws.testClient.server.workspaceForDocument(uri: docUri)!
142+
in: testClient.server.workspaceForDocument(uri: docUri)!
147143
)!
148144

149145
let clangdCrashed = self.expectation(description: "clangd crashed")
@@ -169,25 +165,26 @@ final class CrashRecoveryTests: XCTestCase {
169165
func testClangdCrashRecovery() async throws {
170166
try XCTSkipIf(longTestsDisabled)
171167

172-
let ws = try await staticSourceKitTibsWorkspace(name: "ClangCrashRecovery")!
173-
let loc = ws.testLoc("loc")
168+
let testClient = try await TestSourceKitLSPClient()
169+
let uri = DocumentURI.for(.cpp)
174170

175-
try ws.openDocument(loc.url, language: .cpp)
171+
let positions = testClient.openDocument("1️⃣", uri: uri)
176172

177173
// Make a change to the file that's not saved to disk. This way we can check that we re-open the correct in-memory state.
178174

179175
let addFuncChange = TextDocumentContentChangeEvent(
180-
range: loc.position..<loc.position,
176+
range: Range(positions["1️⃣"]),
181177
rangeLength: 0,
182178
text: """
183179
184180
void main() {
185181
}
186182
"""
187183
)
188-
ws.testClient.send(
184+
185+
testClient.send(
189186
DidChangeTextDocumentNotification(
190-
textDocument: VersionedTextDocumentIdentifier(loc.docUri, version: 2),
187+
textDocument: VersionedTextDocumentIdentifier(uri, version: 2),
191188
contentChanges: [addFuncChange]
192189
)
193190
)
@@ -196,21 +193,24 @@ final class CrashRecoveryTests: XCTestCase {
196193

197194
let expectedHoverRange = Position(line: 1, utf16index: 5)..<Position(line: 1, utf16index: 9)
198195

199-
let hoverRequest = HoverRequest(textDocument: loc.docIdentifier, position: Position(line: 1, utf16index: 6))
200-
let preCrashHoverResponse = try await ws.testClient.send(hoverRequest)
196+
let hoverRequest = HoverRequest(
197+
textDocument: TextDocumentIdentifier(uri),
198+
position: Position(line: 1, utf16index: 6)
199+
)
200+
let preCrashHoverResponse = try await testClient.send(hoverRequest)
201201
precondition(
202202
preCrashHoverResponse?.range == expectedHoverRange,
203203
"Sanity check failed. The Hover response was not what we expected, even before crashing sourcekitd"
204204
)
205205

206206
// Crash clangd
207207

208-
try await crashClangd(for: ws, document: loc.docUri)
208+
try await crashClangd(for: testClient, document: uri)
209209

210210
// Check that we have re-opened the document with the correct in-memory state
211211

212212
await assertNoThrow {
213-
let postCrashHoverResponse = try await ws.testClient.send(hoverRequest)
213+
let postCrashHoverResponse = try await testClient.send(hoverRequest)
214214
XCTAssertEqual(postCrashHoverResponse?.range, expectedHoverRange)
215215
}
216216
}
@@ -242,7 +242,7 @@ final class CrashRecoveryTests: XCTestCase {
242242

243243
// Crash clangd
244244

245-
try await crashClangd(for: ws, document: loc.docUri)
245+
try await crashClangd(for: ws.testClient, document: loc.docUri)
246246

247247
// Check that we have re-opened the document with the correct build settings
248248
// If we did not recover the correct build settings, document highlight would
@@ -257,22 +257,22 @@ final class CrashRecoveryTests: XCTestCase {
257257
func testPreventClangdCrashLoop() async throws {
258258
try XCTSkipIf(longTestsDisabled)
259259

260-
let ws = try await staticSourceKitTibsWorkspace(name: "ClangCrashRecovery")!
261-
let loc = ws.testLoc("loc")
260+
let testClient = try await TestSourceKitLSPClient()
261+
let uri = DocumentURI.for(.cpp)
262262

263-
try ws.openDocument(loc.url, language: .cpp)
263+
let positions = testClient.openDocument("1️⃣", uri: uri)
264264

265265
// Send a nonsensical request to wait for clangd to start up
266266

267-
let hoverRequest = HoverRequest(textDocument: loc.docIdentifier, position: Position(line: 1, utf16index: 6))
268-
_ = try await ws.testClient.send(hoverRequest)
267+
let hoverRequest = HoverRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"])
268+
_ = try await testClient.send(hoverRequest)
269269

270270
// Keep track of clangd crashes
271271

272-
let clangdServer = await ws.testClient.server._languageService(
273-
for: loc.docUri,
272+
let clangdServer = await testClient.server._languageService(
273+
for: uri,
274274
.cpp,
275-
in: ws.testClient.server.workspaceForDocument(uri: loc.docUri)!
275+
in: testClient.server.workspaceForDocument(uri: uri)!
276276
)!
277277

278278
let clangdCrashed = self.expectation(description: "clangd crashed")

0 commit comments

Comments
 (0)