hspec-core-2.9.4: A Testing Framework for Haskell
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Test.Hspec.Core.Formatters.V2

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 #

Constructors

Formatter 

Fields

data Item #

Instances

Instances details
Show Item # 
Instance details

Defined in Test.Hspec.Core.Format

Methods

showsPrec :: Int -> Item -> ShowS #

show :: Item -> String #

showList :: [Item] -> ShowS #

data Result #

Instances

Instances details
Show Result # 
Instance details

Defined in Test.Hspec.Core.Format

data FormatM a #

Instances

Instances details
Monad FormatM # 
Instance details

Defined in Test.Hspec.Core.Formatters.Internal

Methods

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

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

return :: a -> FormatM a #

Functor FormatM # 
Instance details

Defined in Test.Hspec.Core.Formatters.Internal

Methods

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

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

Applicative FormatM # 
Instance details

Defined in Test.Hspec.Core.Formatters.Internal

Methods

pure :: a -> FormatM a #

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

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

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

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

MonadIO FormatM # 
Instance details

Defined in Test.Hspec.Core.Formatters.Internal

Methods

liftIO :: IO a -> FormatM a #

Accessing the runner state

getSuccessCount :: FormatM Int #

Get the number of successful examples encountered so far.

getPendingCount :: FormatM Int #

Get the number of pending examples encountered so far.

getFailCount :: FormatM Int #

Get the number of failed examples encountered so far.

getTotalCount :: FormatM Int #

Get the total number of examples encountered so far.

getExpectedTotalCount :: FormatM Int #

Get the number of spec items that will have been encountered when this run completes (if it is not terminated early).

getFailMessages :: FormatM [FailureRecord] #

Get the list of accumulated failure messages.

usedSeed :: FormatM Integer #

The random seed that is used for QuickCheck.

printTimes :: FormatM Bool #

Return True if the user requested time reporting for individual spec items, False otherwise.

newtype Seconds #

Constructors

Seconds Double 

Instances

Instances details
Eq Seconds # 
Instance details

Defined in Test.Hspec.Core.Clock

Methods

(==) :: Seconds -> Seconds -> Bool #

(/=) :: Seconds -> Seconds -> Bool #

Fractional Seconds # 
Instance details

Defined in Test.Hspec.Core.Clock

Num Seconds # 
Instance details

Defined in Test.Hspec.Core.Clock

Ord Seconds # 
Instance details

Defined in Test.Hspec.Core.Clock

Show Seconds # 
Instance details

Defined in Test.Hspec.Core.Clock

PrintfArg Seconds # 
Instance details

Defined in Test.Hspec.Core.Clock

getCPUTime :: FormatM (Maybe Seconds) #

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

getRealTime :: FormatM Seconds #

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

Appending to the generated report

write :: String -> FormatM () #

Append some output to the report.

writeLine :: String -> FormatM () #

The same as write, but adds a newline character.

Dealing with colors

withInfoColor :: FormatM a -> FormatM a #

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

withSuccessColor :: FormatM a -> FormatM a #

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

withPendingColor :: FormatM a -> FormatM a #

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

withFailColor :: FormatM a -> FormatM a #

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

outputUnicode :: FormatM Bool #

Return True if the user requested unicode output, False otherwise.

useDiff :: FormatM Bool #

Return True if the user requested colorized diffs, False otherwise.

prettyPrint :: FormatM Bool #

Return True if the user requested pretty diffs, False otherwise.

extraChunk :: String -> FormatM () #

Output given chunk in red.

missingChunk :: String -> FormatM () #

Output given chunk in green.

Helpers

formatException :: SomeException -> String #

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.