Avatar
@swift-5.2.5 import XCTest extension String: Error {} func XCTAssertResultSuccess<T, E>(_ actual: Result<T, E>, _ expect: (T) -> Bool, file: StaticString = #file, line: UInt = #line) { switch actual { case .success(let value): XCTAssertTrue(expect(value), file: file, line: line) case .failure(let error): XCTFail("Unexpected failure: \(error)", file: file, line: line) } } func XCTAssertResultFailure<T, E>(_ actual: Result<T, E>, _ expect: (E) -> Bool, file: StaticString = #file, line: UInt = #line) { switch actual { case .success(let value): XCTFail("Unexpected success: \(value)") case .failure(let error): XCTAssertTrue(expect(error), file: file, line: line) } } XCTAssertResultSuccess(Result<Int, Error>.success(1), { $0 == 1 }) XCTAssertResultFailure(Result<Int, Error>.failure("error"), { $0 is String })