Skip to content

Commit 4eaaf32

Browse files
committed
removes throws from waitForExpectations
* disables swiftSettings from targets due to unsafe settings * removes `try` from all of the tests for the wait calls
1 parent e6536bd commit 4eaaf32

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ let package = Package(
2424
.target(
2525
name: "AsyncTesting",
2626
dependencies: [],
27-
swiftSettings: swiftSettings,
27+
swiftSettings: nil,
2828
linkerSettings: [.linkedFramework("XCTest")]
2929
),
3030
.testTarget(
3131
name: "AsyncTestingTests",
3232
dependencies: ["AsyncTesting"],
33-
swiftSettings: swiftSettings
33+
swiftSettings: nil
3434
),
3535
]
3636
)

Sources/AsyncTesting/AsyncTesting.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ public enum AsyncTesting {
1111
expectedFulfillmentCount: expectedFulfillmentCount)
1212
}
1313

14-
1514
@MainActor
1615
public static func waitForExpectations(_ expectations: [AsyncExpectation],
1716
timeout: Double = 1.0,
1817
file: StaticString = #filePath,
19-
line: UInt = #line) async throws {
18+
line: UInt = #line) async {
2019
guard !expectations.isEmpty else { return }
2120

2221
// check if all expectations are already satisfied and skip sleeping
@@ -37,16 +36,16 @@ public enum AsyncTesting {
3736
}
3837
}
3938

40-
try await waitUsingTaskGroup(expectations)
39+
await waitUsingTaskGroup(expectations)
4140

4241
timeout.cancel()
4342
}
4443

45-
private static func waitUsingTaskGroup(_ expectations: [AsyncExpectation]) async throws {
46-
await withThrowingTaskGroup(of: Void.self) { group in
44+
private static func waitUsingTaskGroup(_ expectations: [AsyncExpectation]) async {
45+
await withTaskGroup(of: Void.self) { group in
4746
for exp in expectations {
4847
group.addTask {
49-
try await exp.wait()
48+
try? await exp.wait()
5049
}
5150
}
5251
}

Sources/AsyncTesting/XCTestCase+AsyncTesting.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extension XCTestCase {
77
///
88
/// Use this method to create ``AsyncExpectation`` instances that can be
99
/// fulfilled when asynchronous tasks in your tests complete.
10-
///
10+
///
1111
/// To fulfill an expectation that was created with `asyncExpectation(description:)`,
1212
/// call the expectation's `fulfill()` method when the asynchronous task in your
1313
/// test has completed.
@@ -32,11 +32,11 @@ extension XCTestCase {
3232
public func waitForExpectations(_ expectations: [AsyncExpectation],
3333
timeout: Double = 1.0,
3434
file: StaticString = #filePath,
35-
line: UInt = #line) async throws {
36-
try await AsyncTesting.waitForExpectations(expectations,
37-
timeout: timeout,
38-
file: file,
39-
line: line)
35+
line: UInt = #line) async {
36+
await AsyncTesting.waitForExpectations(expectations,
37+
timeout: timeout,
38+
file: file,
39+
line: line)
4040
}
4141

4242
}

Tests/AsyncTestingTests/AsyncTestingTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class AsyncExpectationTests: XCTestCase {
4343
try await Task.sleep(seconds: delay)
4444
await done.fulfill()
4545
}
46-
try await waitForExpectations([done])
46+
await waitForExpectations([done])
4747
}
4848

4949
func testDoneMultipleTimesExpectation() async throws {
@@ -61,7 +61,7 @@ final class AsyncExpectationTests: XCTestCase {
6161
try await Task.sleep(seconds: delay)
6262
await done.fulfill()
6363
}
64-
try await waitForExpectations([done])
64+
await waitForExpectations([done])
6565
}
6666

6767
func testNotDoneInvertedExpectation() async throws {
@@ -73,7 +73,7 @@ final class AsyncExpectationTests: XCTestCase {
7373
}
7474
// cancel immediately to prevent fulfill from being run
7575
task.cancel()
76-
try await waitForExpectations([notDone], timeout: delay * 2)
76+
await waitForExpectations([notDone], timeout: delay * 2)
7777
}
7878

7979
func testNotYetDoneAndThenDoneExpectation() async throws {
@@ -88,9 +88,9 @@ final class AsyncExpectationTests: XCTestCase {
8888
await done.fulfill() // will be called after cancellation
8989
}
9090

91-
try await waitForExpectations([notYetDone], timeout: delay)
91+
await waitForExpectations([notYetDone], timeout: delay)
9292
task.cancel()
93-
try await waitForExpectations([done])
93+
await waitForExpectations([done])
9494
}
9595

9696
func testDoneAndNotDoneInvertedExpectation() async throws {
@@ -107,8 +107,8 @@ final class AsyncExpectationTests: XCTestCase {
107107
// cancel immediately to prevent fulfill from being run
108108
task.cancel()
109109
}
110-
try await waitForExpectations([notDone], timeout: delay * 2)
111-
try await waitForExpectations([done])
110+
await waitForExpectations([notDone], timeout: delay * 2)
111+
await waitForExpectations([done])
112112
}
113113

114114
func testMultipleFulfilledExpectation() async throws {
@@ -128,7 +128,7 @@ final class AsyncExpectationTests: XCTestCase {
128128
try await Task.sleep(seconds: delay)
129129
await three.fulfill()
130130
}
131-
try await waitForExpectations([one, two, three])
131+
await waitForExpectations([one, two, three])
132132
}
133133

134134
func testMultipleAlreadyFulfilledExpectation() async throws {
@@ -139,7 +139,7 @@ final class AsyncExpectationTests: XCTestCase {
139139
await two.fulfill()
140140
await three.fulfill()
141141

142-
try await waitForExpectations([one, two, three])
142+
await waitForExpectations([one, two, three])
143143
}
144144

145145
}

0 commit comments

Comments
 (0)