assert- Helpers for Control.Exception.assert

Safe HaskellNone




newtype Arse Source

A distict Exception from AssertionFailed, so that we stop fudging the exception message after the first mapException.

The name comes from abbreviating ‘assert’ and translating the result to my native tongue.


Arse String 

assertMessage :: String -> String -> (a -> a) -> a -> aSource

Generic helper for assert that includes a descriptive message to the AssertFailure exception if thrown. Use this to build your own assert helpers, such as byOrd. A rule is included which rewrites assertMessage to id when compiling with -fignore-asserts.

byEq :: (Eq x, Show x) => (Bool -> a -> a) -> String -> x -> x -> a -> aSource

Assert that two values are equal.

>>> byEq assert "Bool" False True ()
*** Exception: … Assertion failed "Bool", False ≠ True

byOrd :: (Ord x, Show x) => (Bool -> a -> a) -> String -> Ordering -> x -> x -> a -> aSource

Assert that two values obey the given Ordering.

>>> byOrd assert "Int" LT 0 1 ()

byPred :: Show x => (Bool -> a -> a) -> String -> (x -> Bool) -> x -> a -> aSource

Assert that a value satisfies the given predicate.

>>> byPred assert "Odd" odd 4 ()
*** Exception: … Assertion failed "Odd", 4

assert :: Bool -> a -> a

