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

Skeletest.Hooks

Description

The module that contains everything needed to implement custom hooks.

Synopsis

Hooks

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 #

data 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.

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 #

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.

Implementing a hook

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.

Re-exports

TestResult

data TestResult Source #

Instances

Instances details
HasField "reportTestPost" TestReporter (TestInfo -> (TestResult, NominalDiffTime) -> IO ()) Source # 
Instance details

Defined in Skeletest.Internal.Spec.TestReporter

type BoxSpec = [BoxSpecContent] Source #

The specification for boxed output.

TestInfo

data TestInfo Source #

Constructors

TestInfo 

Fields

Instances

Instances details
Show TestInfo Source # 
Instance details

Defined in Skeletest.Internal.TestInfo

HasField "reportGroupPost" TestReporter (TestInfo -> Text -> (TestExitCode, NominalDiffTime) -> IO ()) Source # 
Instance details

Defined in Skeletest.Internal.Spec.TestReporter

HasField "reportGroupPre" TestReporter (TestInfo -> Text -> IO ()) Source # 
Instance details

Defined in Skeletest.Internal.Spec.TestReporter

Methods

getField :: TestReporter -> TestInfo -> Text -> IO () #

HasField "reportTestPost" TestReporter (TestInfo -> (TestResult, NominalDiffTime) -> IO ()) Source # 
Instance details

Defined in Skeletest.Internal.Spec.TestReporter

HasField "reportTestPre" TestReporter (TestInfo -> IO ()) Source # 
Instance details

Defined in Skeletest.Internal.Spec.TestReporter

Methods

getField :: TestReporter -> TestInfo -> IO () #

HasField "runGroup" SpecRunner (TestInfo -> Text -> [SpecTree] -> IO TestExitCode) Source # 
Instance details

Defined in Skeletest.Internal.Spec

HasField "runTest" SpecRunner (TestInfo -> SpecTest -> IO TestExitCode) Source # 
Instance details

Defined in Skeletest.Internal.Spec

HasField "runTrees" SpecRunner (TestInfo -> [SpecTree] -> IO TestExitCode) Source # 
Instance details

Defined in Skeletest.Internal.Spec

Markers

findMarker :: IsMarker a => [SomeMarker] -> Maybe a Source #

Find the first marker in the given list with the given type.

hasMarker :: IsMarker a => [SomeMarker] -> Bool Source #

Helper for isJust . findMarker MyMarker@.

hasMarkerNamed :: String -> [SomeMarker] -> Bool Source #

Return true if the given marker name is present.

SpecRegistry

type Spec = SpecM () Source #

data SpecInfo Source #

Constructors

SpecInfo 

Fields

Instances

Instances details
HasField "run" SpecRunner (SpecRegistry -> IO TestExitCode) Source # 
Instance details

Defined in Skeletest.Internal.Spec

HasField "runFile" SpecRunner (SpecInfo -> IO TestExitCode) Source # 
Instance details

Defined in Skeletest.Internal.Spec

data SpecTree Source #

Instances

Instances details
HasField "runGroup" SpecRunner (TestInfo -> Text -> [SpecTree] -> IO TestExitCode) Source # 
Instance details

Defined in Skeletest.Internal.Spec

HasField "runTrees" SpecRunner (TestInfo -> [SpecTree] -> IO TestExitCode) Source # 
Instance details

Defined in Skeletest.Internal.Spec

data SpecTest Source #

Constructors

SpecTest 

Fields

  • name :: Text
     
  • markers :: [SomeMarker]

    Markers, in order from least to most recently applied.

    >>> withMarker MarkerA . withMarker MarkerB $ test ...
    

    will contain

    >>> SpecTree_Test { testMarkers = [MarkerA, MarkerB] }
    
  • action :: IO TestResult
     

Instances

Instances details
HasField "runTest" SpecRunner (TestInfo -> SpecTest -> IO TestExitCode) Source # 
Instance details

Defined in Skeletest.Internal.Spec

withSpecTrees :: Monad m => ([SpecTree] -> m [SpecTree]) -> Spec -> m Spec Source #

mapSpecTrees :: ((SpecTree -> SpecTree) -> [SpecTree] -> [SpecTree]) -> Spec -> Spec Source #

Map the tree with the given processing function.

To preprocess trees with pre and postprocess with post:

>>> mapSpecTrees (\go -> post . map go . pre) spec

traverseSpecTrees :: Monad m => ((SpecTree -> m SpecTree) -> [SpecTree] -> m [SpecTree]) -> Spec -> m Spec Source #

Traverse the tree with the given processing function.

To preprocess trees with pre and postprocess with post:

>>> traverseSpecTrees (\go -> post <=< mapM go <=< pre) spec