tasty-1.5.3: Modern and extensible testing framework

Safe Haskell | None
Language | Haskell2010

Test.Tasty.Ingredients.ConsoleReporter

Contents

- Internals
  - Output colouring
  - Test failure statistics
  - Outputting results

Description

Console reporter ingredient.

Since: 0.11.3

Synopsis

- consoleTestReporter :: Ingredient
- consoleTestReporterWithHook :: ([TestName] -> Result -> IO Result) -> Ingredient
- newtype Quiet = Quiet Bool
- newtype HideSuccesses = HideSuccesses Bool
- newtype MinDurationToReport = MinDurationToReport {
  - minDurationMicros :: Integer
  }
- newtype AnsiTricks = AnsiTricks {
  - getAnsiTricks :: Bool
  }
- data UseColor
  - = Never
  - | Always
  - | Auto
- useColor :: UseColor -> Bool -> Bool
- data Statistics = Statistics {
  - statTotal :: !Int
  - statFailures :: !Int
  }
- computeStatistics :: StatusMap -> IO Statistics
- printStatistics :: (?colors :: Bool) => Statistics -> Time -> IO ()
- printStatisticsNoTime :: (?colors :: Bool) => Statistics -> IO ()
- data TestOutput
  - = PrintTest String (IO ()) (Progress -> IO ()) (Result -> IO ())
  - | PrintHeading String (IO ()) TestOutput
  - | Skip
  - | Seq TestOutput TestOutput
- buildTestOutput :: (?colors :: Bool) => OptionSet -> TestTree -> TestOutput
- foldTestOutput :: Monoid b => (String -> IO () -> IO Result -> (Result -> IO ()) -> b) -> (String -> IO () -> b -> b) -> TestOutput -> StatusMap -> b
- withConsoleFormat :: (?colors :: Bool) => ConsoleFormatPrinter

# Documentation

consoleTestReporter :: Ingredient #

A simple console UI.

Since: 0.4

consoleTestReporterWithHook :: ([TestName] -> Result -> IO Result) -> Ingredient #

A simple console UI with a hook to postprocess results, depending on their names and external conditions (e. g., its previous outcome, stored in a file). Names are listed in reverse order: from test's own name to a name of the outermost test group.

Since: 1.4.2

newtype Quiet #

Do not print test results (see README for details).

Since: 0.8

Constructors

Quiet Bool |

#### Instances

Instances details

Eq Quiet # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods (==) :: Quiet -> Quiet -> Bool # (/=) :: Quiet -> Quiet -> Bool #
Ord Quiet # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods compare :: Quiet -> Quiet -> Ordering # (<) :: Quiet -> Quiet -> Bool # (<=) :: Quiet -> Quiet -> Bool # (>) :: Quiet -> Quiet -> Bool # (>=) :: Quiet -> Quiet -> Bool # max :: Quiet -> Quiet -> Quiet # min :: Quiet -> Quiet -> Quiet #
IsOption Quiet # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods defaultValue :: Quiet # parseValue :: String -> Maybe Quiet # optionName :: Tagged Quiet String # optionHelp :: Tagged Quiet String # showDefaultValue :: Quiet -> Maybe String # optionCLParser :: Parser Quiet #

newtype HideSuccesses #

Report only failed tests.

At the moment, this option only works globally. As an argument to `localOption`, it does nothing.

Since: 0.8

Constructors

HideSuccesses Bool |

#### Instances

Instances details

Eq HideSuccesses # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods (==) :: HideSuccesses -> HideSuccesses -> Bool # (/=) :: HideSuccesses -> HideSuccesses -> Bool #
Ord HideSuccesses # |

Instance details

Defined in Test.Tasty.Ingredients.ConsoleReporter

Methods

compare :: HideSuccesses -> HideSuccesses -> Ordering #

(<) :: HideSuccesses -> HideSuccesses -> Bool #

(<=) :: HideSuccesses -> HideSuccesses -> Bool #

(>) :: HideSuccesses -> HideSuccesses -> Bool #

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

max :: HideSuccesses -> HideSuccesses -> HideSuccesses #

