test-shouldbe-0.1.0: Catchy combinators for HUnit

Safe HaskellSafe-Infered




Introductory documentation: https://github.com/sol/test-shouldbe#readme


Making assertions

shouldBe :: (Show a, Eq a) => a -> a -> AssertionSource

actual `shouldBe` expected asserts that actual is equal to expected (this is just an alias for @?=).

shouldSatisfy :: Show a => a -> (a -> Bool) -> AssertionSource

v `shouldSatisfy` p asserts that p v is True.

Checking for exceptions

shouldThrow :: Exception e => IO a -> Selector e -> AssertionSource

action `shouldThrow` selector asserts that action throws an exception. The precise nature of that exception is described with a Selector.

Selecting exceptions

type Selector a = a -> BoolSource

A Selector is a predicate; it can simultaneously constrain the type and value of an exception.

Predefined type-based selectors

There are predefined selectors for some standard exceptions. Each selector is just const True with an appropriate type.

Combinators for defining value-based selectors

Some exceptions (most prominently ErrorCall) have no Eq instance. Selecting a specific value would require pattern matching.

For such exceptions, combinators that construct selectors are provided. Each combinator corresponds to a constructor; it takes the same arguments, and has the same name (but starting with a lower-case letter).