Skip to content

Commit

Permalink
Fixed AsyncAssertThrowsError(_:_:_:) would not execute the error ha…
Browse files Browse the repository at this point in the history
…ndler closure in case the evaluated expression throws an error.
  • Loading branch information
angu committed Aug 15, 2023
1 parent 731bf8c commit 1ff2f95
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## HEAD

* Fixed `AsyncAssertThrowsError(_:_:_:)` would not execute the error handler closure in case the evaluated expression throws an error.

## 1.0.0

Initial release
Expand All @@ -25,5 +27,5 @@ Contains the following assert methods
* `AsyncAssertNotIdentical(_:_:_:)`
* `AsyncAssertNil(_:_:)`
* `AsyncAssertNotNil(_:_:)`
* `AsyncAssertThrowsError(_:_:)`
* `AsyncAssertThrowsError(_:_:_:)`
* `AsyncAssertNoThrow(_:_:)`
4 changes: 2 additions & 2 deletions Sources/SwiftAsyncAssert/SwiftAsyncAssert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ public func AsyncAssertNotNil(_ expression: @autoclosure () async throws -> Any?
public func AsyncAssertThrowsError<T>(_ expression: @autoclosure () async throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, line: UInt = #line, _ errorHandler: (_ error: Error) -> Void = { _ in }) async {
do {
let _ = try await expression()
XCTAssertThrowsError({}(), message(), file: file, line: line)
XCTAssertThrowsError({}(), message(), file: file, line: line, errorHandler)
} catch {
XCTAssertThrowsError(try { throw error }(), message(), file: file, line: line)
XCTAssertThrowsError(try { throw error }(), message(), file: file, line: line, errorHandler)
}
}

Expand Down
4 changes: 4 additions & 0 deletions Tests/SwiftAsyncAssertTests/SwiftAsyncAssertTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@ final class SwiftAsyncAssertTests: XCTestCase {
}

func test_should_pass_AsyncAssertThrows() async throws {
var isErrorHandlerCalled = false
await AsyncAssertThrowsError(try await throwingExpr { throw TestingError.systemFailedToWork }) { error in
XCTAssertEqual(error as? TestingError, .systemFailedToWork)
isErrorHandlerCalled = true
}

XCTAssertTrue(isErrorHandlerCalled)
}

func test_should_pass_AsyncAssertNotThrows() async throws {
Expand Down

0 comments on commit 1ff2f95

Please sign in to comment.