min :: HideSuccesses -> HideSuccesses -> HideSuccesses #

IsOption HideSuccesses # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods defaultValue :: HideSuccesses # parseValue :: String -> Maybe HideSuccesses # optionName :: Tagged HideSuccesses String # optionHelp :: Tagged HideSuccesses String # showDefaultValue :: HideSuccesses -> Maybe String # optionCLParser :: Parser HideSuccesses #

newtype MinDurationToReport #

The minimum amount of time a test can take before tasty prints timing information.

Since: 1.5

Constructors

MinDurationToReport |

Fields

- minDurationMicros :: Integer

#### Instances

Instances details

Eq MinDurationToReport # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods (==) :: MinDurationToReport -> MinDurationToReport -> Bool # (/=) :: MinDurationToReport -> MinDurationToReport -> Bool #
Ord MinDurationToReport # |

Instance details

Defined in Test.Tasty.Ingredients.ConsoleReporter

Methods

compare :: MinDurationToReport -> MinDurationToReport -> Ordering #

(<) :: MinDurationToReport -> MinDurationToReport -> Bool #

(<=) :: MinDurationToReport -> MinDurationToReport -> Bool #

(>) :: MinDurationToReport -> MinDurationToReport -> Bool #

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

max :: MinDurationToReport -> MinDurationToReport -> MinDurationToReport #

min :: MinDurationToReport -> MinDurationToReport -> MinDurationToReport #

IsOption MinDurationToReport # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods defaultValue :: MinDurationToReport # parseValue :: String -> Maybe MinDurationToReport # optionName :: Tagged MinDurationToReport String # optionHelp :: Tagged MinDurationToReport String # showDefaultValue :: MinDurationToReport -> Maybe String # optionCLParser :: Parser MinDurationToReport #

newtype AnsiTricks #

By default, when the option `--hide-successes` is given and the output goes to an ANSI-capable terminal, we employ some ANSI terminal tricks to display the name of the currently running test and then erase it if it succeeds.

These tricks sometimes fail, however—in particular, when the test names happen to be longer than the width of the terminal window. See

- https://github.com/UnkindPartition/tasty/issues/152
- https://github.com/UnkindPartition/tasty/issues/250

When that happens, this option can be used to disable the tricks. In that case, the test name will be printed only once the test fails.

Since: 1.3

Constructors

AnsiTricks |

Fields

- getAnsiTricks :: Bool

#### Instances

Instances details

IsOption AnsiTricks # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods defaultValue :: AnsiTricks # parseValue :: String -> Maybe AnsiTricks # optionName :: Tagged AnsiTricks String # optionHelp :: Tagged AnsiTricks String # showDefaultValue :: AnsiTricks -> Maybe String # optionCLParser :: Parser AnsiTricks #

# Internals

The following functions and datatypes are internals that are exposed to simplify the task of rolling your own custom console reporter UI.

## Output colouring

data UseColor #

When to use color on the output

Since: 0.11.3

Constructors

Never |
Always |
Auto | Only if stdout is an ANSI color supporting terminal

#### Instances

Instances details

Eq UseColor # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods (==) :: UseColor -> UseColor -> Bool # (/=) :: UseColor -> UseColor -> Bool #
Ord UseColor # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods compare :: UseColor -> UseColor -> Ordering # (<) :: UseColor -> UseColor -> Bool # (<=) :: UseColor -> UseColor -> Bool # (>) :: UseColor -> UseColor -> Bool # (>=) :: UseColor -> UseColor -> Bool # max :: UseColor -> UseColor -> UseColor # min :: UseColor -> UseColor -> UseColor #
IsOption UseColor # | Control color output
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods defaultValue :: UseColor # parseValue :: String -> Maybe UseColor # optionName :: Tagged UseColor String # optionHelp :: Tagged UseColor String # showDefaultValue :: UseColor -> Maybe String # optionCLParser :: Parser UseColor #

useColor :: UseColor -> Bool -> Bool #

`useColor when isTerm` decides if colors should be used, where `isTerm` indicates whether `stdout` is a terminal device.

