Skip to content

Commit d5e2541

Browse files
committed
Make fulfillmentOfOrThrow take a variadic list of expectations
In almost all cases, we pass a single expectation and that looks a lot nicer with a variadic parameter.
1 parent e6ca874 commit d5e2541

23 files changed

+71
-71
lines changed

Sources/SKTestSupport/Assertions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ package struct ExpectationNotFulfilledError: Error, CustomStringConvertible {
144144
/// Wait for the given expectations to be fulfilled. If the expectations aren't
145145
/// fulfilled within `timeout`, throw an error, aborting the test execution.
146146
package nonisolated func fulfillmentOfOrThrow(
147-
_ expectations: [XCTestExpectation],
147+
_ expectations: XCTestExpectation...,
148148
timeout: TimeInterval = defaultTimeout,
149149
enforceOrder enforceOrderOfFulfillment: Bool = false
150150
) async throws {

Tests/BuildSystemIntegrationTests/BuildSystemManagerTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ final class BuildSystemManagerTests: XCTestCase {
173173
(a, .swift, fallbackBuildSettings(for: a, language: .swift, options: .init()), changed)
174174
])
175175
await buildSystem.setBuildSettings(for: a, to: nil)
176-
try await fulfillmentOfOrThrow([changed])
176+
try await fulfillmentOfOrThrow(changed)
177177
}
178178

179179
func testSettingsMainFileInitialNil() async throws {
@@ -187,7 +187,7 @@ final class BuildSystemManagerTests: XCTestCase {
187187
let changed = expectation(description: "changed settings")
188188
await del.setExpected([(a, .swift, FileBuildSettings(compilerArguments: ["x"], language: .swift), changed)])
189189
await buildSystem.setBuildSettings(for: a, to: TextDocumentSourceKitOptionsResponse(compilerArguments: ["x"]))
190-
try await fulfillmentOfOrThrow([changed])
190+
try await fulfillmentOfOrThrow(changed)
191191
}
192192

193193
func testSettingsMainFileWithFallback() async throws {
@@ -211,12 +211,12 @@ final class BuildSystemManagerTests: XCTestCase {
211211
for: a,
212212
to: TextDocumentSourceKitOptionsResponse(compilerArguments: ["non-fallback", "args"])
213213
)
214-
try await fulfillmentOfOrThrow([changed])
214+
try await fulfillmentOfOrThrow(changed)
215215

216216
let revert = expectation(description: "revert to fallback settings")
217217
await del.setExpected([(a, .swift, fallbackSettings, revert)])
218218
await buildSystem.setBuildSettings(for: a, to: nil)
219-
try await fulfillmentOfOrThrow([revert])
219+
try await fulfillmentOfOrThrow(revert)
220220
}
221221

222222
func testSettingsHeaderChangeMainFile() async throws {
@@ -257,20 +257,20 @@ final class BuildSystemManagerTests: XCTestCase {
257257
let changed = expectation(description: "changed settings to cpp2")
258258
await del.setExpected([(h, .c, FileBuildSettings(compilerArguments: ["C++ 2"], language: .c), changed)])
259259
await manager.mainFilesChanged()
260-
try await fulfillmentOfOrThrow([changed])
260+
try await fulfillmentOfOrThrow(changed)
261261

262262
let changed2 = expectation(description: "still cpp2, no update")
263263
changed2.isInverted = true
264264
await del.setExpected([(h, .c, nil, changed2)])
265265
await manager.mainFilesChanged()
266-
try await fulfillmentOfOrThrow([changed2], timeout: 1)
266+
try await fulfillmentOfOrThrow(changed2, timeout: 1)
267267

268268
await mainFiles.updateMainFiles(for: h, to: [cpp1, cpp2])
269269

270270
let changed3 = expectation(description: "added lexicographically earlier main file")
271271
await del.setExpected([(h, .c, FileBuildSettings(compilerArguments: ["C++ 1"], language: .c), changed3)])
272272
await manager.mainFilesChanged()
273-
try await fulfillmentOfOrThrow([changed3], timeout: 1)
273+
try await fulfillmentOfOrThrow(changed3, timeout: 1)
274274

275275
await mainFiles.updateMainFiles(for: h, to: [])
276276

@@ -279,7 +279,7 @@ final class BuildSystemManagerTests: XCTestCase {
279279
(h, .c, fallbackBuildSettings(for: h, language: .cpp, options: .init()), changed4)
280280
])
281281
await manager.mainFilesChanged()
282-
try await fulfillmentOfOrThrow([changed4])
282+
try await fulfillmentOfOrThrow(changed4)
283283
}
284284

285285
func testSettingsOneMainTwoHeader() async throws {
@@ -332,7 +332,7 @@ final class BuildSystemManagerTests: XCTestCase {
332332
for: cpp,
333333
to: TextDocumentSourceKitOptionsResponse(compilerArguments: [newCppArg, cpp.pseudoPath])
334334
)
335-
try await fulfillmentOfOrThrow([changed1, changed2])
335+
try await fulfillmentOfOrThrow(changed1, changed2)
336336
}
337337
}
338338

