Is it possible to assert a case of error in HUnit?

If I have a function that causes an error for a specific input, can I write a test confirming that an error occurs for this input?

I do not find this "assert error" function available in HUnit . Is this available in HUnit or perhaps in some other test suite?

+4
source share
1 answer

You can catch the error and approve if this does not happen using standard exception handling:

errored <- catch (somethingThatErrors >> pure False) handler
if errored then
    assertFailure "Did not catch expected error"
else
    pure ()
where
   handler :: ErrorCall -> IO Bool
   handler _ = pure True
+4
source

Source: https://habr.com/ru/post/1686069/


All Articles