HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduletasty-1.5.3Haskell2010

Test.Tasty.Runners

API for test runners.

  • 19 types
  • 27 values
  • Packagetasty-1.5.3
  • Exports46
  • LanguageHaskell2010
  • LicenceMIT
  • SourceRunners.hs

Working with the test tree

7 declarations
datadata TestTree
#

The main data structure defining a test suite.

It consists of individual test cases and properties, organized in named groups which form a tree-like hierarchy.

There is no generic way to create a test case. Instead, every test provider (tasty-hunit, tasty-smallcheck etc.) provides a function to turn a test case into a TestTree.

Groups can be created using testGroup.

Constructors

valuefoldTestTree
  1. :: Monoid b
  2. => TreeFold b

    the algebra (i.e. how to fold a tree)

  3. -> OptionSet

    initial options

  4. -> TestTree

    the tree to fold

  5. -> b
#

Fold a test tree into a single value.

The fold result type should be a monoid. This is used to fold multiple results in a test group. In particular, empty groups get folded into mempty.

Apart from pure convenience, this function also does the following useful things:

  1. Keeping track of the current options (which may change due to PlusTestOptions nodes)

  2. Filtering out the tests which do not match the patterns

Thus, it is preferred to an explicit recursive traversal of the tree.

valuetrivialFold :: Monoid b => TreeFold b
#

trivialFold can serve as the basis for custom folds. Just override the fields you need.

Here's what it does:

  • single tests are mapped to mempty (you probably do want to override that)

  • test groups are returned unmodified

  • for a resource, an IO action that throws an exception is passed (you want to override this for runners/ingredients that execute tests)

newtypenewtype Ap (f :: Type -> Type) a
#

Monoid generated by liftA2 (<>)

Starting from GHC 8.6, a similar type is available from Data.Monoid. This type is nevertheless kept for compatibility.

Constructors

Instances5Monad, Functor, Applicative, Semigroup, Monoid

Ingredients

5 declarations
datadata Ingredient
#

Ingredients make your test suite tasty.

Ingredients represent different actions that you can perform on your test suite. One obvious ingredient that you want to include is one that runs tests and reports the progress and results.

Another standard ingredient is one that simply prints the names of all tests.

Similar to test providers (see IsTest), every ingredient may specify which options it cares about, so that those options are presented to the user if the ingredient is included in the test suite.

An ingredient can choose, typically based on the OptionSet, whether to run. That's what the Maybe is for. The first ingredient that agreed to run does its work, and the remaining ingredients are ignored. Thus, the order in which you arrange the ingredients may matter.

Usually, the ingredient which runs the tests is unconditional and thus should be placed last in the list. Other ingredients usually run only if explicitly requested via an option. Their relative order thus doesn't matter.

That's all you need to know from an (advanced) user perspective. Read on if you want to create a new ingredient.

There are two kinds of ingredients.

The first kind is TestReporter. If the ingredient that agrees to run is a TestReporter, then tasty will automatically launch the tests and pass a StatusMap to the ingredient. All the ingredient needs to do then is to process the test results and probably report them to the user in some way (hence the name).

TestManager is the second kind of ingredient. It is typically used for test management purposes (such as listing the test names), although it can also be used for running tests (but, unlike TestReporter, it has to launch the tests manually if it wants them to be run). It is therefore more general than TestReporter. TestReporter is provided just for convenience.

The function's result should indicate whether all the tests passed.

In the TestManager case, it's up to the ingredient author to decide what the result should be. When no tests are run, the result should probably be True. Sometimes, even if some tests run and fail, it still makes sense to return True.

Constructors

typetype Time = Double
#

Time in seconds. Used to measure how long the tests took to run.

Standard console ingredients

0 declarations

NOTE: the exports in this section are deprecated and will be removed in the future. Please import Test.Tasty.Ingredients.Basic if you need them.

Console test reporter

Tests list

newtypenewtype ListTests
#

This option, when set to True, specifies that we should run in the «list tests» mode.

Constructors

