Sorry if this is the wrong place to ask this... is there any preferred idiom for testing code that should throw an exception using SwiftCheck?
For example, I have the following pair of tests, and I'd like to make the second one less verbose if possible:
property("UInt values generate valid values") <- forAll { (number: UInt) -> Testable in
return try! String(number).parseAsConditionalUInt(forElement: "element") == ConditionalUInt.uint(value: number)
}
property("Negative values cause exception") <- forAll { (number: Int) -> Testable in
(number < 0) ==> {
do {
let _ = try String(number).parseAsConditionalUInt(forElement: "element")
return false
} catch {
return error is ParseError<String>
}
}
}
Sorry if this is the wrong place to ask this... is there any preferred idiom for testing code that should throw an exception using SwiftCheck?
For example, I have the following pair of tests, and I'd like to make the second one less verbose if possible: