HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulehspec-expectations-0.8.4Haskell2010

Test.Hspec.Expectations.Contrib

Experimental combinators, that may become part of the main distribution, if they turn out to be useful for a wider audience.

  • 3 values

Predicates

2 declarations

(useful in combination with shouldSatisfy)

valueisLeft :: Either a b -> Bool
#

Return True if the given value is a Left-value, False otherwise.

Examples

Basic usage:

Example2 expressions
isLeft (Left "foo")TrueisLeft (Right 3)False

Assuming a Left value signifies some sort of error, we can use isLeft to write a very simple error-reporting function that does absolutely nothing in the case of success, and outputs "ERROR" if any error occurred.

This example shows how isLeft might be used to avoid pattern matching when one does not care about the value contained in the constructor:

Example4 expressions
import Control.Monad ( when )let report e = when (isLeft e) $ putStrLn "ERROR"report (Right 1)report (Left "parse error")ERROR
valueisRight :: Either a b -> Bool
#

Return True if the given value is a Right-value, False otherwise.

Examples

Basic usage:

Example2 expressions
isRight (Left "foo")FalseisRight (Right 3)True

Assuming a Left value signifies some sort of error, we can use isRight to write a very simple reporting function that only outputs "SUCCESS" when a computation has succeeded.

This example shows how isRight might be used to avoid pattern matching when one does not care about the value contained in the constructor:

Example4 expressions
import Control.Monad ( when )let report e = when (isRight e) $ putStrLn "SUCCESS"report (Left "parse error")report (Right 1)SUCCESS

Annotating expectations

1 declaration
valueannotate :: String -> IO a -> IO a
#

If you have a test case that has multiple assertions, you can use the annotate function to provide a string message that will be attached to the Expectation.

describe "annotate" $ do
  it "adds the message" $ do
    annotate "obvious falsehood" $ do
      True shouldBe False

========>

1) annotate, adds the message
      obvious falsehood
      expected: False
       but got: True