hspec-core-2.3.2: A Testing Framework for Haskell

Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Test.Hspec.Core.Formatters

Contents

Description

This module contains formatters that can be used with hspecWith.

Synopsis

Formatters

Implementing a custom Formatter

A formatter is a set of actions. Each action is evaluated when a certain situation is encountered during a test run.

Actions live in the FormatM monad. It provides access to the runner state and primitives for appending to the generated report.

data Formatter Source #

Constructors

Formatter 

Fields

data FormatM a Source #

Instances

Monad FormatM Source # 

Methods

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

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

return :: a -> FormatM a #

fail :: String -> FormatM a #

Functor FormatM Source # 

Methods

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

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

Applicative FormatM Source # 

Methods

pure :: a -> FormatM a #

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

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

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

MonadIO FormatM Source # 

Methods

liftIO :: IO a -> FormatM a #

Accessing the runner state

getSuccessCount :: FormatM Int Source #

Get the number of successful examples encountered so far.

getPendingCount :: FormatM Int Source #

Get the number of pending examples encountered so far.

getFailCount :: FormatM Int Source #

Get the number of failed examples encountered so far.

getTotalCount :: FormatM Int Source #

Get the total number of examples encountered so far.

getFailMessages :: FormatM [FailureRecord] Source #

Get the list of accumulated failure messages.

usedSeed :: FormatM Integer Source #

The random seed that is used for QuickCheck.

getCPUTime :: FormatM (Maybe Double) Source #

Get the used CPU time since the test run has been started.

getRealTime :: FormatM Double Source #

Get the passed real time since the test run has been started.

Appending to the gerenated report

write :: String -> FormatM () Source #

Append some output to the report.

writeLine :: String -> FormatM () Source #

The same as write, but adds a newline character.

newParagraph :: FormatM () Source #

Deprecated: use writeLine "" instead

Append an empty line to the report.

Calling this multiple times has the same effect as calling it once.

Dealing with colors

withInfoColor :: FormatM a -> FormatM a Source #

Set output color to cyan, run given action, and finally restore the default color.

withSuccessColor :: FormatM a -> FormatM a Source #

Set output color to green, run given action, and finally restore the default color.

withPendingColor :: FormatM a -> FormatM a Source #

Set output color to yellow, run given action, and finally restore the default color.

withFailColor :: FormatM a -> FormatM a Source #

Set output color to red, run given action, and finally restore the default color.

Helpers

formatException :: SomeException -> String Source #

The function formatException converts an exception to a string.

This is different from show. The type of the exception is included, e.g.:

>>> formatException (toException DivideByZero)
"ArithException (divide by zero)"

For IOExceptions the IOErrorType is included, as well.