hspec-api-2.11.16: A Testing Framework for Haskell
Stabilitydeprecated
Safe HaskellNone
LanguageHaskell2010

Test.Hspec.Api.Formatters.V1

Description

This module contains formatters that can be used with hspecWith:

import Test.Hspec
import Test.Hspec.Api.Formatters.V1

main :: IO ()
main = hspecWith (useFormatter ("my-formatter", formatter) defaultConfig) spec

formatter :: Formatter
formatter = ...

spec :: Spec
spec = ...
Synopsis

Register a formatter

useFormatter :: (String, Formatter) -> Config -> Config Source #

Make a formatter available for use with --format and use it by default.

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 FailureReason Source #

Constructors

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

Instances

Instances details
Show FailureReason 
Instance details

Defined in Test.Hspec.Core.Formatters.V1.Monad

Methods

showsPrec :: Int -> FailureReason -> ShowS

show :: FailureReason -> String

showList :: [FailureReason] -> ShowS

type FormatM = Free FormatF Source #

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.

newtype Seconds Source #

Constructors

Seconds Double 

Instances

Instances details
PrintfArg Seconds 
Instance details

Defined in Test.Hspec.Core.Clock

Methods

formatArg :: Seconds -> FieldFormatter

parseFormat :: Seconds -> ModifierParser

Num Seconds 
Instance details

Defined in Test.Hspec.Core.Clock

Fractional Seconds 
Instance details

Defined in Test.Hspec.Core.Clock

Methods

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

recip :: Seconds -> Seconds

fromRational :: Rational -> Seconds

Show Seconds 
Instance details

Defined in Test.Hspec.Core.Clock

Methods

showsPrec :: Int -> Seconds -> ShowS

show :: Seconds -> String

showList :: [Seconds] -> ShowS

Eq Seconds 
Instance details

Defined in Test.Hspec.Core.Clock

Methods

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

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

Ord Seconds 
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.

useDiff :: FormatM Bool Source #

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

extraChunk :: String -> FormatM () Source #

Output given chunk in red.

missingChunk :: String -> FormatM () Source #

Output given chunk in green.

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: hspec-core-2.0.0

Re-exports

data Location Source #

Location is used to represent source locations.

Constructors

Location 

Fields

Instances

Instances details
Read Location 
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 
Instance details

Defined in Test.Hspec.Core.Example.Location

Methods

showsPrec :: Int -> Location -> ShowS

show :: Location -> String

showList :: [Location] -> ShowS

Eq Location 
Instance details

Defined in Test.Hspec.Core.Example.Location

Methods

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

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

type Progress = (Int, Int) Source #

(CurrentItem, TotalItems) tuple.

type SpecWith a = SpecM a () Source #

A SpecWith a represents a test or group of tests that require an a value to run.

In the common case, a Spec is a SpecWith () which requires () and can thus be executed with hspec.

To supply an argument to SpecWith tests to turn them into Spec, use functions from Test.Hspec.Core.Hooks such as around, before, mapSubject and similar.

Values of this type are created by it, describe and similar.

modifyConfig :: (Config -> Config) -> SpecWith a Source #

Since: hspec-core-2.10.0