Tests/LanguageServerProtocolJSONRPCTests/ConnectionTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ConnectionTests: XCTestCase {
5252
expectation.fulfill()
5353
}
5454

55-
try await fulfillmentOfOrThrow([expectation])
55+
try await fulfillmentOfOrThrow(expectation)
5656
}
5757

5858
func testMessageBuffer() async throws {
@@ -81,7 +81,7 @@ class ConnectionTests: XCTestCase {
8181
_rawData: [notification1Str.utf8.last!, notfication2Str.utf8.first!].withUnsafeBytes { DispatchData(bytes: $0) }
8282
)
8383

84-
try await fulfillmentOfOrThrow([expectation])
84+
try await fulfillmentOfOrThrow(expectation)
8585

8686
let expectation2 = self.expectation(description: "notification received")
8787

@@ -94,7 +94,7 @@ class ConnectionTests: XCTestCase {
9494
clientConnection.send(_rawData: [b].withUnsafeBytes { DispatchData(bytes: $0) })
9595
}
9696

97-
try await fulfillmentOfOrThrow([expectation2])
97+
try await fulfillmentOfOrThrow(expectation2)
9898

9999
// Close the connection before accessing requestBuffer, which ensures we don't race.
100100
connection.serverToClientConnection.close()
@@ -120,7 +120,7 @@ class ConnectionTests: XCTestCase {
120120
expectation2.fulfill()
121121
}
122122

123-
try await fulfillmentOfOrThrow([expectation, expectation2])
123+
try await fulfillmentOfOrThrow(expectation, expectation2)
124124
}
125125

