Skip to content

Commit 6679652

Browse files
committed
Remove awaitTask
It turns out that `XCTestCase.setUp` can indeed be `async` and we thus don’t actually need `awaitTask`
1 parent 64ba40e commit 6679652

File tree

4 files changed

+62
-92
lines changed

4 files changed

+62
-92
lines changed

Sources/LSPTestSupport/Assertions.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,4 @@ extension XCTestCase {
130130
throw ExpectationNotFulfilledError(expecatations: expectations)
131131
}
132132
}
133-
134-
/// Execute the given asynchronous `operation` and block execution until it
135-
/// finishes.
136-
///
137-
/// - Important: Only use this in context where execution of async functions
138-
/// is necessary but the context doesn't allow it, like `XCTestCase.setUp`
139-
public func awaitTask(
140-
description: String,
141-
_ operation: () async throws -> Void,
142-
file: StaticString = #filePath,
143-
line: UInt = #line
144-
) {
145-
let completed = self.expectation(description: description)
146-
withoutActuallyEscaping(operation) { operation in
147-
Task(priority: .userInitiated) {
148-
await assertNoThrow<Void>(operation, "", file: file, line: line)
149-
completed.fulfill()
150-
}
151-
let started = XCTWaiter.wait(for: [completed], timeout: defaultTimeout)
152-
if started != .completed {
153-
XCTFail("Task '\(description)' did not finish within timeout", file: file, line: line)
154-
}
155-
}
156-
}
157133
}

