Skip to content

Commit 12c1c0c

Browse files
committed
All parts of the dsl must take in sending (#1167)
1 parent fc7bb4c commit 12c1c0c

File tree

7 files changed

+115
-57
lines changed

7 files changed

+115
-57
lines changed

Sources/Nimble/DSL+AsyncAwait.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Dispatch
33
#endif
44

55
/// Make an ``AsyncExpectation`` on a given actual value. The value given is lazily evaluated.
6-
public func expect<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @escaping @Sendable () async throws -> T?) -> AsyncExpectation<T> {
6+
public func expect<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @escaping @Sendable () async throws -> sending T?) -> AsyncExpectation<T> {
77
return AsyncExpectation(
88
expression: AsyncExpression(
99
expression: expression,
@@ -12,7 +12,7 @@ public func expect<T: Sendable>(fileID: String = #fileID, file: FileString = #fi
1212
}
1313

1414
/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
15-
public func expect<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @Sendable () -> (@Sendable () async throws -> T)) -> AsyncExpectation<T> {
15+
public func expect<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @Sendable () -> (@Sendable () async throws -> sending T)) -> AsyncExpectation<T> {
1616
return AsyncExpectation(
1717
expression: AsyncExpression(
1818
expression: expression(),
@@ -21,7 +21,7 @@ public func expect<T: Sendable>(fileID: String = #fileID, file: FileString = #fi
2121
}
2222

2323
/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
24-
public func expect<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @Sendable () -> (@Sendable () async throws -> T?)) -> AsyncExpectation<T> {
24+
public func expect<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @Sendable () -> (@Sendable () async throws -> sending T?)) -> AsyncExpectation<T> {
2525
return AsyncExpectation(
2626
expression: AsyncExpression(
2727
expression: expression(),
@@ -30,7 +30,7 @@ public func expect<T: Sendable>(fileID: String = #fileID, file: FileString = #fi
3030
}
3131

3232
/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
33-
public func expect(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @Sendable () -> (@Sendable () async throws -> Void)) -> AsyncExpectation<Void> {
33+
public func expect(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @Sendable () -> (@Sendable () async throws -> sending Void)) -> AsyncExpectation<Void> {
3434
return AsyncExpectation(
3535
expression: AsyncExpression(
3636
expression: expression(),
@@ -40,7 +40,7 @@ public func expect(fileID: String = #fileID, file: FileString = #filePath, line:
4040

4141
/// Make an ``AsyncExpectation`` on a given actual value. The value given is lazily evaluated.
4242
/// This is provided to avoid confusion between `expect -> SyncExpectation` and `expect -> AsyncExpectation`.
43-
public func expecta<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure @escaping @Sendable () async throws -> T?) async -> AsyncExpectation<T> {
43+
public func expecta<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure @escaping @Sendable () async throws -> sending T?) async -> AsyncExpectation<T> {
4444
return AsyncExpectation(
4545
expression: AsyncExpression(
4646
expression: expression,
@@ -50,7 +50,7 @@ public func expecta<T: Sendable>(fileID: String = #fileID, file: FileString = #f
5050

5151
/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
5252
/// This is provided to avoid confusion between `expect -> SyncExpectation` and `expect -> AsyncExpectation`
53-
public func expecta<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> T)) async -> AsyncExpectation<T> {
53+
public func expecta<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> sending T)) async -> AsyncExpectation<T> {
5454
return AsyncExpectation(
5555
expression: AsyncExpression(
5656
expression: expression(),
@@ -60,7 +60,7 @@ public func expecta<T: Sendable>(fileID: String = #fileID, file: FileString = #f
6060

6161
/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
6262
/// This is provided to avoid confusion between `expect -> SyncExpectation` and `expect -> AsyncExpectation`
63-
public func expecta<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> T?)) async -> AsyncExpectation<T> {
63+
public func expecta<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> sending T?)) async -> AsyncExpectation<T> {
6464
return AsyncExpectation(
6565
expression: AsyncExpression(
6666
expression: expression(),
@@ -70,7 +70,7 @@ public func expecta<T: Sendable>(fileID: String = #fileID, file: FileString = #f
7070

7171
/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
7272
/// This is provided to avoid confusion between `expect -> SyncExpectation` and `expect -> AsyncExpectation`
73-
public func expecta(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> Void)) async -> AsyncExpectation<Void> {
73+
public func expecta(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> sending Void)) async -> AsyncExpectation<Void> {
7474
return AsyncExpectation(
7575
expression: AsyncExpression(
7676
expression: expression(),

Sources/Nimble/DSL+Require.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public func requires(fileID: String = #fileID, file: FileString = #filePath, lin
123123
/// `require` will return the result of the expression if the matcher passes, and throw an error if not.
124124
/// if a `customError` is given, then that will be thrown. Otherwise, a ``RequireError`` will be thrown.
125125
@discardableResult
126-
public func require<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, _ expression: @escaping () async throws -> T?) -> AsyncRequirement<T> {
126+
public func require<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, _ expression: @escaping @Sendable () async throws -> sending T?) -> AsyncRequirement<T> {
127127
return AsyncRequirement(
128128
expression: AsyncExpression(
129129
expression: expression,
@@ -137,7 +137,7 @@ public func require<T: Sendable>(fileID: String = #fileID, file: FileString = #f
137137
/// `require` will return the result of the expression if the matcher passes, and throw an error if not.
138138
/// if a `customError` is given, then that will be thrown. Otherwise, a ``RequireError`` will be thrown.
139139
@discardableResult
140-
public func require<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, _ expression: () -> (() async throws -> T)) -> AsyncRequirement<T> {
140+
public func require<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, _ expression: () -> (@Sendable () async throws -> sending T)) -> AsyncRequirement<T> {
141141
return AsyncRequirement(
142142
expression: AsyncExpression(
143143
expression: expression(),
@@ -151,7 +151,7 @@ public func require<T: Sendable>(fileID: String = #fileID, file: FileString = #f
151151
/// `require` will return the result of the expression if the matcher passes, and throw an error if not.
152152
/// if a `customError` is given, then that will be thrown. Otherwise, a ``RequireError`` will be thrown.
153153
@discardableResult
154-
public func require<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, _ expression: () -> (() async throws -> T?)) -> AsyncRequirement<T> {
154+
public func require<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, _ expression: () -> (@Sendable () async throws -> sending T?)) -> AsyncRequirement<T> {
155155
return AsyncRequirement(
156156
expression: AsyncExpression(
157157
expression: expression(),
@@ -167,7 +167,7 @@ public func require<T: Sendable>(fileID: String = #fileID, file: FileString = #f
167167
///
168168
/// This is provided to avoid confusion between `require -> SyncRequirement` and `require -> AsyncRequirement`.
169169
@discardableResult
170-
public func requirea<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, _ expression: @autoclosure @escaping () async throws -> T?) async -> AsyncRequirement<T> {
170+
public func requirea<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, _ expression: @autoclosure @escaping @Sendable () async throws -> sending T?) async -> AsyncRequirement<T> {
171171
return AsyncRequirement(
172172
expression: AsyncExpression(
173173
expression: expression,
@@ -183,7 +183,7 @@ public func requirea<T: Sendable>(fileID: String = #fileID, file: FileString = #
183183
///
184184
/// This is provided to avoid confusion between `require -> SyncRequirement` and `require -> AsyncRequirement`
185185
@discardableResult
186-
public func requirea<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, _ expression: @autoclosure () -> (() async throws -> T)) async -> AsyncRequirement<T> {
186+
public func requirea<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, _ expression: @autoclosure () -> (@Sendable () async throws -> sending T)) async -> AsyncRequirement<T> {
187187
return AsyncRequirement(
188188
expression: AsyncExpression(
189189
expression: expression(),
@@ -199,7 +199,7 @@ public func requirea<T: Sendable>(fileID: String = #fileID, file: FileString = #
199199
///
200200
/// This is provided to avoid confusion between `require -> SyncRequirement` and `require -> AsyncRequirement`
201201
@discardableResult
202-
public func requirea<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, _ expression: @autoclosure () -> (() async throws -> T?)) async -> AsyncRequirement<T> {
202+
public func requirea<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, _ expression: @autoclosure () -> (@Sendable () async throws -> sending T?)) async -> AsyncRequirement<T> {
203203
return AsyncRequirement(
204204
expression: AsyncExpression(
205205
expression: expression(),
@@ -266,7 +266,7 @@ public func unwrap<T: Sendable>(fileID: String = #fileID, file: FileString = #fi
266266
/// `unwrap` will return the result of the expression if it is non-nil, and throw an error if the value is nil.
267267
/// if a `customError` is given, then that will be thrown. Otherwise, a ``RequireError`` will be thrown.
268268
@discardableResult
269-
public func unwrap<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, description: String? = nil, _ expression: () -> (() async throws -> T?)) async throws -> T {
269+
public func unwrap<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, description: String? = nil, _ expression: () -> (@Sendable () async throws -> sending T?)) async throws -> T {
270270
try await requirea(fileID: fileID, file: file, line: line, column: column, customError: customError, expression()).toNot(beNil(), description: description)
271271
}
272272

@@ -286,7 +286,7 @@ public func unwrapa<T: Sendable>(fileID: String = #fileID, file: FileString = #f
286286
/// `unwrapa` will return the result of the expression if it is non-nil, and throw an error if the value is nil.
287287
/// if a `customError` is given, then that will be thrown. Otherwise, a ``RequireError`` will be thrown.
288288
@discardableResult
289-
public func unwrapa<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, description: String? = nil, _ expression: @autoclosure () -> (() async throws -> T?)) async throws -> T {
289+
public func unwrapa<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, customError: Error? = nil, description: String? = nil, _ expression: @autoclosure () -> (@Sendable () async throws -> sending T?)) async throws -> T {
290290
try await requirea(fileID: fileID, file: file, line: line, column: column, customError: customError, expression()).toNot(beNil(), description: description)
291291
}
292292

Sources/Nimble/DSL.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ public func expects<T>(fileID: String = #fileID, file: FileString = #filePath, l
6666

6767
/// Make a ``SyncExpectation`` on a given actual value. The closure is lazily invoked.
6868
/// This is provided as an alternative to `expect` which avoids overloading with `expect -> AsyncExpectation`.
69-
public func expects(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure () -> (@Sendable () throws -> Void)) -> SyncExpectation<Void> {
69+
public func expects(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure () -> (@Sendable () throws -> sending Void)) -> SyncExpectation<Void> {
70+
// It would seem like `sending` isn't necessary for the `expression` argument
71+
// because the closure returns void. However, this gets rid of a type
72+
// conversion warning/error.
7073
return SyncExpectation(
7174
expression: Expression(
7275
expression: expression(),

Sources/Nimble/Polling+Require.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ public func pollUnwrap<T>(file: FileString = #file, line: UInt = #line, _ expres
715715
/// Makes sure that the expression evaluates to a non-nil value, otherwise throw an error.
716716
/// As you can tell, this is a much less verbose equivalent to `require(expression).toEventuallyNot(beNil())`
717717
@discardableResult
718-
public func pollUnwrap<T>(file: FileString = #file, line: UInt = #line, timeout: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil, _ expression: @autoclosure () -> (@Sendable () throws -> T?)) throws -> T {
718+
public func pollUnwrap<T>(file: FileString = #file, line: UInt = #line, timeout: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil, _ expression: @autoclosure () -> (@Sendable () throws -> sending T?)) throws -> T {
719719
try require(file: file, line: line, expression()).toEventuallyNot(beNil(), timeout: timeout, pollInterval: pollInterval, description: description)
720720
}
721721

@@ -729,7 +729,7 @@ public func pollUnwraps<T>(file: FileString = #file, line: UInt = #line, timeout
729729
/// Makes sure that the expression evaluates to a non-nil value, otherwise throw an error.
730730
/// As you can tell, this is a much less verbose equivalent to `require(expression).toEventuallyNot(beNil())`
731731
@discardableResult
732-
public func pollUnwraps<T>(file: FileString = #file, line: UInt = #line, timeout: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil, _ expression: @autoclosure () -> (@Sendable () throws -> T?)) throws -> T {
732+
public func pollUnwraps<T>(file: FileString = #file, line: UInt = #line, timeout: NimbleTimeInterval = PollingDefaults.timeout, pollInterval: NimbleTimeInterval = PollingDefaults.pollInterval, description: String? = nil, _ expression: @autoclosure () -> (@Sendable () throws -> sending T?)) throws -> T {
733733
try require(file: file, line: line, expression()).toEventuallyNot(beNil(), timeout: timeout, pollInterval: pollInterval, description: description)
734734
}
735735

Tests/NimbleTests/Matchers/BeIdenticalToTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class BeIdenticalToTest: XCTestCase {
2626
}
2727

2828
func testBeIdenticalToNegativeMessage() {
29-
let value1 = NSArray()
29+
let value1 = 1 as NSNumber
3030
let value2 = value1
3131
let message = "expected to not be identical to \(identityAsString(value2)), got \(identityAsString(value1))"
3232
failsWithErrorMessage(message) {
@@ -46,7 +46,7 @@ final class BeIdenticalToTest: XCTestCase {
4646
expect(1 as NSNumber).toNot(be("turtles" as NSString))
4747
expect([1 as NSNumber] as NSArray).toNot(be([1 as NSNumber] as NSArray))
4848

49-
let value1 = NSArray()
49+
let value1 = 1 as NSNumber
5050
let value2 = value1
5151
let message = "expected to not be identical to \(identityAsString(value1)), got \(identityAsString(value2))"
5252
failsWithErrorMessage(message) {

0 commit comments

Comments
 (0)