@@ -247,9 +247,11 @@ final class BuildServerBuildSystemTests: XCTestCase {
247
247
#error( " DEBUG NOT SET " )
248
248
#endif
249
249
""" ,
250
+ " should_crash " : " dummy file to indicate that BSP server should crash " ,
250
251
] ,
251
252
buildServer: """
252
253
import threading
254
+ import os
253
255
254
256
class BuildServer(AbstractBuildServer):
255
257
def workspace_build_targets(self, request: Dict[str, object]) -> Dict[str, object]:
@@ -279,23 +281,25 @@ final class BuildServerBuildSystemTests: XCTestCase {
279
281
}
280
282
281
283
def textdocument_sourcekitoptions(self, request: Dict[str, object]) -> Dict[str, object]:
282
- # Crash when getting build settings for Crash.swift
283
- assert " Crash.swift " not in request[ " textDocument " ][ " uri " ]
284
+ if os.path.exists( " $TEST_DIR/should_crash " ):
285
+ assert False
284
286
return {
285
287
" compilerArguments " : [ " $TEST_DIR/Test.swift " , " -DDEBUG " , $SDK_ARGS]
286
288
}
287
289
"""
288
290
)
289
291
290
- // Crash the build server
291
- let ( crashUri, _) = try project. openDocument ( " Crash.swift " )
292
- _ = try await project. testClient. send ( DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( crashUri) ) )
293
- project. testClient. send ( DidCloseTextDocumentNotification ( textDocument: TextDocumentIdentifier ( crashUri) ) )
294
-
295
292
// Check that we still get results for Test.swift (after relaunching the BSP server)
296
293
let ( uri, _) = try project. openDocument ( " Test.swift " )
297
294
298
- try await repeatUntilExpectedResult {
295
+ // While the BSP server is crashing, we shouldn't get any build settings and thus get empty diagnostics.
296
+ let diagnosticsBeforeCrash = try await project. testClient. send (
297
+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( uri) )
298
+ )
299
+ XCTAssertEqual ( diagnosticsBeforeCrash. fullReport? . items, [ ] )
300
+ try FileManager . default. removeItem ( at: project. scratchDirectory. appendingPathComponent ( " should_crash " ) )
301
+
302
+ try await repeatUntilExpectedResult ( timeout: 20 ) {
299
303
let diagnostics = try await project. testClient. send (
300
304
DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( uri) )
301
305
)
0 commit comments