Tests/SourceKitLSPTests/BuildSystemTests.swift

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -92,40 +92,38 @@ final class BuildSystemTests: XCTestCase {
9292
/// - Note: Set before each test run in `setUp`.
9393
private var haveClangd: Bool = false
9494

95-
override func setUp() {
96-
awaitTask(description: "Setup complete") {
97-
haveClangd = ToolchainRegistry.shared.toolchains.contains { $0.clangd != nil }
98-
testClient = TestSourceKitLSPClient()
99-
buildSystem = TestBuildSystem()
100-
101-
let server = testClient.server
102-
103-
self.workspace = await Workspace(
104-
documentManager: DocumentManager(),
105-
rootUri: nil,
106-
capabilityRegistry: CapabilityRegistry(clientCapabilities: ClientCapabilities()),
107-
toolchainRegistry: ToolchainRegistry.shared,
108-
buildSetup: SourceKitServer.Options.testDefault.buildSetup,
109-
underlyingBuildSystem: buildSystem,
110-
index: nil,
111-
indexDelegate: nil
112-
)
95+
override func setUp() async throws {
96+
haveClangd = ToolchainRegistry.shared.toolchains.contains { $0.clangd != nil }
97+
testClient = TestSourceKitLSPClient()
98+
buildSystem = TestBuildSystem()
99+
100+
let server = testClient.server
101+
102+
self.workspace = await Workspace(
103+
documentManager: DocumentManager(),
104+
rootUri: nil,
105+
capabilityRegistry: CapabilityRegistry(clientCapabilities: ClientCapabilities()),
106+
toolchainRegistry: ToolchainRegistry.shared,
107+
buildSetup: SourceKitServer.Options.testDefault.buildSetup,
108+
underlyingBuildSystem: buildSystem,
109+
index: nil,
110+
indexDelegate: nil
111+
)
113112

114-
await server.setWorkspaces([workspace])
115-
await workspace.buildSystemManager.setDelegate(server)
116-
117-
_ = try await testClient.send(
118-
InitializeRequest(
119-
processId: nil,
120-
rootPath: nil,
121-
rootURI: nil,
122-
initializationOptions: nil,
123-
capabilities: ClientCapabilities(workspace: nil, textDocument: nil),
124-
trace: .off,
125-
workspaceFolders: nil
126-
)
113+
await server.setWorkspaces([workspace])
114+
await workspace.buildSystemManager.setDelegate(server)
115+
116+
_ = try await testClient.send(
117+
InitializeRequest(
118+
processId: nil,
119+
rootPath: nil,
120+
rootURI: nil,
121+
initializationOptions: nil,
122+
capabilities: ClientCapabilities(workspace: nil, textDocument: nil),
123+
trace: .off,
124+
workspaceFolders: nil
127125
)
128-
}
126+
)
129127
}
130128

131129
override func tearDown() {

Tests/SourceKitLSPTests/PublishDiagnosticsTests.swift

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,22 @@ final class PublishDiagnosticsTests: XCTestCase {
3232
/// `openDocument` and `editDocument`.
3333
private var version: Int!
3434

35-
override func setUp() {
35+
override func setUp() async throws {
3636
version = 0
3737
uri = DocumentURI(URL(fileURLWithPath: "/PublishDiagnosticsTests/\(UUID()).swift"))
3838
testClient = TestSourceKitLSPClient()
3939
let documentCapabilities = TextDocumentClientCapabilities()
40-
awaitTask(description: "Initialized") {
41-
_ = try await self.testClient.send(
42-
InitializeRequest(
43-
processId: nil,
44-
rootPath: nil,
45-
rootURI: nil,
46-
initializationOptions: nil,
47-
capabilities: ClientCapabilities(workspace: nil, textDocument: documentCapabilities),
48-
trace: .off,
49-
workspaceFolders: nil
50-
)
40+
_ = try await self.testClient.send(
41+
InitializeRequest(
42+
processId: nil,
43+
rootPath: nil,
44+
rootURI: nil,
45+
initializationOptions: nil,
46+
capabilities: ClientCapabilities(workspace: nil, textDocument: documentCapabilities),
47+
trace: .off,
48+
workspaceFolders: nil
5149
)
52-
}
50+
)
5351
}
5452

5553
override func tearDown() {

Tests/SourceKitLSPTests/SwiftInterfaceTests.swift

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,34 @@ final class SwiftInterfaceTests: XCTestCase {
2727
/// - Note: Set before each test run in `setUp`.
2828
private var testClient: TestSourceKitLSPClient! = nil
2929

30-
override func setUp() {
30+
override func setUp() async throws {
3131
// This is the only test that references modules from the SDK (Foundation).
3232
// `testSystemModuleInterface` has been flaky for a long while and a
3333
// hypothesis is that it was failing because of a malformed global module
3434
// cache that might still be present from previous CI runs. If we use a
3535
// local module cache, we define away that source of bugs.
3636
testClient = TestSourceKitLSPClient(useGlobalModuleCache: false)
37-
awaitTask(description: "Initialize") {
38-
_ = try await testClient.send(
39-
InitializeRequest(
40-
processId: nil,
41-
rootPath: nil,
42-
rootURI: nil,
43-
initializationOptions: nil,
44-
capabilities: ClientCapabilities(
45-
workspace: nil,
46-
textDocument: TextDocumentClientCapabilities(
47-
codeAction: .init(
48-
codeActionLiteralSupport: .init(
49-
codeActionKind: .init(valueSet: [.quickFix])
50-
)
51-
),
52-
publishDiagnostics: .init(codeDescriptionSupport: true)
53-
)
54-
),
55-
trace: .off,
56-
workspaceFolders: nil
57-
)
37+
_ = try await testClient.send(
38+
InitializeRequest(
39+
processId: nil,
40+
rootPath: nil,
41+
rootURI: nil,
42+
initializationOptions: nil,
43+
capabilities: ClientCapabilities(
44+
workspace: nil,
45+
textDocument: TextDocumentClientCapabilities(
46+
codeAction: .init(
47+
codeActionLiteralSupport: .init(
48+
codeActionKind: .init(valueSet: [.quickFix])
49+
)
50+
),
51+
publishDiagnostics: .init(codeDescriptionSupport: true)
52+
)
53+
),
54+
trace: .off,
55+
workspaceFolders: nil
5856
)
59-
}
57+
)
6058
}
6159

6260
override func tearDown() {

0 commit comments

Comments
 (0)