├── .github
└── workflows
│ └── test.yml
├── .gitignore
├── LICENSE
├── Package.swift
├── README.md
├── Sources
└── XCTAsync
│ └── XCTAsync.swift
└── Tests
└── XCTAsyncTests
└── XCTAsyncTests.swift
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test XCTAsync
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - main
7 |
8 | jobs:
9 | Test:
10 | runs-on: ubuntu-latest
11 | timeout-minutes: 10
12 | steps:
13 | - name: Checkout Source
14 | uses: actions/checkout@v2
15 | # - name: Build
16 | # run: |
17 | # swift build --build-tests --enable-index-store --configuration release -Xswiftc -warnings-as-errors -Xcc -Werror
18 | - name: Run Tests
19 | run: |
20 | swift test --enable-index-store --configuration release -Xswiftc -warnings-as-errors -Xcc -Werror
21 | # swift test --skip-build --enable-index-store --configuration release
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | /.build
3 | /Packages
4 | /*.xcodeproj
5 | xcuserdata/
6 | DerivedData/
7 | .swiftpm/config/registries.json
8 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
9 | .netrc
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Mochi Development, Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version: 5.6
2 | // The swift-tools-version declares the minimum version of Swift required to build this package.
3 |
4 | import PackageDescription
5 |
6 | let package = Package(
7 | name: "XCTAsync",
8 | products: [
9 | // Products define the executables and libraries a package produces, and make them visible to other packages.
10 | .library(
11 | name: "XCTAsync",
12 | targets: ["XCTAsync"]),
13 | ],
14 | dependencies: [
15 | // Dependencies declare other packages that this package depends on.
16 | // .package(url: /* package url */, from: "1.0.0"),
17 | ],
18 | targets: [
19 | // Targets are the basic building blocks of a package. A target can define a module or a test suite.
20 | // Targets can depend on other targets in this package, and on products in packages this package depends on.
21 | .target(
22 | name: "XCTAsync",
23 | dependencies: []),
24 | .testTarget(
25 | name: "XCTAsyncTests",
26 | dependencies: ["XCTAsync"]),
27 | ]
28 | )
29 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # XCTAsync
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | `XCTAsync` redefines many `XCTAssert` functions as async functions within asynchronous contexts.
16 |
17 | ## Installation
18 |
19 | Add `XCTAsync` as a dependency in your `Package.swift` file to start using it. Then, add `import XCTAssert` to any file you wish to use the library in.
20 |
21 | Please check the [releases](https://github.com/mochidev/XCTAsync/releases) for recommended versions.
22 |
23 | ```swift
24 | dependencies: [
25 | .package(url: "https://github.com/mochidev/XCTAsync.git", .upToNextMajor(from: "1.0.0")),
26 | ],
27 | ...
28 | targets: [
29 | .testTarget(
30 | name: "MyPackageTests",
31 | dependencies: [
32 | "XCTAsync",
33 | ]
34 | )
35 | ]
36 | ```
37 |
38 | ## What is `XCTAsync`?
39 |
40 | `XCTAsync` is a collection of functions for testing asynchonous code:
41 |
42 | ```swift
43 | import XCTest
44 | import XCTAsync
45 |
46 | func testAsyncMethods() async {
47 | await XCTAssertTrue(await asynchronousMethod())
48 | }
49 | ```
50 |
51 | Note that `XCTAsync` is only necessary for async methods, and will not be overloaded in synchronous contexts:
52 |
53 | ```swift
54 | import XCTest
55 | import XCTAsync
56 |
57 | func testSyncMethods() {
58 | XCTAssertTrue(synchronousMethod())
59 | }
60 | ```
61 |
62 | However, if you are in an asynchronous test, you'll need to use the asynchronous variants for each assert:
63 |
64 | ```swift
65 | import XCTest
66 | import XCTAsync
67 |
68 | func testSyncMethods() async {
69 | await XCTAssertTrue(synchronousMethod())
70 | }
71 | ```
72 |
73 | ## Contributing
74 |
75 | Contribution is welcome! Please take a look at the issues already available, or start a new issue to discuss a new feature. Although guarantees can't be made regarding feature requests, PRs that fit with the goals of the project and that have been discussed before hand are more than welcome!
76 |
77 | Please make sure that all submissions have clean commit histories, are well documented, and thoroughly tested. **Please rebase your PR** before submission rather than merge in `main`. Linear histories are required.
78 |
--------------------------------------------------------------------------------
/Sources/XCTAsync/XCTAsync.swift:
--------------------------------------------------------------------------------
1 | import XCTest
2 |
3 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
4 | @inlinable
5 | @inline(__always)
6 | func expand(_ expression: () async throws -> T) async -> () throws -> T {
7 | do {
8 | let value = try await expression()
9 | return { value }
10 | } catch {
11 | return { throw error }
12 | }
13 | }
14 |
15 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
16 | @inlinable
17 | public func XCTAssert(
18 | _ expression: @autoclosure () async throws -> Bool,
19 | _ message: @autoclosure () -> String = "",
20 | file: StaticString = #filePath,
21 | line: UInt = #line
22 | ) async {
23 | let expression = await expand(expression)
24 | try? { XCTAssert(try expression(), message(), file: file, line: line) }()
25 | }
26 |
27 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
28 | @inlinable
29 | public func XCTAssertEqual(
30 | _ expression1: @autoclosure () async throws -> T,
31 | _ expression2: @autoclosure () async throws -> T,
32 | _ message: @autoclosure () -> String = "",
33 | file: StaticString = #filePath,
34 | line: UInt = #line
35 | ) async where T : Equatable {
36 | let expression1 = await expand(expression1)
37 | let expression2 = await expand(expression2)
38 | try? { XCTAssertEqual(try expression1(), try expression2(), message(), file: file, line: line) }()
39 | }
40 |
41 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
42 | @inlinable
43 | public func XCTAssertEqual(
44 | _ expression1: @autoclosure () async throws -> T,
45 | _ expression2: @autoclosure () async throws -> T,
46 | accuracy: T,
47 | _ message: @autoclosure () -> String = "",
48 | file: StaticString = #filePath,
49 | line: UInt = #line
50 | ) async where T : FloatingPoint {
51 | let expression1 = await expand(expression1)
52 | let expression2 = await expand(expression2)
53 | try? { XCTAssertEqual(try expression1(), try expression2(), accuracy: accuracy, message(), file: file, line: line) }()
54 | }
55 |
56 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
57 | @inlinable
58 | public func XCTAssertEqual(
59 | _ expression1: @autoclosure () async throws -> T,
60 | _ expression2: @autoclosure () async throws -> T,
61 | accuracy: T,
62 | _ message: @autoclosure () -> String = "",
63 | file: StaticString = #filePath,
64 | line: UInt = #line
65 | ) async where T : Numeric {
66 | let expression1 = await expand(expression1)
67 | let expression2 = await expand(expression2)
68 | try? { XCTAssertEqual(try expression1(), try expression2(), accuracy: accuracy, message(), file: file, line: line) }()
69 | }
70 |
71 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
72 | @inlinable
73 | public func XCTAssertFalse(
74 | _ expression: @autoclosure () async throws -> Bool,
75 | _ message: @autoclosure () -> String = "",
76 | file: StaticString = #filePath,
77 | line: UInt = #line
78 | ) async {
79 | let expression = await expand(expression)
80 | try? { XCTAssertFalse(try expression(), message(), file: file, line: line) }()
81 | }
82 |
83 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
84 | @inlinable
85 | public func XCTAssertGreaterThan(
86 | _ expression1: @autoclosure () async throws -> T,
87 | _ expression2: @autoclosure () async throws -> T,
88 | _ message: @autoclosure () -> String = "",
89 | file: StaticString = #filePath,
90 | line: UInt = #line
91 | ) async where T : Comparable {
92 | let expression1 = await expand(expression1)
93 | let expression2 = await expand(expression2)
94 | try? { XCTAssertGreaterThan(try expression1(), try expression2(), message(), file: file, line: line) }()
95 | }
96 |
97 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
98 | @inlinable
99 | public func XCTAssertGreaterThanOrEqual(
100 | _ expression1: @autoclosure () async throws -> T,
101 | _ expression2: @autoclosure () async throws -> T,
102 | _ message: @autoclosure () -> String = "",
103 | file: StaticString = #filePath,
104 | line: UInt = #line
105 | ) async where T : Comparable {
106 | let expression1 = await expand(expression1)
107 | let expression2 = await expand(expression2)
108 | try? { XCTAssertGreaterThanOrEqual(try expression1(), try expression2(), message(), file: file, line: line) }()
109 | }
110 |
111 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
112 | @inlinable
113 | public func XCTAssertIdentical(
114 | _ expression1: @autoclosure () async throws -> AnyObject?,
115 | _ expression2: @autoclosure () async throws -> AnyObject?,
116 | _ message: @autoclosure () -> String = "",
117 | file: StaticString = #filePath,
118 | line: UInt = #line
119 | ) async {
120 | let expression1 = await expand(expression1)
121 | let expression2 = await expand(expression2)
122 | try? { XCTAssertIdentical(try expression1(), try expression2(), message(), file: file, line: line) }()
123 | }
124 |
125 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
126 | @inlinable
127 | public func XCTAssertLessThan(
128 | _ expression1: @autoclosure () async throws -> T,
129 | _ expression2: @autoclosure () async throws -> T,
130 | _ message: @autoclosure () -> String = "",
131 | file: StaticString = #filePath,
132 | line: UInt = #line
133 | ) async where T : Comparable {
134 | let expression1 = await expand(expression1)
135 | let expression2 = await expand(expression2)
136 | try? { XCTAssertLessThan(try expression1(), try expression2(), message(), file: file, line: line) }()
137 | }
138 |
139 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
140 | @inlinable
141 | public func XCTAssertLessThanOrEqual(
142 | _ expression1: @autoclosure () async throws -> T,
143 | _ expression2: @autoclosure () async throws -> T,
144 | _ message: @autoclosure () -> String = "",
145 | file: StaticString = #filePath,
146 | line: UInt = #line
147 | ) async where T : Comparable {
148 | let expression1 = await expand(expression1)
149 | let expression2 = await expand(expression2)
150 | try? { XCTAssertLessThanOrEqual(try expression1(), try expression2(), message(), file: file, line: line) }()
151 | }
152 |
153 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
154 | @inlinable
155 | public func XCTAssertNil(
156 | _ expression: @autoclosure () async throws -> Any?,
157 | _ message: @autoclosure () -> String = "",
158 | file: StaticString = #filePath,
159 | line: UInt = #line
160 | ) async {
161 | let expression = await expand(expression)
162 | try? { XCTAssertNil(try expression(), message(), file: file, line: line) }()
163 | }
164 |
165 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
166 | @inlinable
167 | public func XCTAssertNoThrow(
168 | _ expression: @autoclosure () async throws -> T,
169 | _ message: @autoclosure () -> String = "",
170 | file: StaticString = #filePath,
171 | line: UInt = #line
172 | ) async {
173 | let expression = await expand(expression)
174 | try? { XCTAssertNoThrow(try expression(), message(), file: file, line: line) }()
175 | }
176 |
177 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
178 | @inlinable
179 | public func XCTAssertNotEqual(
180 | _ expression1: @autoclosure () async throws -> T,
181 | _ expression2: @autoclosure () async throws -> T,
182 | _ message: @autoclosure () -> String = "",
183 | file: StaticString = #filePath,
184 | line: UInt = #line
185 | ) async where T : Equatable {
186 | let expression1 = await expand(expression1)
187 | let expression2 = await expand(expression2)
188 | try? { XCTAssertNotEqual(try expression1(), try expression2(), message(), file: file, line: line) }()
189 | }
190 |
191 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
192 | @inlinable
193 | public func XCTAssertNotEqual(
194 | _ expression1: @autoclosure () async throws -> T,
195 | _ expression2: @autoclosure () async throws -> T,
196 | accuracy: T,
197 | _ message: @autoclosure () -> String = "",
198 | file: StaticString = #filePath,
199 | line: UInt = #line
200 | ) async where T : FloatingPoint {
201 | let expression1 = await expand(expression1)
202 | let expression2 = await expand(expression2)
203 | try? { XCTAssertNotEqual(try expression1(), try expression2(), accuracy: accuracy, message(), file: file, line: line) }()
204 | }
205 |
206 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
207 | @inlinable
208 | public func XCTAssertNotEqual(
209 | _ expression1: @autoclosure () async throws -> T,
210 | _ expression2: @autoclosure () async throws -> T,
211 | accuracy: T,
212 | _ message: @autoclosure () -> String = "",
213 | file: StaticString = #filePath,
214 | line: UInt = #line
215 | ) async where T : Numeric {
216 | let expression1 = await expand(expression1)
217 | let expression2 = await expand(expression2)
218 | try? { XCTAssertNotEqual(try expression1(), try expression2(), accuracy: accuracy, message(), file: file, line: line) }()
219 | }
220 |
221 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
222 | @inlinable
223 | public func XCTAssertNotIdentical(
224 | _ expression1: @autoclosure () async throws -> AnyObject?,
225 | _ expression2: @autoclosure () async throws -> AnyObject?,
226 | _ message: @autoclosure () -> String = "",
227 | file: StaticString = #filePath,
228 | line: UInt = #line
229 | ) async {
230 | let expression1 = await expand(expression1)
231 | let expression2 = await expand(expression2)
232 | try? { XCTAssertNotIdentical(try expression1(), try expression2(), message(), file: file, line: line) }()
233 | }
234 |
235 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
236 | @inlinable
237 | public func XCTAssertNotNil(
238 | _ expression: @autoclosure () async throws -> Any?,
239 | _ message: @autoclosure () -> String = "",
240 | file: StaticString = #filePath,
241 | line: UInt = #line
242 | ) async {
243 | let expression = await expand(expression)
244 | try? { XCTAssertNotNil(try expression(), message(), file: file, line: line) }()
245 | }
246 |
247 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
248 | @inlinable
249 | public func XCTAssertThrowsError(
250 | _ expression: @autoclosure () async throws -> T,
251 | _ message: @autoclosure () -> String = "",
252 | file: StaticString = #filePath,
253 | line: UInt = #line,
254 | _ errorHandler: (_ error: Error) -> Void = { _ in }
255 | ) async {
256 | let expression = await expand(expression)
257 | try? { XCTAssertThrowsError(try expression(), message(), file: file, line: line, errorHandler) }()
258 | }
259 |
260 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
261 | @inlinable
262 | public func XCTAssertTrue(
263 | _ expression: @autoclosure () async throws -> Bool,
264 | _ message: @autoclosure () -> String = "",
265 | file: StaticString = #filePath,
266 | line: UInt = #line
267 | ) async {
268 | let expression = await expand(expression)
269 | try? { XCTAssertTrue(try expression(), message(), file: file, line: line) }()
270 | }
271 |
272 |
--------------------------------------------------------------------------------
/Tests/XCTAsyncTests/XCTAsyncTests.swift:
--------------------------------------------------------------------------------
1 | import XCTest
2 | import XCTAsync
3 |
4 | struct TestError: Error, Equatable {}
5 | class TestClass {
6 | init() {}
7 | }
8 |
9 | func sync(_ value: T) -> T { value }
10 | func syncThrows(_ value: T) throws -> T { value }
11 | func syncThrowsError(_ value: T) throws -> T { throw TestError() }
12 |
13 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
14 | func async(_ value: T) async -> T { value }
15 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
16 | func asyncThrows(_ value: T) async throws -> T { value }
17 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
18 | func asyncThrowsError(_ value: T) async throws -> T { throw TestError() }
19 |
20 | @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
21 | final class XCTAsyncTests: XCTestCase {
22 | func testAsyncAssert() async throws {
23 | await XCTAssert(sync(true))
24 | await XCTAssert(await async(true))
25 | await XCTAssert(true)
26 | await XCTAssert(try syncThrows(true))
27 | await XCTAssert(try await asyncThrows(true))
28 | }
29 |
30 | func testSyncAssert() throws {
31 | XCTAssert(sync(true))
32 | XCTAssert(true)
33 | XCTAssert(try syncThrows(true))
34 | }
35 |
36 | func testAsyncAssertEqual() async {
37 | await XCTAssertEqual(sync(true), sync(true))
38 | await XCTAssertEqual(await async(true), await async(true))
39 | await XCTAssertEqual(true, true)
40 | await XCTAssertEqual(try syncThrows(true), try syncThrows(true))
41 | await XCTAssertEqual(try await asyncThrows(true), try await asyncThrows(true))
42 | }
43 |
44 | func testSyncAssertEqual() {
45 | XCTAssertEqual(sync(true), sync(true))
46 | XCTAssertEqual(true, true)
47 | XCTAssertEqual(try syncThrows(true), try syncThrows(true))
48 | }
49 |
50 | func testAsyncAssertEqualAccuracy() async {
51 | await XCTAssertEqual(sync(3.14), sync(3.14), accuracy: 0.01)
52 | await XCTAssertEqual(await async(3.14), await async(3.14), accuracy: 0.01)
53 | await XCTAssertEqual(3.14, 3.14, accuracy: 0.01)
54 | await XCTAssertEqual(try syncThrows(3.14), try syncThrows(3.14), accuracy: 0.01)
55 | await XCTAssertEqual(try await asyncThrows(3.14), try await asyncThrows(3.14), accuracy: 0.01)
56 | }
57 |
58 | func testSyncAssertEqualAccuracy() {
59 | XCTAssertEqual(sync(3.14), sync(3.14), accuracy: 0.01)
60 | XCTAssertEqual(3.14, 3.14, accuracy: 0.01)
61 | XCTAssertEqual(try syncThrows(3.14), try syncThrows(3.14), accuracy: 0.01)
62 | }
63 |
64 | func testAsyncAssertFalse() async throws {
65 | await XCTAssertFalse(sync(false))
66 | await XCTAssertFalse(await async(false))
67 | await XCTAssertFalse(false)
68 | await XCTAssertFalse(try syncThrows(false))
69 | await XCTAssertFalse(try await asyncThrows(false))
70 | }
71 |
72 | func testSyncAssertFalse() throws {
73 | XCTAssertFalse(sync(false))
74 | XCTAssertFalse(false)
75 | XCTAssertFalse(try syncThrows(false))
76 | }
77 |
78 | func testAsyncAssertGreaterThan() async {
79 | await XCTAssertGreaterThan(sync(5), sync(2))
80 | await XCTAssertGreaterThan(await async(5), await async(2))
81 | await XCTAssertGreaterThan(5, 2)
82 | await XCTAssertGreaterThan(try syncThrows(5), try syncThrows(2))
83 | await XCTAssertGreaterThan(try await asyncThrows(5), try await asyncThrows(2))
84 | }
85 |
86 | func testSyncAssertGreaterThan() {
87 | XCTAssertGreaterThan(sync(5), sync(2))
88 | XCTAssertGreaterThan(5, 2)
89 | XCTAssertGreaterThan(try syncThrows(5), try syncThrows(2))
90 | }
91 |
92 | func testAsyncAssertGreaterThanOrEqual() async {
93 | await XCTAssertGreaterThanOrEqual(sync(5), sync(2))
94 | await XCTAssertGreaterThanOrEqual(await async(5), await async(2))
95 | await XCTAssertGreaterThanOrEqual(5, 2)
96 | await XCTAssertGreaterThanOrEqual(try syncThrows(5), try syncThrows(2))
97 | await XCTAssertGreaterThanOrEqual(try await asyncThrows(5), try await asyncThrows(2))
98 | }
99 |
100 | func testSyncAssertGreaterThanOrEqual() {
101 | XCTAssertGreaterThanOrEqual(sync(5), sync(2))
102 | XCTAssertGreaterThanOrEqual(5, 2)
103 | XCTAssertGreaterThanOrEqual(try syncThrows(5), try syncThrows(2))
104 | }
105 |
106 | func testAsyncAssertIdentical() async {
107 | let object = TestClass()
108 | await XCTAssertIdentical(sync(object), sync(object))
109 | await XCTAssertIdentical(await async(object), await async(object))
110 | await XCTAssertIdentical(object, object)
111 | await XCTAssertIdentical(try syncThrows(object), try syncThrows(object))
112 | await XCTAssertIdentical(try await asyncThrows(object), try await asyncThrows(object))
113 | }
114 |
115 | func testSyncAssertIdentical() {
116 | let object = TestClass()
117 | XCTAssertIdentical(sync(object), sync(object))
118 | XCTAssertIdentical(object, object)
119 | XCTAssertIdentical(try syncThrows(object), try syncThrows(object))
120 | }
121 |
122 | func testAsyncAssertLessThan() async {
123 | await XCTAssertLessThan(sync(5), sync(7))
124 | await XCTAssertLessThan(await async(5), await async(7))
125 | await XCTAssertLessThan(5, 7)
126 | await XCTAssertLessThan(try syncThrows(5), try syncThrows(7))
127 | await XCTAssertLessThan(try await asyncThrows(5), try await asyncThrows(7))
128 | }
129 |
130 | func testSyncAssertLessThan() {
131 | XCTAssertLessThan(sync(5), sync(7))
132 | XCTAssertLessThan(5, 7)
133 | XCTAssertLessThan(try syncThrows(5), try syncThrows(7))
134 | }
135 |
136 | func testAsyncAssertLessThanOrEqual() async {
137 | await XCTAssertLessThanOrEqual(sync(5), sync(7))
138 | await XCTAssertLessThanOrEqual(await async(5), await async(7))
139 | await XCTAssertLessThanOrEqual(5, 7)
140 | await XCTAssertLessThanOrEqual(try syncThrows(5), try syncThrows(7))
141 | await XCTAssertLessThanOrEqual(try await asyncThrows(5), try await asyncThrows(7))
142 | }
143 |
144 | func testSyncAssertLessThanOrEqual() {
145 | XCTAssertLessThanOrEqual(sync(5), sync(7))
146 | XCTAssertLessThanOrEqual(5, 7)
147 | XCTAssertLessThanOrEqual(try syncThrows(5), try syncThrows(7))
148 | }
149 |
150 | func testAsyncAssertNil() async throws {
151 | let optional: Int? = nil
152 | await XCTAssertNil(sync(optional))
153 | await XCTAssertNil(await async(optional))
154 | await XCTAssertNil(optional)
155 | await XCTAssertNil(try syncThrows(optional))
156 | await XCTAssertNil(try await asyncThrows(optional))
157 | }
158 |
159 | func testSyncAssertNil() throws {
160 | let optional: Int? = nil
161 | XCTAssertNil(sync(optional))
162 | XCTAssertNil(optional)
163 | XCTAssertNil(try syncThrows(optional))
164 | }
165 |
166 | func testAsyncAssertNoThrow() async throws {
167 | await XCTAssertNoThrow(sync(1))
168 | await XCTAssertNoThrow(await async(1))
169 | await XCTAssertNoThrow(1)
170 | await XCTAssertNoThrow(try syncThrows(1))
171 | await XCTAssertNoThrow(try await asyncThrows(1))
172 | }
173 |
174 | func testSyncAssertNoThrow() throws {
175 | XCTAssertNoThrow(sync(1))
176 | XCTAssertNoThrow(1)
177 | XCTAssertNoThrow(try syncThrows(1))
178 | }
179 |
180 | func testAsyncAssertNotEqual() async {
181 | await XCTAssertNotEqual(sync(true), sync(false))
182 | await XCTAssertNotEqual(await async(true), await async(false))
183 | await XCTAssertNotEqual(true, false)
184 | await XCTAssertNotEqual(try syncThrows(true), try syncThrows(false))
185 | await XCTAssertNotEqual(try await asyncThrows(true), try await asyncThrows(false))
186 | }
187 |
188 | func testSyncAssertNotEqual() {
189 | XCTAssertNotEqual(sync(true), sync(false))
190 | XCTAssertNotEqual(true, false)
191 | XCTAssertNotEqual(try syncThrows(true), try syncThrows(false))
192 | }
193 |
194 | func testAsyncAssertNotEqualAccuracy() async {
195 | await XCTAssertNotEqual(sync(3.14), sync(6.28), accuracy: 0.01)
196 | await XCTAssertNotEqual(await async(3.14), await async(6.28), accuracy: 0.01)
197 | await XCTAssertNotEqual(3.14, 6.28, accuracy: 0.01)
198 | await XCTAssertNotEqual(try syncThrows(3.14), try syncThrows(6.28), accuracy: 0.01)
199 | await XCTAssertNotEqual(try await asyncThrows(3.14), try await asyncThrows(6.28), accuracy: 0.01)
200 | }
201 |
202 | func testSyncAssertEqualNotAccuracy() {
203 | XCTAssertNotEqual(sync(3.14), sync(6.28), accuracy: 0.01)
204 | XCTAssertNotEqual(3.14, 6.28, accuracy: 0.01)
205 | XCTAssertNotEqual(try syncThrows(3.14), try syncThrows(6.28), accuracy: 0.01)
206 | }
207 |
208 | func testAsyncAssertNotIdentical() async {
209 | let objectA = TestClass()
210 | let objectB = TestClass()
211 | await XCTAssertNotIdentical(sync(objectA), sync(objectB))
212 | await XCTAssertNotIdentical(await async(objectA), await async(objectB))
213 | await XCTAssertNotIdentical(objectA, objectB)
214 | await XCTAssertNotIdentical(try syncThrows(objectA), try syncThrows(objectB))
215 | await XCTAssertNotIdentical(try await asyncThrows(objectA), try await asyncThrows(objectB))
216 | }
217 |
218 | func testSyncAssertNotIdentical() {
219 | let objectA = TestClass()
220 | let objectB = TestClass()
221 | XCTAssertNotIdentical(sync(objectA), sync(objectB))
222 | XCTAssertNotIdentical(objectA, objectB)
223 | XCTAssertNotIdentical(try syncThrows(objectA), try syncThrows(objectB))
224 | }
225 |
226 | func testAsyncAssertNotNil() async throws {
227 | let optional: Int? = 1
228 | await XCTAssertNotNil(sync(optional))
229 | await XCTAssertNotNil(await async(optional))
230 | await XCTAssertNotNil(optional)
231 | await XCTAssertNotNil(try syncThrows(optional))
232 | await XCTAssertNotNil(try await asyncThrows(optional))
233 | }
234 |
235 | func testSyncAssertNotNil() throws {
236 | let optional: Int? = 1
237 | XCTAssertNotNil(sync(optional))
238 | XCTAssertNotNil(optional)
239 | XCTAssertNotNil(try syncThrows(optional))
240 | }
241 |
242 | func testAsyncAssertThrowsError() async throws {
243 | await XCTAssertThrowsError(try syncThrowsError(true))
244 | await XCTAssertThrowsError(try await asyncThrowsError(true))
245 | }
246 |
247 | func testSyncAssertThrowsError() throws {
248 | XCTAssertThrowsError(try syncThrowsError(true))
249 | }
250 |
251 | func testAsyncAssertTrue() async throws {
252 | await XCTAssertTrue(sync(true))
253 | await XCTAssertTrue(await async(true))
254 | await XCTAssertTrue(true)
255 | await XCTAssertTrue(try syncThrows(true))
256 | await XCTAssertTrue(try await asyncThrows(true))
257 | }
258 |
259 | func testSyncAssertTrue() throws {
260 | XCTAssertTrue(sync(true))
261 | XCTAssertTrue(true)
262 | XCTAssertTrue(try syncThrows(true))
263 | }
264 | }
265 |
--------------------------------------------------------------------------------