HTF- The Haskell Test Framework

Safe HaskellNone




This module defines types (and small auxiliary functions) for organizing tests, for configuring the execution of tests, and for representing and reporting their results.


Organizing tests

type TestID = StringSource

Type for naming tests.

data Test Source

Abstract type for tests and their results.


data TestOptions Source

General options for tests




to_parallel :: Bool

data TestSuite Source

Abstract type for test suites and their results.

data TestSort Source

Type for distinguishing different sorts of tests.

data TestPath Source

A type denoting the hierarchical name of a test.

data GenFlatTest a Source

Generic type for flattened tests and their results.




ft_sort :: TestSort

The sort of the test.

ft_path :: TestPath

Hierarchival path.

ft_location :: Maybe Location

Place of definition.

ft_payload :: a

A generic payload.

type FlatTest = GenFlatTest (WithTestOptions Assertion)Source

Flattened representation of tests.

type TestFilter = FlatTest -> BoolSource

A filter is a predicate on FlatTest. If the predicate is True, the flat test is run.

testPathToList :: TestPath -> [Maybe TestID]Source

Splits a TestPath into a list of test identifiers.

flatName :: TestPath -> StringSource

Creates a string representation from a TestPath.

finalName :: TestPath -> StringSource

Returns the final name of a TestPath

prefixName :: TestPath -> StringSource

Returns the name of the prefix of a test path. The prefix is everything except the last element.

withOptions :: (TestOptions -> TestOptions) -> a -> WithTestOptions aSource

Shortcut for constructing a WithTestOptions value.

historyKey :: GenFlatTest a -> TextSource

Key of a flat test for the history database.

Executing tests

type TR = RWST TestConfig () TestState IOSource

The TR (test runner) monad.

data TestState Source

The state type for the TR monad.




ts_results :: [FlatTestResult]

Results collected so far.

ts_index :: Int

Current index for splitted output.

initTestState :: TestStateSource

The initial test state.

data TestConfig Source

Configuration of test execution.




tc_quiet :: Bool

If set, displays messages only for failed tests.

tc_threads :: Maybe Int

Use Just i for parallel execution with i threads, Nothing for sequential execution.

tc_shuffle :: Bool

Shuffle tests before parallel execution

tc_output :: TestOutput

Output destination of progress and result messages.

tc_outputXml :: Maybe FilePath

Output destination of XML result summary

tc_filter :: TestFilter

Filter for the tests to run.

tc_reporters :: [TestReporter]

Test reporters to use.

tc_useColors :: Bool

Whether to use colored output

tc_historyFile :: FilePath

Path to history file

tc_history :: TestHistory

History of previous test runs

tc_sortByPrevTime :: Bool

Sort ascending by previous execution times

tc_failFast :: Bool

Stop test run as soon as one test fails

tc_timeoutIsSuccess :: Bool

Do not regard timeout as an error

tc_maxSingleTestTime :: Maybe Milliseconds

Maximum time in milliseconds a single test is allowed to run

tc_prevFactor :: Maybe Double

Maximum factor a single test is allowed to run slower than its previous execution


data TestOutput Source

The destination of progress and result messages from HTF.


TestOutputHandle Handle Bool

Output goes to Handle, boolean flag indicates whether the handle should be closed at the end.

TestOutputSplitted FilePath

Output goes to files whose names are derived from FilePath by appending a number to it. Numbering starts at zero.

Reporting results

type ReportAllTests = [FlatTest] -> TR ()Source

Reports the IDs of all tests available.

type ReportGlobalStart = [FlatTest] -> TR ()Source

Signals that test execution is about to start.

type ReportTestStart = FlatTest -> TR ()Source

Reports the start of a single test.

type ReportTestResult = FlatTestResult -> TR ()Source

Reports the result of a single test.

type ReportGlobalResults = ReportGlobalResultsArg -> TR ()Source

Reports the overall results of all tests.

data TestReporter Source

A TestReporter provides hooks to customize the output of HTF.




tr_id :: String
tr_reportAllTests :: ReportAllTests

Called to report the IDs of all tests available.

tr_reportGlobalStart :: ReportGlobalStart

Called to report the start of test execution.

tr_reportTestStart :: ReportTestStart

Called to report the start of a single test.

tr_reportTestResult :: ReportTestResult

Called to report the result of a single test.

tr_reportGlobalResults :: ReportGlobalResults

Called to report the overall results of all tests.

type CallStack = [(Maybe String, Location)]Source

A type for call-stacks

Specifying results.

data TestResult Source

The summary result of a test.



type FlatTestResult = GenFlatTest RunResultSource

The result of running a FlatTest

type Milliseconds = IntSource

A type synonym for time in milliseconds.

data RunResult Source

The result of a test run.




rr_result :: TestResult

The summary result of the test.

rr_location :: Maybe Location

The location where the test failed (if applicable).

rr_callers :: CallStack

Information about the callers of the location where the test failed

rr_message :: ColorString

A message describing the result.

rr_wallTimeMs :: Milliseconds

Execution time in milliseconds.

rr_timeout :: Bool

True if the execution took too long