sandwich-0.2.2.0: Yet another test framework for Haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Sandwich.Expectations

Description

Functions for making assertions about test behavior.

Synopsis

Manually fail a test or mark as pending

expectationFailure :: (HasCallStack, MonadThrow m) => String -> m a Source #

General-purpose function to throw a test exception with a String.

pending :: (HasCallStack, MonadThrow m) => m a Source #

Throws a Pending exception, which will cause the test to be marked as pending.

pendingWith :: (HasCallStack, MonadThrow m) => String -> m a Source #

Throws a Pending exception with a message to add additional details.

xit :: (HasCallStack, Monad m, MonadThrow m) => String -> ExampleT context m1 () -> SpecFree context m () Source #

Shorthand for a pending test example. You can quickly mark an it node as pending by putting an "x" in front of it.

Expecting failures

shouldFail :: (HasCallStack, MonadCatch m, MonadThrow m) => m () -> m () Source #

Assert that a given action should fail with some FailureReason.

shouldFailPredicate :: (HasCallStack, MonadCatch m, MonadThrow m) => (FailureReason -> Bool) -> m () -> m () Source #

Assert that a given action should fail with some FailureReason matching a predicate.

shouldThrow Source #

Arguments

:: (HasCallStack, MonadThrow m, MonadCatch m, MonadIO m, Exception e) 
=> m a

The action to run.

-> (e -> Bool)

A predicate on the exception to determine if it's as expected.

-> m () 

Asserts that an action should throw an exception. Accepts a predicate to determine if the exception matches.

Assertions

shouldBe :: (HasCallStack, MonadThrow m, Eq a, Show a) => a -> a -> m () Source #

Asserts that two things are equal.

shouldNotBe :: (HasCallStack, MonadThrow m, Eq a, Show a) => a -> a -> m () Source #

Asserts that two things are not equal.

shouldContain :: (HasCallStack, MonadThrow m, Eq a, Show a) => [a] -> [a] -> m () Source #

Asserts that the given list contains a subsequence.

shouldContainPredicate :: (HasCallStack, MonadThrow m, Eq a, Show a) => [a] -> (a -> Bool) -> m () Source #

Asserts that the given list contains an item matching a predicate.

shouldNotContain :: (HasCallStack, MonadThrow m, Eq a, Show a) => [a] -> [a] -> m () Source #

Asserts that the given list does not contain a subsequence.

shouldNotContainPredicate :: (HasCallStack, MonadThrow m, Eq a, Show a) => [a] -> (a -> Bool) -> m () Source #

Asserts that the given list contains an item matching a predicate.

shouldBeNothing :: (HasCallStack, MonadThrow m, Show a) => Maybe a -> m () Source #

Asserts that the given Maybe is Nothing.

shouldBeJust :: (HasCallStack, MonadThrow m, Show a) => Maybe a -> m () Source #

Asserts that the given Maybe is Just.

shouldBeLeft :: (HasCallStack, MonadThrow m, Show a, Show b) => Either a b -> m () Source #

Asserts that the given Either is Left.

shouldBeRight :: (HasCallStack, MonadThrow m, Show a, Show b) => Either a b -> m () Source #

Asserts that the given Either is Right.

textShouldContain :: (HasCallStack, MonadThrow m) => Text -> Text -> m () Source #

Asserts that the given text contains a substring.

textShouldNotContain :: (HasCallStack, MonadThrow m) => Text -> Text -> m () Source #

Asserts that the given text does not contain a substring.