hspec-1.3.0.2: Behavior Driven Development for Haskell

Safe HaskellNone

Test.Hspec.Formatters

Contents

Description

This module contains formatters that take a set of specs and write to a given handle. They follow a structure similar to RSpec formatters.

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

formatterName :: String
 
exampleGroupStarted :: Int -> String -> FormatM ()

evaluated before each test group

exampleSucceeded :: Int -> String -> FormatM ()

evaluated after each successful example

exampleFailed :: Int -> String -> String -> FormatM ()

evaluated after each failed example

examplePending :: Int -> String -> Maybe String -> FormatM ()

evaluated after each pending example

failedFormatter :: FormatM ()

evaluated after a test run

footerFormatter :: FormatM ()

evaluated after failuresFormatter

Accessing the runner state

getSuccessCount :: FormatM IntSource

Get the number of successful examples encountered so far.

getPendingCount :: FormatM IntSource

Get the number of pending examples encountered so far.

getFailCount :: FormatM IntSource

Get the number of failed examples encountered so far.

getTotalCount :: FormatM IntSource

Get the total number of examples encountered so far.

getFailMessages :: FormatM [String]Source

Get the list of accumulated failure messages.

getCPUTime :: FormatM DoubleSource

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

getRealTime :: FormatM DoubleSource

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.

Dealing with colors

withSuccessColor :: FormatM a -> FormatM aSource

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

withPendingColor :: FormatM a -> FormatM aSource

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

withFailColor :: FormatM a -> FormatM aSource

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