Really ioProperty
is the key to this type of test. You will need to use it in combination with catch
or try
. Here I show the last:
prop_exceptional :: Int -> Property
prop_exceptional n = ioProperty $ do
result <- try . evaluate $ myDangerousFunction n
return $ r === result
where r | n == 0 = Left MyException
| otherwise = Right 42
, myDangerousFunction
MyException
, 0
42
. evaluate
, IO
, .