126126
func testEchoNotification() async throws {
@@ -134,7 +134,7 @@ class ConnectionTests: XCTestCase {
134134

135135
client.send(EchoNotification(string: "hello!"))
136136

137-
try await fulfillmentOfOrThrow([expectation])
137+
try await fulfillmentOfOrThrow(expectation)
138138
}
139139

140140
func testUnknownRequest() async throws {
@@ -151,7 +151,7 @@ class ConnectionTests: XCTestCase {
151151
expectation.fulfill()
152152
}
153153

154-
try await fulfillmentOfOrThrow([expectation])
154+
try await fulfillmentOfOrThrow(expectation)
155155
}
156156

157157
func testUnknownNotification() async throws {
@@ -173,7 +173,7 @@ class ConnectionTests: XCTestCase {
173173
expectation.fulfill()
174174
}
175175

176-
try await fulfillmentOfOrThrow([expectation])
176+
try await fulfillmentOfOrThrow(expectation)
177177
}
178178

179179
func testUnexpectedResponse() async throws {
@@ -192,7 +192,7 @@ class ConnectionTests: XCTestCase {
192192
expectation.fulfill()
193193
}
194194

195-
try await fulfillmentOfOrThrow([expectation])
195+
try await fulfillmentOfOrThrow(expectation)
196196
}
197197

198198
func testSendAfterClose() async throws {
@@ -212,7 +212,7 @@ class ConnectionTests: XCTestCase {
212212
connection.clientToServerConnection.close()
213213
connection.clientToServerConnection.close()
214214

215-
try await fulfillmentOfOrThrow([expectation])
215+
try await fulfillmentOfOrThrow(expectation)
216216
}
217217

218218
func testSendBeforeClose() async throws {
@@ -227,7 +227,7 @@ class ConnectionTests: XCTestCase {
227227
server.client.send(EchoNotification(string: "about to close!"))
228228
connection.serverToClientConnection.close()
229229

230-
try await fulfillmentOfOrThrow([expectation])
230+
try await fulfillmentOfOrThrow(expectation)
231231
}
232232

233233
/// We can explicitly close a connection, but the connection also
@@ -279,7 +279,7 @@ class ConnectionTests: XCTestCase {
279279
#endif
280280
conn.close()
281281

282-
try await fulfillmentOfOrThrow([expectation])
282+
try await fulfillmentOfOrThrow(expectation)
283283
withExtendedLifetime(conn) {}
284284
}
285285
}
@@ -300,7 +300,7 @@ class ConnectionTests: XCTestCase {
300300
"""
301301
connection.clientToServerConnection.send(message: messageContents)
302302

303-
try await fulfillmentOfOrThrow([expectation])
303+
try await fulfillmentOfOrThrow(expectation)
304304
}
305305
}
306306

Tests/LanguageServerProtocolTests/ConnectionTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ConnectionTests: XCTestCase {
3737
expectation.fulfill()
3838
}
3939

40-
try await fulfillmentOfOrThrow([expectation])
40+
try await fulfillmentOfOrThrow(expectation)
4141
}
4242

4343
func testEchoError() async throws {
@@ -57,7 +57,7 @@ class ConnectionTests: XCTestCase {
5757
expectation2.fulfill()
5858
}
5959

60-
try await fulfillmentOfOrThrow([expectation, expectation2])
60+
try await fulfillmentOfOrThrow(expectation, expectation2)
6161
}
6262

6363
func testEchoNotification() async throws {
@@ -71,6 +71,6 @@ class ConnectionTests: XCTestCase {
7171

7272
client.send(EchoNotification(string: "hello!"))
7373

74-
try await fulfillmentOfOrThrow([expectation])
74+
try await fulfillmentOfOrThrow(expectation)
7575
}
7676
}

Tests/SKLoggingTests/LoggingTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ final class LoggingTests: XCTestCase {
8383
}
8484
)
8585
logger.log(level: .error, "my message")
86-
try await fulfillmentOfOrThrow([expectation])
86+
try await fulfillmentOfOrThrow(expectation)
8787
XCTAssert(
8888
message.starts(with: "[org.swift.sourcekit-lsp:test] error"),
8989
"Message did not have expected header. Received \n\(message)"

Tests/SKUtilitiesTests/DebouncerTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class DebouncerTests: XCTestCase {
2323
}
2424
await debouncer.scheduleCall()
2525
await debouncer.scheduleCall()
26-
try await fulfillmentOfOrThrow([expectation])
26+
try await fulfillmentOfOrThrow(expectation)
2727
// Sleep for 0.2s to make sure the debouncer actually debounces and doesn't fulfill the expectation twice.
2828
try await Task.sleep(for: .seconds(0.2))
2929
}
@@ -37,6 +37,6 @@ final class DebouncerTests: XCTestCase {
3737
}
3838
await debouncer.scheduleCall(1)
3939
await debouncer.scheduleCall(2)
40-
try await fulfillmentOfOrThrow([expectation])
40+
try await fulfillmentOfOrThrow(expectation)
4141
}
4242
}

Tests/SemanticIndexTests/TaskSchedulerTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,17 @@ final class TaskSchedulerTests: XCTestCase {
226226
}
227227

228228
// The high priority task should be able to finish because we have an execution slot for it.
229-
try await fulfillmentOfOrThrow([highPriorityTaskFinished])
229+
try await fulfillmentOfOrThrow(highPriorityTaskFinished)
230230

231231
// But we shouldn't be able to execute the low priority task because it doesn't have an execution slot.
232-
await assertThrowsError(try await fulfillmentOfOrThrow([lowPriorityTaskFinished1], timeout: 1)) { error in
232+
await assertThrowsError(try await fulfillmentOfOrThrow(lowPriorityTaskFinished1, timeout: 1)) { error in
233233
XCTAssert(error is ExpectationNotFulfilledError)
234234
}
235235

236236
await taskScheduler.setMaxConcurrentTasksByPriority([(.high, 1), (.low, 1)])
237237

238238
// After increasing the number of execution slots, we should be able to execute the low-priority task
239-
try await fulfillmentOfOrThrow([lowPriorityTaskFinished2])
239+
try await fulfillmentOfOrThrow(lowPriorityTaskFinished2)
240240
}
241241

242242
func testDecreaseNumberOfExecutionSlots() async throws {
@@ -261,7 +261,7 @@ final class TaskSchedulerTests: XCTestCase {
261261
taskStartedExecuting.fulfill()
262262

263263
do {
264-
try await fulfillmentOfOrThrow([executionSlotsReduced])
264+
try await fulfillmentOfOrThrow(executionSlotsReduced)
265265

266266
try await repeatUntilExpectedResult {
267267
try Task.checkCancellation()
@@ -276,14 +276,14 @@ final class TaskSchedulerTests: XCTestCase {
276276
}
277277

278278
// Check that we cancel the in-progress task when reducing the number of execution slots
279-
try await fulfillmentOfOrThrow([taskStartedExecuting])
279+
try await fulfillmentOfOrThrow(taskStartedExecuting)
280280
await taskScheduler.setMaxConcurrentTasksByPriority([(.low, 0)])
281281
executionSlotsReduced.fulfill()
282-
try await fulfillmentOfOrThrow([taskCancelled])
282+
try await fulfillmentOfOrThrow(taskCancelled)
283283

284284
// And check that we execute it again when increasing the number of execution slots again
285285
await taskScheduler.setMaxConcurrentTasksByPriority([(.low, 1)])
286-
try await fulfillmentOfOrThrow([taskExecutedAgain])
286+
try await fulfillmentOfOrThrow(taskExecutedAgain)
287287
}
288288

289289
func testUseAllExecutionSlotsWithHighAndLowPriorityTasks() async throws {

Tests/SourceKitDTests/CrashRecoveryTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ final class CrashRecoveryTests: XCTestCase {
139139

140140
await clangdServer.crash()
141141

142-
try await fulfillmentOfOrThrow([clangdCrashed])
143-
try await fulfillmentOfOrThrow([clangdRestarted])
142+
try await fulfillmentOfOrThrow(clangdCrashed)
143+
try await fulfillmentOfOrThrow(clangdRestarted)
144144
}
145145

146146
func testClangdCrashRecovery() async throws {
@@ -298,15 +298,15 @@ final class CrashRecoveryTests: XCTestCase {
298298

299299
await clangdServer.crash()
300300

301-
try await fulfillmentOfOrThrow([clangdCrashed], timeout: 5)
302-
try await fulfillmentOfOrThrow([clangdRestartedFirstTime], timeout: 30)
301+
try await fulfillmentOfOrThrow(clangdCrashed, timeout: 5)
302+
try await fulfillmentOfOrThrow(clangdRestartedFirstTime, timeout: 30)
303303
// Clangd has restarted. Note the date so we can check that the second restart doesn't happen too quickly.
304304
let firstRestartDate = Date()
305305

306306
// Crash clangd again. This time, it should only restart after a delay.
307307
await clangdServer.crash()
308308

309-
try await fulfillmentOfOrThrow([clangdRestartedSecondTime], timeout: 30)
309+
try await fulfillmentOfOrThrow(clangdRestartedSecondTime, timeout: 30)
310310
XCTAssert(
311311
Date().timeIntervalSince(firstRestartDate) > 5,
312312
"Clangd restarted too quickly after crashing twice in a row. We are not preventing crash loops."

Tests/SourceKitDTests/SourceKitDTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ final class SourceKitDTests: XCTestCase {
8686

8787
_ = try await sourcekitd.send(req, timeout: defaultTimeoutDuration, fileContents: nil)
8888

89-
try await fulfillmentOfOrThrow([expectation1, expectation2])
89+
try await fulfillmentOfOrThrow(expectation1, expectation2)
9090

9191
let close = sourcekitd.dictionary([
9292
keys.request: sourcekitd.requests.editorClose,

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ final class BackgroundIndexingTests: XCTestCase {
604604
DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri))
605605
)
606606

607-
try await fulfillmentOfOrThrow([receivedEmptyDiagnostics])
607+
try await fulfillmentOfOrThrow(receivedEmptyDiagnostics)
608608

609609
// Check that we received a work done progress for the re-preparation of the target
610610
_ = try await project.testClient.nextNotification(
@@ -2618,7 +2618,7 @@ final class BackgroundIndexingTests: XCTestCase {
26182618
func myTestFunc() {}
26192619
"""
26202620
)
2621-
try await fulfillmentOfOrThrow([updateIndexStoreStarted])
2621+
try await fulfillmentOfOrThrow(updateIndexStoreStarted)
26222622
try await repeatUntilExpectedResult(sleepInterval: .milliseconds(2)) {
26232623
try await !project.testClient.send(IsIndexingRequest()).indexing
26242624
}

Tests/SourceKitLSPTests/CodeActionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ final class CodeActionTests: XCTestCase {
505505
}
506506
_ = try await testClient.send(ExecuteCommandRequest(command: command.command, arguments: command.arguments))
507507

508-
try await fulfillmentOfOrThrow([editReceived])
508+
try await fulfillmentOfOrThrow(editReceived)
509509
}
510510

511511
func testAddDocumentationCodeActionResult() async throws {

Tests/SourceKitLSPTests/DefinitionTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ class DefinitionTests: XCTestCase {
366366
diagnosticRefreshRequestReceived.fulfill()
367367
return VoidResponse()
368368
}
369-
try await fulfillmentOfOrThrow([diagnosticRefreshRequestReceived])
369+
try await fulfillmentOfOrThrow(diagnosticRefreshRequestReceived)
370370

371371
let afterChangingFileA = try await project.testClient.send(
372372
DefinitionRequest(textDocument: TextDocumentIdentifier(bUri), position: bPositions["1️⃣"])
@@ -438,7 +438,7 @@ class DefinitionTests: XCTestCase {
438438
diagnosticRefreshRequestReceived.fulfill()
439439
return VoidResponse()
440440
}
441-
try await fulfillmentOfOrThrow([diagnosticRefreshRequestReceived])
441+
try await fulfillmentOfOrThrow(diagnosticRefreshRequestReceived)
442442

443443
let afterBuilding = try await project.testClient.send(
444444
DefinitionRequest(textDocument: TextDocumentIdentifier(bUri), position: bPositions["2️⃣"])

Tests/SourceKitLSPTests/ExecuteCommandTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class ExecuteCommandTests: XCTestCase {
5959

6060
let _ = try await testClient.send(request)
6161

62-
try await fulfillmentOfOrThrow([expectation])
62+
try await fulfillmentOfOrThrow(expectation)
6363

6464
let label = try XCTUnwrap(applyEditTitle.value)
6565
let edit = try XCTUnwrap(applyEditWorkspaceEdit.value)
@@ -124,7 +124,7 @@ final class ExecuteCommandTests: XCTestCase {
124124

125125
let _ = try await testClient.send(request)
126126

127-
try await fulfillmentOfOrThrow([expectation])
127+
try await fulfillmentOfOrThrow(expectation)
128128

129129
let label = try XCTUnwrap(applyEditTitle.value)
130130
let edit = try XCTUnwrap(applyEditWorkspaceEdit.value)

0 commit comments

Comments
 (0)