apple / swift-nio-http2

HTTP/2 support for SwiftNIO
https://swiftpackageindex.com/apple/swift-nio-http2/main/documentation/niohttp2
Apache License 2.0
465 stars 82 forks source link

get rid of `do { ... } catch { ... }` for expected errors #190

Closed weissi closed 4 years ago

weissi commented 4 years ago

The

do {
    try someOperation()
XCTFail("should throw") // easy to forget
} catch error as SomethingError {
    XCTAssertEqual(.something, error as? SomethingError)
} catch {
    XCTFail("wrong error")
}

pattern is not only very long, it's also very error prone. If you forget any of the XCTFails, you might not tests what it looks like

XCTAssertThrowsError(try someOperation) { error in
    XCTAssertEqual(.something, error as? SomethingError)
}

is much safer and shorter.

We should replace all uses of this pattern in Tests/**.

See also https://github.com/apple/swift-nio/pull/1430 which does the same for swift-nio.

weissi commented 4 years ago

see also: