HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulehspec-core-2.11.14Haskell2010

Test.Hspec.Core.Runner

  • 10 types
  • 21 values

Simple interface

4 declarations
valuehspec :: Spec -> IO ()
#

Run a given spec and write a report to stdout. Exit with exitFailure if at least one spec item fails.

Note: hspec handles command-line options and reads config files. This is not always desirable. Use evalSpec and runSpecForest if you need more control over these aspects.

Summary

Running a spec

3 declarations

To run a spec hspec performs a sequence of steps:

  1. Evaluate a Spec to a forest of SpecTrees

  2. Read config values from the command-line, config files and the process environment

  3. Execute each spec item of the forest and report results to stdout

  4. Exit with exitFailure if at least on spec item fails

The four primitives evalSpec, readConfig, runSpecForest and evaluateResult each perform one of these steps respectively.

hspec is defined in terms of these primitives. Loosely speaking, a definition for hspec is:

hspec = evalSpec defaultConfig >=> \ (config, spec) ->
      getArgs
  >>= readConfig config
  >>= withArgs [] . runSpecForest spec
  >>= evaluateResult

Loosely speaking in the sense that this definition of hspec ignores --rerun-all-on-success.

Using these primitives individually gives you more control over how a spec is run. However, if you need support for --rerun-all-on-success then you should try hard to solve your use case with one of hspec, hspecWith, hspecResult or hspecWithResult.

Result

Spec Result

datadata SpecResult
#
Instances2Eq, Show
  • Eq SpecResultDefined in hspec-core-2.11.14 · Test.Hspec.Core.Runner.Result
  • Show SpecResultDefined in hspec-core-2.11.14 · Test.Hspec.Core.Runner.Result

Result Item

datadata ResultItem
#
Instances2Eq, Show
  • Eq ResultItemDefined in hspec-core-2.11.14 · Test.Hspec.Core.Runner.Result
  • Show ResultItemDefined in hspec-core-2.11.14 · Test.Hspec.Core.Runner.Result

Result Item Status

Config

9 declarations
datadata Config
#
typetype Path = ([String], String)
#

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.

valuereadConfig :: Config -> [String] -> IO Config
#

readConfig parses config options from several sources and constructs a Config value. It takes options from:

  1. ~/.hspec (a config file in the user's home directory)

  2. .hspec (a config file in the current working directory)

  3. environment variables starting with HSPEC_

  4. the provided list of command-line options (the second argument to readConfig)

(precedence from low to high)

When parsing fails then readConfig writes an error message to stderr and exits with exitFailure.

When --help is provided as a command-line option then readConfig writes a help message to stdout and exits with exitSuccess.

A common way to use readConfig is:

getArgs >>= readConfig defaultConfig

Legacy

1 declaration

Re-exports

2 declarations
typetype Spec = SpecWith ()
#

A SpecWith that can be evaluated directly by the hspec function as it does not require any parameters.