easytest-0.2: Simple, expressive testing library

Safe HaskellNone
LanguageHaskell98

EasyTest.Internal

Contents

Synopsis

Core

crash :: HasCallStack => Text -> Test a Source #

Record a failure at the current scope

note :: Text -> Test () Source #

Log a message

scope :: Text -> Test a -> Test a Source #

Label a test. Can be nested. A "." is placed between nested scopes, so scope "foo" . scope "bar" is equivalent to scope "foo.bar"

Internal

data Status Source #

Status of a test

Constructors

Failed 
Passed !Int 
Skipped 

data Env Source #

Constructors

Env 

Instances

MonadReader Env Test Source # 

Methods

ask :: Test Env #

local :: (Env -> Env) -> Test a -> Test a #

reader :: (Env -> a) -> Test a #

newtype Test a Source #

Tests are values of type Test a, and Test forms a monad with access to:

  • repeatable randomness (the random and random' functions for random and bounded random values, or handy specialized int, int', double, double', etc)
  • I/O (via liftIO or io, which is an alias for liftIO)
  • failure (via crash, which yields a stack trace, or fail, which does not)
  • logging (via note, noteScoped, or note')
  • hierarchically-named subcomputations (under scope) which can be switched on and off via runOnly
  • parallelism (via fork)
  • conjunction of tests via MonadPlus (the <|> operation runs both tests, even if the first test fails, and the tests function used above is just msum).

Using any or all of these capabilities, you assemble Test values into a "test suite" (just another Test value) using ordinary Haskell code, not framework magic. Notice that to generate a list of random values, we just replicateM and forM as usual.

Constructors

Test (ReaderT Env IO (Maybe a)) 

Instances

Monad Test Source # 

Methods

(>>=) :: Test a -> (a -> Test b) -> Test b #

(>>) :: Test a -> Test b -> Test b #

return :: a -> Test a #

fail :: String -> Test a #

Functor Test Source # 

Methods

fmap :: (a -> b) -> Test a -> Test b #

(<$) :: a -> Test b -> Test a #

Applicative Test Source # 

Methods

pure :: a -> Test a #

(<*>) :: Test (a -> b) -> Test a -> Test b #

liftA2 :: (a -> b -> c) -> Test a -> Test b -> Test c #

(*>) :: Test a -> Test b -> Test b #

(<*) :: Test a -> Test b -> Test a #

MonadIO Test Source # 

Methods

liftIO :: IO a -> Test a #

Alternative Test Source # 

Methods

empty :: Test a #

(<|>) :: Test a -> Test a -> Test a #

some :: Test a -> Test [a] #

many :: Test a -> Test [a] #

MonadPlus Test Source # 

Methods

mzero :: Test a #

mplus :: Test a -> Test a -> Test a #

MonadReader Env Test Source # 

Methods

ask :: Test Env #

local :: (Env -> Env) -> Test a -> Test a #

reader :: (Env -> a) -> Test a #

IsString (Test a -> Test a) Source # 

Methods

fromString :: String -> Test a -> Test a #