It looks like XCTest is missing some basic support for testing if a function throws or not. Here are two snippets that I'm using until that support is added.
func XCTAssertDoesNotThrow(@autoclosure fn: () throws -> (), message: String = "", file: String = __FILE__, line: UInt = __LINE__) {
do {
try fn()
}
catch {
XCTFail(message, file: file, line: line)
}
}
func XCTAssertDoesThrow(@autoclosure fn: () throws -> (), message: String = "", file: String = __FILE__, line: UInt = __LINE__) {
do {
try fn()
XCTFail(message, file: file, line: line)
}
catch {
}
}
I'm not sure how to extend this to validating for a specific error though…
Using it in a test is pretty easy:
func f() throws {
}
func someTest() {
XCTAssertDoesNotThrow(try f())
}