Since: 0.11.3

## Test failure statistics

data Statistics #

Track the number of tests that were run and failures of a `TestTree` or sub-tree.

Since: 0.11.3

Constructors

Statistics |

Fields

- statTotal :: !Int

  Number of active tests (e.g., that match the pattern specified on the commandline), inactive tests are not counted.

- statFailures :: !Int

  Number of active tests that failed.

#### Instances

Instances details

Monoid Statistics # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods mempty :: Statistics # mappend :: Statistics -> Statistics -> Statistics # mconcat :: [Statistics] -> Statistics #
Semigroup Statistics # | Since: 0.12.0.1
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods (<>) :: Statistics -> Statistics -> Statistics # sconcat :: NonEmpty Statistics -> Statistics # stimes :: Integral b => b -> Statistics -> Statistics #

computeStatistics :: StatusMap -> IO Statistics #

`computeStatistics` computes a summary `Statistics` for a given state of the `StatusMap`. Useful in combination with `printStatistics`.

Since: 1.2.3

printStatistics :: (?colors :: Bool) => Statistics -> Time -> IO () #

`printStatistics` reports test success/failure statistics and time it took to run. The `Time` results is intended to be filled in by the `TestReporter` callback. The `colors` ImplicitParam controls whether coloured output is used.

Since: 0.11.3

printStatisticsNoTime :: (?colors :: Bool) => Statistics -> IO () #

`printStatisticsNoTime` reports test success/failure statistics The `colors` ImplicitParam controls whether coloured output is used.

Since: 0.12

## Outputting results

data TestOutput #

`TestOutput` is an intermediary between output formatting and output printing. It lets us have several different printing modes (normal; print failures only; quiet).

Since: 0.12

Constructors

PrintTest | Printing a test.

Fields

- String

  Name of the test.

- (IO ())

  Action that prints the test name.

- (Progress -> IO ())

  Action that prints the progress of the test. Since: 1.5

- (Result -> IO ())

  Action that renders the result of the test.

PrintHeading | Printing a test group.

Fields

- String

  Name of the test group

- (IO ())

  Action that prints the heading of a test group.

- TestOutput

  The `TestOutput` for that test group.

Skip | Inactive test (e.g. not matching the current pattern).
Seq TestOutput TestOutput | Two sets of `TestOutput` on the same level.

#### Instances

Instances details

Monoid TestOutput # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods mempty :: TestOutput # mappend :: TestOutput -> TestOutput -> TestOutput # mconcat :: [TestOutput] -> TestOutput #
Semigroup TestOutput # |
Instance details Defined in Test.Tasty.Ingredients.ConsoleReporter Methods (<>) :: TestOutput -> TestOutput -> TestOutput # sconcat :: NonEmpty TestOutput -> TestOutput # stimes :: Integral b => b -> TestOutput -> TestOutput #

buildTestOutput :: (?colors :: Bool) => OptionSet -> TestTree -> TestOutput #

Build the `TestOutput` for a `TestTree` and `OptionSet`. The `colors` ImplicitParam controls whether the output is colored.

Since: 0.11.3

foldTestOutput #

Arguments

:: Monoid b |
=> (String -> IO () -> IO Result -> (Result -> IO ()) -> b) | Eliminator for test cases. The `IO ()` prints the testname. The `IO Result` blocks until the test is finished, returning it's `Result`. The `Result -> IO ()` function prints the formatted output.
-> (String -> IO () -> b -> b) | Eliminator for test groups. The `IO ()` prints the test group's name. The `b` is the result of folding the test group.
-> TestOutput | The `TestOutput` being rendered.
-> StatusMap | The `StatusMap` received by the `TestReporter`
-> b |

Fold function for the `TestOutput` tree into a `Monoid`.

Since: 0.12

withConsoleFormat :: (?colors :: Bool) => ConsoleFormatPrinter #

Run action with console configured for a specific output format

This function does not apply any output formats if colors are disabled at command line or console detection.

Can be used by providers that wish to provider specific result details printing, while re-using the tasty formats and coloring logic.

Since: 1.3.1