Instances3Eq, Ord, IsOption
  • Eq ListTestsDefined in tasty-1.5.3 · Test.Tasty.Ingredients.ListTests
  • Ord ListTestsDefined in tasty-1.5.3 · Test.Tasty.Ingredients.ListTests
  • IsOption ListTestsDefined in tasty-1.5.3 · Test.Tasty.Ingredients.ListTests

Command line handling

4 declarations

Running tests

11 declarations
datadata Result
#

A test result.

Constructors

Instances1Show
  • Show ResultDefined in tasty-1.5.3 · Test.Tasty.Core
datadata Outcome
#

Outcome of a test run

Note: this is isomorphic to Maybe FailureReason. You can use the generic-maybe package to exploit that.

Constructors

Instances3Show, Generic, Rep
datadata FailureReason
#

If a test failed, FailureReason describes why.

Constructors

  • TestFailed

    test provider indicated failure of the code to test, either because the tested code returned wrong results, or raised an exception

  • TestThrewException SomeException

    the test code itself raised an exception. Typical cases include missing example input or output files.

    Usually, providers do not have to implement this, as their run method may simply raise an exception.

  • TestTimedOut Integer

    test didn't complete in allotted time

  • TestDepFailed

    a dependency of this test failed, so this test was skipped.

Instances1Show
datadata Progress
#

Test progress information.

This may be used by a runner to provide some feedback to the user while a long-running test is executing.

Constructors

Instances2Eq, Show
typetype StatusMap = IntMap (TVar Status)
#

Mapping from test numbers (starting from 0) to their status variables.

This is what an ingredient uses to analyse and display progress, and to detect when tests finish.

valuelaunchTestTree
  1. :: OptionSet
  2. -> TestTree
  3. -> (StatusMap -> IO (Time -> IO a))

    A callback. First, it receives the StatusMap through which it can observe the execution of tests in real time. Typically (but not necessarily), it waits until all the tests are finished.

    After this callback returns, the test-running threads (if any) are terminated and all resources acquired by tests are released.

    The callback must return another callback (of type Time -> IO a) which additionally can report and/or record the total time taken by the test suite. This time includes the time taken to run all resource initializers and finalizers, which is why it is more accurate than what could be measured from inside the first callback.

  4. -> IO a
#

Start running the tests (in background, in parallel) and pass control to the callback.

Once the callback returns, stop running the tests.

The number of test running threads is determined by the NumThreads option.

newtypenewtype NumThreads
#

Number of parallel threads to use for running tests.

Note that this is not included in coreOptions. Instead, it's automatically included in the options for any TestReporter ingredient by ingredientOptions, because the way test reporters are handled already involves parallelism. Other ingredients may also choose to include this option.

Instances4Eq, Num, Ord, IsOption
newtypenewtype DependencyException
#

Exceptions related to dependencies between tests.

Constructors

  • DependencyLoop [[Path]]

    Test dependencies form cycles. In other words, test A cannot start until test B finishes, and test B cannot start until test A finishes. Field lists detected cycles.

Instances2Show, Exception

Options

2 declarations

Patterns

newtypenewtype TestPattern
#

Constructors

Instances3Eq, Show, IsOption
  • Eq TestPatternDefined in tasty-1.5.3 · Test.Tasty.Patterns
  • Show TestPatternDefined in tasty-1.5.3 · Test.Tasty.Patterns
  • IsOption TestPatternDefined in tasty-1.5.3 · Test.Tasty.Patterns

    Since tasty-1.5, this option can be specified multiple times on the command line. Only the tests matching all given patterns will be selected.

Utilities

6 declarations
valuetimed :: IO a -> IO (Time, a)
#

Measure the time taken by an IO action to run.

valueinstallSignalHandlers :: IO ()
#

Install signal handlers so that e.g. the cursor is restored if the test suite is killed by SIGTERM. Upon a signal, a SignalException will be thrown to the thread that has executed this action.

This function is called automatically from the defaultMain* family of functions. You only need to call it explicitly if you call Test.Tasty.Runners.tryIngredients yourself.

This function does nothing when POSIX signals are not supported.

valuegetTime :: IO Time
#

Get monotonic time.

Warning: This is not the system time, but a monotonically increasing time that facilitates reliable measurement of time differences.