| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Test.ImpSpec.Expectations
Synopsis
- assertBool :: HasCallStack => String -> Bool -> Assertion
- assertFailure :: HasCallStack => String -> IO a
- expectationFailure :: HasCallStack => String -> Expectation
- shouldBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation
- shouldSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
- shouldStartWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldEndWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldMatchList :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
- shouldNotBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation
- shouldNotSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
- shouldNotContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldNotReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
- shouldThrow :: (HasCallStack, Exception e) => IO a -> Selector e -> Expectation
- type Selector a = a -> Bool
- assertColorFailure :: HasCallStack => String -> IO a
- shouldBeRight :: (HasCallStack, Show a, Show b, Eq b) => Either a b -> b -> Expectation
- shouldBeLeft :: (HasCallStack, Show a, Eq a, Show b) => Either a b -> a -> Expectation
- expectRight :: (HasCallStack, Show a) => Either a b -> IO b
- expectRightDeep :: (HasCallStack, Show a, NFData b) => Either a b -> IO b
- expectRightDeep_ :: (HasCallStack, Show a, NFData b) => Either a b -> IO ()
- expectLeft :: (HasCallStack, Show b) => Either a b -> IO a
- expectLeftDeep :: (HasCallStack, NFData a, Show b) => Either a b -> IO a
- expectLeftDeep_ :: (HasCallStack, NFData a, Show b) => Either a b -> IO ()
- shouldBeJust :: (HasCallStack, Show a, Eq a) => Maybe a -> a -> Expectation
- expectJust :: HasCallStack => Maybe a -> IO a
- expectJustDeep :: (HasCallStack, NFData a) => Maybe a -> IO a
- expectJustDeep_ :: (HasCallStack, NFData a) => Maybe a -> IO ()
- expectNothing :: (HasCallStack, Show a) => Maybe a -> IO ()
- callStackToLocation :: CallStack -> Maybe Location
- srcLocToLocation :: SrcLoc -> Location
Expectations
Common
Arguments
| :: HasCallStack | |
| => String | The message that is displayed if the assertion fails |
| -> Bool | The condition |
| -> Assertion |
Asserts that the specified condition holds.
Arguments
| :: HasCallStack | |
| => String | A message that is displayed with the assertion failure |
| -> IO a |
Unconditionally signals that a failure has occurred.
expectationFailure :: HasCallStack => String -> Expectation #
shouldBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation infix 1 #
actual `shouldBe` expected sets the expectation that actual is equal
to expected.
shouldSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation infix 1 #
v `shouldSatisfy` p sets the expectation that p v is True.
shouldStartWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
list `shouldStartWith` prefix sets the expectation that list starts with prefix,
shouldEndWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
list `shouldEndWith` suffix sets the expectation that list ends with suffix,
shouldContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
list `shouldContain` sublist sets the expectation that sublist is contained,
wholly and intact, anywhere in list.
shouldMatchList :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
xs `shouldMatchList` ys sets the expectation that xs has the same
elements that ys has, possibly in another order
shouldReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation infix 1 #
action `shouldReturn` expected sets the expectation that action
returns expected.
shouldNotBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation infix 1 #
actual `shouldNotBe` notExpected sets the expectation that actual is not
equal to notExpected
shouldNotSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation infix 1 #
v `shouldNotSatisfy` p sets the expectation that p v is False.
shouldNotContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
list `shouldNotContain` sublist sets the expectation that sublist is not
contained anywhere in list.
shouldNotReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation infix 1 #
action `shouldNotReturn` notExpected sets the expectation that action
does not return notExpected.
shouldThrow :: (HasCallStack, Exception e) => IO a -> Selector e -> Expectation infix 1 #
action `shouldThrow` selector sets the expectation that action throws
an exception. The precise nature of the expected exception is described
with a Selector.
A Selector is a predicate; it can simultaneously constrain the type and
value of an exception.
Custom
assertColorFailure :: HasCallStack => String -> IO a Source #
Similar to assertFailure, except hspec will not interfer with any escape sequences
that indicate color output.
Either
shouldBeRight :: (HasCallStack, Show a, Show b, Eq b) => Either a b -> b -> Expectation infix 1 Source #
shouldBeLeft :: (HasCallStack, Show a, Eq a, Show b) => Either a b -> a -> Expectation infix 1 Source #
expectRight :: (HasCallStack, Show a) => Either a b -> IO b Source #
Return value on the Right and fail otherwise.
Difference from in that shouldSatisfy action isRightexpectRight
will force the content of the Right to WHNF and return it. This expectation will also
show the content of the Left when expectation fails.
expectRightDeep :: (HasCallStack, Show a, NFData b) => Either a b -> IO b Source #
Same as expectRight, but also evaluate the returned value to NF
expectRightDeep_ :: (HasCallStack, Show a, NFData b) => Either a b -> IO () Source #
Same as expectRightDeep, but discards the result
expectLeft :: (HasCallStack, Show b) => Either a b -> IO a Source #
Return value on the Left an fail otherwise
Difference from in that shouldSatisfy action isLeftexpectLeft will
force the content of the Left to WHNF and and return it. This expectation will also
show the content of the Right when expectation fails.
expectLeftDeep :: (HasCallStack, NFData a, Show b) => Either a b -> IO a Source #
Same as expectLeft, but also evaluate the returned value to NF
expectLeftDeep_ :: (HasCallStack, NFData a, Show b) => Either a b -> IO () Source #
Same as expectLeftDeep, but discards the result
Maybe
shouldBeJust :: (HasCallStack, Show a, Eq a) => Maybe a -> a -> Expectation Source #
expectJust :: HasCallStack => Maybe a -> IO a Source #
Return value from the Just an fail otherwise
Difference from in that shouldSatisfy action isJustexpectJust will force the
content of the Just to WHNF and it will also return it.
expectJustDeep :: (HasCallStack, NFData a) => Maybe a -> IO a Source #
Same as expectJust, but will force the value to NF
expectJustDeep_ :: (HasCallStack, NFData a) => Maybe a -> IO () Source #
Same as expectJustDeep, but will discard the forced contents of Just
expectNothing :: (HasCallStack, Show a) => Maybe a -> IO () Source #
Same as shouldSatisfy action isNothing