hspec-core-2.11.12: A Testing Framework for Haskell
Stabilityunstable
Safe HaskellNone
LanguageHaskell2010

Test.Hspec.Core.Formatters.V2

Description

This is an unstable API. Use Test.Hspec.Api.Formatters.V3 instead.

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.

type Path = ([String], String) Source #

A Path describes the location of a spec item within a spec tree.

It consists of a list of group descriptions and a requirement description.

Since: 2.0.0

type Progress = (Int, Int) Source #

data Location Source #

Location is used to represent source locations.

Constructors

Location 

Fields

Instances

Instances details
Read Location Source # 
Instance details

Defined in Test.Hspec.Core.Example.Location

Methods

readsPrec :: Int -> ReadS Location

readList :: ReadS [Location]

readPrec :: ReadPrec Location

readListPrec :: ReadPrec [Location]

Show Location Source # 
Instance details

Defined in Test.Hspec.Core.Example.Location

Methods

showsPrec :: Int -> Location -> ShowS

show :: Location -> String

showList :: [Location] -> ShowS

Eq Location Source # 
Instance details

Defined in Test.Hspec.Core.Example.Location

Methods

(==) :: Location -> Location -> Bool

(/=) :: Location -> Location -> Bool

data Item Source #

Constructors

Item 

Fields

Instances

Instances details
Show Item Source # 
Instance details

Defined in Test.Hspec.Core.Format

Methods

showsPrec :: Int -> Item -> ShowS

show :: Item -> String

showList :: [Item] -> ShowS

data Result Source #

Constructors

Success 
Pending (Maybe Location) (Maybe String) 
Failure (Maybe Location) FailureReason 

Instances

Instances details
Show Result Source # 
Instance details

Defined in Test.Hspec.Core.Format

Methods

showsPrec :: Int -> Result -> ShowS

show :: Result -> String

showList :: [Result] -> ShowS

data FailureReason Source #

Constructors

NoReason 
Reason String 
ColorizedReason String 
ExpectedButGot (Maybe String) String String 
Error (Maybe String) SomeException 

Instances

Instances details
Show FailureReason Source # 
Instance details

Defined in Test.Hspec.Core.Example

Methods

showsPrec :: Int -> FailureReason -> ShowS

show :: FailureReason -> String

showList :: [FailureReason] -> ShowS

NFData FailureReason Source # 
Instance details

Defined in Test.Hspec.Core.Example

Methods

rnf :: FailureReason -> ()

data FormatM a Source #

Instances

Instances details
MonadIO FormatM Source # 
Instance details

Defined in Test.Hspec.Core.Formatters.Internal

Methods

liftIO :: IO a -> FormatM a

Applicative FormatM Source # 
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

Functor FormatM Source # 
Instance details

Defined in Test.Hspec.Core.Formatters.Internal

Methods

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

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

Monad FormatM Source # 
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

Accessing config values

getConfigValue :: (FormatConfig -> a) -> FormatM a Source #

Since: 2.11.5

data FormatConfig Source #

Since: 2.11.5

Constructors

FormatConfig 

Fields

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.

getExpectedTotalCount :: FormatM Int Source #

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

Since: 2.9.0

getFailMessages :: FormatM [FailureRecord] Source #

Get the list of accumulated failure messages.

usedSeed :: FormatM Integer Source #

The random seed that is used for QuickCheck.

printTimes :: FormatM Bool Source #

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

newtype Seconds Source #

Constructors

Seconds Double 

Instances

Instances details
Num Seconds Source # 
Instance details

Defined in Test.Hspec.Core.Clock

Fractional Seconds Source # 
Instance details

Defined in Test.Hspec.Core.Clock

Methods

(/) :: Seconds -> Seconds -> Seconds

recip :: Seconds -> Seconds

fromRational :: Rational -> Seconds

Show Seconds Source # 
Instance details

Defined in Test.Hspec.Core.Clock

Methods

showsPrec :: Int -> Seconds -> ShowS

show :: Seconds -> String

showList :: [Seconds] -> ShowS

PrintfArg Seconds Source # 
Instance details

Defined in Test.Hspec.Core.Clock

Methods

formatArg :: Seconds -> FieldFormatter

parseFormat :: Seconds -> ModifierParser

Eq Seconds Source # 
Instance details

Defined in Test.Hspec.Core.Clock

Methods

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

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

Ord Seconds Source # 
Instance details

Defined in Test.Hspec.Core.Clock

Methods

compare :: Seconds -> Seconds -> Ordering

(<) :: Seconds -> Seconds -> Bool

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

(>) :: Seconds -> Seconds -> Bool

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

max :: Seconds -> Seconds -> Seconds

min :: Seconds -> Seconds -> Seconds

getCPUTime :: FormatM (Maybe Seconds) Source #

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

getRealTime :: FormatM Seconds Source #

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

Appending to the generated report

write :: String -> FormatM () Source #

Append some output to the report.

writeLine :: String -> FormatM () Source #

The same as write, but adds a newline character.

writeTransient :: String -> FormatM () Source #

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.

outputUnicode :: FormatM Bool Source #

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

Since: 2.9.0

useDiff :: FormatM Bool Source #

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

diffContext :: FormatM (Maybe Int) Source #

Return the value of configDiffContext.

Since: 2.10.6

externalDiffAction :: FormatM (Maybe (String -> String -> IO ())) Source #

An action for printing diffs.

The action takes expected and actual as arguments.

When this is a Just-value then it should be used instead of any built-in diff implementation. A Just-value also implies that useDiff returns True.

Since: 2.10.6

prettyPrint :: FormatM Bool Source #

Deprecated: use prettyPrintFunction instead

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

prettyPrintFunction :: FormatM (Maybe (String -> String -> (String, String))) Source #

Return a function for pretty-printing if the user requested pretty diffs, Nothing otherwise.

Since: 2.10.0

extraChunk :: String -> FormatM () Source #

Output given chunk in red.

missingChunk :: String -> FormatM () Source #

Output given chunk in green.

expert mode

unlessExpert :: FormatM () -> FormatM () Source #

Do nothing on `--expert`, otherwise run the given action.

Since: 2.11.2

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\ndivide by zero"

For IOExceptions the IOErrorType is included, as well.

Since: 2.0.0