Skip to content

Commit 27cef92

Browse files
committed
Mork work on getting the async-version of polling expectations to be compatible with swift 6
1 parent 599568b commit 27cef92

2 files changed

Lines changed: 94 additions & 18 deletions

File tree

Sources/Nimble/AsyncExpression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public struct AsyncExpression<Value> {
167167
)
168168
}
169169

170-
public func evaluate() async throws -> Value? {
170+
public func evaluate() async throws -> sending Value? {
171171
try await self._expression(_withoutCaching)
172172
}
173173

Sources/Nimble/Polling+AsyncAwait.swift

Lines changed: 93 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
import Dispatch
55

66
@MainActor
7-
internal func execute<T>(_ expression: AsyncExpression<T>, style: ExpectationStyle, to: String, description: String?, matcherExecutor: () async throws -> MatcherResult) async -> (Bool, FailureMessage) {
7+
internal func execute<T>(
8+
_ expression: AsyncExpression<T>,
9+
style: ExpectationStyle,
10+
to: String,
11+
description: String?,
12+
matcherExecutor: @Sendable () async throws -> MatcherResult
13+
) async -> (Bool, FailureMessage) {
814
let msg = FailureMessage()
915
msg.userDescription = description
1016
msg.to = to
@@ -33,7 +39,7 @@ internal actor Poller<T> {
3339
timeout: NimbleTimeInterval,
3440
poll: NimbleTimeInterval,
3541
fnName: String,
36-
matcherRunner: @escaping () async throws -> MatcherResult) async -> MatcherResult {
42+
matcherRunner: @escaping @Sendable () async throws -> MatcherResult) async -> MatcherResult {
3743
let fnName = "expect(...).\(fnName)(...)"
3844
let result = await pollBlock(
3945
pollInterval: poll,
@@ -71,7 +77,7 @@ internal func poll<T>(
7177
timeout: NimbleTimeInterval,
7278
poll: NimbleTimeInterval,
7379
fnName: String,
74-
matcherRunner: @escaping () async throws -> MatcherResult
80+
matcherRunner: @escaping @Sendable () async throws -> MatcherResult
7581
) async -> MatcherResult {
7682
let poller = Poller<T>()
7783
return await poller.poll(
@@ -90,7 +96,12 @@ extension SyncExpectation {
9096
/// Tests the actual value using a matcher to match by checking continuously
9197
/// at each pollInterval until the timeout is reached.
9298
@discardableResult
93-
public func toEventually(_ matcher: Matcher<Value>, timeout: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
99+
public func toEventually(
100+
_ matcher: Matcher<Value>,
101+
timeout: NimbleTimeInterval = PollingDefaults.timeout,
102+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
103+
description: String? = nil
104+
) async -> Self {
94105
nimblePrecondition(expression.isClosure, "NimbleInternalError", toEventuallyRequiresClosureError.stringValue)
95106

96107
let asyncExpression = expression.toAsyncExpression()
@@ -116,7 +127,12 @@ extension SyncExpectation {
116127
/// Tests the actual value using a matcher to not match by checking
117128
/// continuously at each pollInterval until the timeout is reached.
118129
@discardableResult
119-
public func toEventuallyNot(_ matcher: Matcher<Value>, timeout: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
130+
public func toEventuallyNot(
131+
_ matcher: Matcher<Value>,
132+
timeout: NimbleTimeInterval = PollingDefaults.timeout,
133+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
134+
description: String? = nil
135+
) async -> Self {
120136
nimblePrecondition(expression.isClosure, "NimbleInternalError", toEventuallyRequiresClosureError.stringValue)
121137

122138
let asyncExpression = expression.toAsyncExpression()
@@ -144,14 +160,24 @@ extension SyncExpectation {
144160
///
145161
/// Alias of toEventuallyNot()
146162
@discardableResult
147-
public func toNotEventually(_ matcher: Matcher<Value>, timeout: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
163+
public func toNotEventually(
164+
_ matcher: Matcher<Value>,
165+
timeout: NimbleTimeInterval = PollingDefaults.timeout,
166+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
167+
description: String? = nil
168+
) async -> Self {
148169
return await toEventuallyNot(matcher, timeout: timeout, pollInterval: pollInterval, description: description)
149170
}
150171

151172
/// Tests the actual value using a matcher to never match by checking
152173
/// continuously at each pollInterval until the timeout is reached.
153174
@discardableResult
154-
public func toNever(_ matcher: Matcher<Value>, until: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
175+
public func toNever(
176+
_ matcher: Matcher<Value>,
177+
until: NimbleTimeInterval = PollingDefaults.timeout,
178+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
179+
description: String? = nil
180+
) async -> Self {
155181
nimblePrecondition(expression.isClosure, "NimbleInternalError", toEventuallyRequiresClosureError.stringValue)
156182
let asyncExpression = expression.toAsyncExpression()
157183

@@ -178,14 +204,24 @@ extension SyncExpectation {
178204
///
179205
/// Alias of toNever()
180206
@discardableResult
181-
public func neverTo(_ matcher: Matcher<Value>, until: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
207+
public func neverTo(
208+
_ matcher: Matcher<Value>,
209+
until: NimbleTimeInterval = PollingDefaults.timeout,
210+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
211+
description: String? = nil
212+
) async -> Self {
182213
return await toNever(matcher, until: until, pollInterval: pollInterval, description: description)
183214
}
184215

185216
/// Tests the actual value using a matcher to always match by checking
186217
/// continusouly at each pollInterval until the timeout is reached
187218
@discardableResult
188-
public func toAlways(_ matcher: Matcher<Value>, until: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
219+
public func toAlways(
220+
_ matcher: Matcher<Value>,
221+
until: NimbleTimeInterval = PollingDefaults.timeout,
222+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
223+
description: String? = nil
224+
) async -> Self {
189225
nimblePrecondition(expression.isClosure, "NimbleInternalError", toEventuallyRequiresClosureError.stringValue)
190226
let asyncExpression = expression.toAsyncExpression()
191227

@@ -212,15 +248,25 @@ extension SyncExpectation {
212248
///
213249
/// Alias of toAlways()
214250
@discardableResult
215-
public func alwaysTo(_ matcher: Matcher<Value>, until: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
251+
public func alwaysTo(
252+
_ matcher: Matcher<Value>,
253+
until: NimbleTimeInterval = PollingDefaults.timeout,
254+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
255+
description: String? = nil
256+
) async -> Self {
216257
return await toAlways(matcher, until: until, pollInterval: pollInterval, description: description)
217258
}
218259

219260
// MARK: - With AsyncMatchers
220261
/// Tests the actual value using a matcher to match by checking continuously
221262
/// at each pollInterval until the timeout is reached.
222263
@discardableResult
223-
public func toEventually(_ matcher: AsyncMatcher<Value>, timeout: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
264+
public func toEventually(
265+
_ matcher: AsyncMatcher<Value>,
266+
timeout: NimbleTimeInterval = PollingDefaults.timeout,
267+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
268+
description: String? = nil
269+
) async -> Self {
224270
nimblePrecondition(expression.isClosure, "NimbleInternalError", toEventuallyRequiresClosureError.stringValue)
225271

226272
let asyncExpression = expression.toAsyncExpression()
@@ -246,7 +292,12 @@ extension SyncExpectation {
246292
/// Tests the actual value using a matcher to not match by checking
247293
/// continuously at each pollInterval until the timeout is reached.
248294
@discardableResult
249-
public func toEventuallyNot(_ matcher: AsyncMatcher<Value>, timeout: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
295+
public func toEventuallyNot(
296+
_ matcher: AsyncMatcher<Value>,
297+
timeout: NimbleTimeInterval = PollingDefaults.timeout,
298+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
299+
description: String? = nil
300+
) async -> Self {
250301
nimblePrecondition(expression.isClosure, "NimbleInternalError", toEventuallyRequiresClosureError.stringValue)
251302

252303
let asyncExpression = expression.toAsyncExpression()
@@ -274,14 +325,24 @@ extension SyncExpectation {
274325
///
275326
/// Alias of toEventuallyNot()
276327
@discardableResult
277-
public func toNotEventually(_ matcher: AsyncMatcher<Value>, timeout: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
328+
public func toNotEventually(
329+
_ matcher: AsyncMatcher<Value>,
330+
timeout: NimbleTimeInterval = PollingDefaults.timeout,
331+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
332+
description: String? = nil
333+
) async -> Self {
278334
return await toEventuallyNot(matcher, timeout: timeout, pollInterval: pollInterval, description: description)
279335
}
280336

281337
/// Tests the actual value using a matcher to never match by checking
282338
/// continuously at each pollInterval until the timeout is reached.
283339
@discardableResult
284-
public func toNever(_ matcher: AsyncMatcher<Value>, until: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
340+
public func toNever(
341+
_ matcher: AsyncMatcher<Value>,
342+
until: NimbleTimeInterval = PollingDefaults.timeout,
343+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
344+
description: String? = nil
345+
) async -> Self {
285346
nimblePrecondition(expression.isClosure, "NimbleInternalError", toEventuallyRequiresClosureError.stringValue)
286347
let asyncExpression = expression.toAsyncExpression()
287348

@@ -308,14 +369,24 @@ extension SyncExpectation {
308369
///
309370
/// Alias of toNever()
310371
@discardableResult
311-
public func neverTo(_ matcher: AsyncMatcher<Value>, until: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
372+
public func neverTo(
373+
_ matcher: AsyncMatcher<Value>,
374+
until: NimbleTimeInterval = PollingDefaults.timeout,
375+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
376+
description: String? = nil
377+
) async -> Self {
312378
return await toNever(matcher, until: until, pollInterval: pollInterval, description: description)
313379
}
314380

315381
/// Tests the actual value using a matcher to always match by checking
316382
/// continusouly at each pollInterval until the timeout is reached
317383
@discardableResult
318-
public func toAlways(_ matcher: AsyncMatcher<Value>, until: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
384+
public func toAlways(
385+
_ matcher: AsyncMatcher<Value>,
386+
until: NimbleTimeInterval = PollingDefaults.timeout,
387+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
388+
description: String? = nil
389+
) async -> Self {
319390
nimblePrecondition(expression.isClosure, "NimbleInternalError", toEventuallyRequiresClosureError.stringValue)
320391
let asyncExpression = expression.toAsyncExpression()
321392

@@ -342,7 +413,12 @@ extension SyncExpectation {
342413
///
343414
/// Alias of toAlways()
344415
@discardableResult
345-
public func alwaysTo(_ matcher: AsyncMatcher<Value>, until: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil) async -> Self {
416+
public func alwaysTo(
417+
_ matcher: AsyncMatcher<Value>,
418+
until: NimbleTimeInterval = PollingDefaults.timeout,
419+
pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval,
420+
description: String? = nil
421+
) async -> Self {
346422
return await toAlways(matcher, until: until, pollInterval: pollInterval, description: description)
347423
}
348424
}

0 commit comments

Comments
 (0)