hspec-core-2.11.16: A Testing Framework for Haskell

Stability | deprecated
Safe Haskell | None
Language | Haskell2010

Test.Hspec.Core.Formatters.V1

Contents

- Formatters
- Implementing a custom Formatter
  - Accessing the runner state
  - Appending to the generated report
  - Dealing with colors
  - Helpers

Description

Deprecated: Use Test.Hspec.Api.Formatters.V1 instead.

This module contains formatters that can be used with `hspecWith`.

Synopsis

- silent :: Formatter
- checks :: Formatter
- specdoc :: Formatter
- progress :: Formatter
- failed_examples :: Formatter
- data Formatter = Formatter {
  - headerFormatter :: FormatM ()
  - exampleGroupStarted :: [String] -> String -> FormatM ()
  - exampleGroupDone :: FormatM ()
  - exampleStarted :: Path -> FormatM ()
  - exampleProgress :: Path -> Progress -> FormatM ()
  - exampleSucceeded :: Path -> String -> FormatM ()
  - exampleFailed :: Path -> String -> FailureReason -> FormatM ()
  - examplePending :: Path -> String -> Maybe String -> FormatM ()
  - failedFormatter :: FormatM ()
  - footerFormatter :: FormatM ()
  }
- data FailureReason
  - = NoReason
  - | Reason String
  - | ExpectedButGot (Maybe String) String String
  - | Error (Maybe String) SomeException
- type FormatM = Free FormatF
- formatterToFormat :: Formatter -> FormatConfig -> IO Format
- getSuccessCount :: FormatM Int
- getPendingCount :: FormatM Int
- getFailCount :: FormatM Int
- getTotalCount :: FormatM Int
- data FailureRecord = FailureRecord {
  - failureRecordLocation :: Maybe Location
  - failureRecordPath :: Path
  - failureRecordMessage :: FailureReason
  }
- getFailMessages :: FormatM [FailureRecord]
- usedSeed :: FormatM Integer
- newtype Seconds = Seconds Double
- getCPUTime :: FormatM (Maybe Seconds)
- getRealTime :: FormatM Seconds
- write :: String -> FormatM ()
- writeLine :: String -> FormatM ()
- writeTransient :: String -> FormatM ()
- withInfoColor :: FormatM a -> FormatM a
- withSuccessColor :: FormatM a -> FormatM a
- withPendingColor :: FormatM a -> FormatM a
- withFailColor :: FormatM a -> FormatM a
- useDiff :: FormatM Bool
- extraChunk :: String -> FormatM ()
- missingChunk :: String -> FormatM ()
- formatException :: SomeException -> String

# Formatters

silent :: Formatter Source #

checks :: Formatter Source #

specdoc :: Formatter Source #

progress :: Formatter Source #

failed_examples :: Formatter Source #

# 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

- headerFormatter :: FormatM ()
- exampleGroupStarted :: [String] -> String -> FormatM ()
- exampleGroupDone :: FormatM ()
- exampleStarted :: Path -> FormatM ()
- exampleProgress :: Path -> Progress -> FormatM ()
- exampleSucceeded :: Path -> String -> FormatM ()
- exampleFailed :: Path -> String -> FailureReason -> FormatM ()
- examplePending :: Path -> String -> Maybe String -> FormatM ()
- failedFormatter :: FormatM ()
- footerFormatter :: FormatM ()

data FailureReason Source #

Constructors

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

#### Instances

Instances details

Show FailureReason Source # |
Instance details Defined in Test.Hspec.Core.Formatters.V1.Monad Methods showsPrec :: Int -> FailureReason -> ShowS Source # show :: FailureReason -> String Source # showList :: [FailureReason] -> ShowS Source #

type FormatM = Free FormatF Source #

formatterToFormat :: Formatter -> FormatConfig -> IO Format 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.

data FailureRecord Source #

Constructors

FailureRecord |

Fields

- failureRecordLocation :: Maybe Location
- failureRecordPath :: Path
- failureRecordMessage :: FailureReason

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 Source # |
Instance details Defined in Test.Hspec.Core.Clock Methods formatArg :: Seconds -> FieldFormatter Source # parseFormat :: Seconds -> ModifierParser Source #
Num Seconds Source # |
Instance details Defined in Test.Hspec.Core.Clock Methods (+) :: Seconds -> Seconds -> Seconds Source # (-) :: Seconds -> Seconds -> Seconds Source # (*) :: Seconds -> Seconds -> Seconds Source # negate :: Seconds -> Seconds Source # abs :: Seconds -> Seconds Source # signum :: Seconds -> Seconds Source # fromInteger :: Integer -> Seconds Source #
Fractional Seconds Source # |
Instance details Defined in Test.Hspec.Core.Clock Methods (/) :: Seconds -> Seconds -> Seconds Source # recip :: Seconds -> Seconds Source # fromRational :: Rational -> Seconds Source #
Show Seconds Source # |
Instance details Defined in Test.Hspec.Core.Clock Methods showsPrec :: Int -> Seconds -> ShowS Source # show :: Seconds -> String Source # showList :: [Seconds] -> ShowS Source #
Eq Seconds Source # |
Instance details Defined in Test.Hspec.Core.Clock Methods (==) :: Seconds -> Seconds -> Bool Source # (/=) :: Seconds -> Seconds -> Bool Source #
Ord Seconds Source # |
Instance details Defined in Test.Hspec.Core.Clock Methods compare :: Seconds -> Seconds -> Ordering Source # (<) :: Seconds -> Seconds -> Bool Source # (<=) :: Seconds -> Seconds -> Bool Source # (>) :: Seconds -> Seconds -> Bool Source # (>=) :: Seconds -> Seconds -> Bool Source # max :: Seconds -> Seconds -> Seconds Source # min :: Seconds -> Seconds -> Seconds Source #

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 `IOException`s the `IOErrorType` is included, as well.

Since: 2.0.0