skeletest-0.4.0: Batteries-included, opinionated test framework
Safe HaskellNone
LanguageGHC2021

Skeletest.Internal.Hooks

Synopsis

Documentation

data Hooks Source #

Hooks for extending Skeletest.

Use defaultHooks instead of using Hooks directly, to minimize breaking changes.

Instances

Instances details
Monoid Hooks Source # 
Instance details

Defined in Skeletest.Internal.Hooks

Methods

mempty :: Hooks #

mappend :: Hooks -> Hooks -> Hooks #

mconcat :: [Hooks] -> Hooks #

Semigroup Hooks Source # 
Instance details

Defined in Skeletest.Internal.Hooks

Methods

(<>) :: Hooks -> Hooks -> Hooks #

sconcat :: NonEmpty Hooks -> Hooks #

stimes :: Integral b => b -> Hooks -> Hooks #

Runtime

data UserHooks Source #

Instances

Instances details
HasField field Hooks (Hook ctx inp out) => HasField (field :: k) UserHooks (ctx -> inp -> (inp -> IO out) -> IO out) Source # 
Instance details

Defined in Skeletest.Internal.Hooks

Methods

getField :: UserHooks -> ctx -> inp -> (inp -> IO out) -> IO out #

Hook implementation

newtype Hook ctx inp out Source #

The implementation of a Skeletest hook in Hooks.

A hook of type Hook ctx inp out means:

  • The hook takes a value of type ctx with extra read-only information that may be relevant for the hook.
  • The hook takes an action of type inp -> IO out and returns a potentially modified action of the same type.

ctx/inp should generally be accessed with OverloadedRecordDot or record destructuring, to minimize breaking changes when adding fields to them.

Constructors

Hook [HookDef ctx inp out] 

Instances

Instances details
Monoid (Hook ctx inp out) Source # 
Instance details

Defined in Skeletest.Internal.Hooks.HookDef

Methods

mempty :: Hook ctx inp out #

mappend :: Hook ctx inp out -> Hook ctx inp out -> Hook ctx inp out #

mconcat :: [Hook ctx inp out] -> Hook ctx inp out #

Semigroup (Hook ctx inp out) Source # 
Instance details

Defined in Skeletest.Internal.Hooks.HookDef

Methods

(<>) :: Hook ctx inp out -> Hook ctx inp out -> Hook ctx inp out #

sconcat :: NonEmpty (Hook ctx inp out) -> Hook ctx inp out #

stimes :: Integral b => b -> Hook ctx inp out -> Hook ctx inp out #

data HookDef ctx inp out Source #

Constructors

HookDef 

Fields

runHook :: Hook ctx inp out -> ctx -> inp -> (inp -> IO out) -> IO out Source #

Hook DSL

runEarly :: Hook ctx inp out -> Hook ctx inp out Source #

Run the given hook earlier if possible.

runLate :: Hook ctx inp out -> Hook ctx inp out Source #

Run the given hook later if possible.

mkHook :: (ctx -> (inp -> IO out) -> inp -> IO out) -> Hook ctx inp out Source #

Create a hook.

Example

hooks :: Hooks
hooks =
  defaultHooks
    { runSpecs = runEarly . mkHook $ ctx run -> pre >=> run >=> post
    }
  where
    pre inp = do
      inp' <- doStuff inp
      pure inp'
    post out = do
      out' <- doMoreStuff out
      pure out'

mkHook_ :: (ctx -> inp -> IO ()) -> (ctx -> inp -> out -> IO ()) -> Hook ctx inp out Source #

Like mkHook, except for read-only hooks that don't need to modify anything.

mkPreHook :: (ctx -> inp -> IO inp) -> Hook ctx inp out Source #

Like mkHook, except only supports modifying the input.

mkPreHook_ :: (ctx -> inp -> IO ()) -> Hook ctx inp out Source #

Like mkHook_, except with only a before action.

mkPostHook :: (ctx -> inp -> out -> IO out) -> Hook ctx inp out Source #

Like mkHook, except only supports modifying the output.

mkPostHook_ :: (ctx -> inp -> out -> IO ()) -> Hook ctx inp out Source #

Like mkHook_, except with only an after action.

Specific hooks

modifySpecRegistry

runTest

type RunTestHook = Hook RunTestHookContext () TestResult Source #

Modify how a test is executed

onTestFailure

runSpecs

type RunSpecsHook = Hook RunSpecsHookContext SpecRegistry TestExitCode Source #

Modify the action to run specs.

modifyTestSummary

type ModifyTestSummaryHook = Hook ModifyTestSummaryHookContext Text Text Source #

Modify the test summary at the end of the report.