| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Skeletest.Hooks
Description
The module that contains everything needed to implement custom hooks.
Synopsis
- data Hooks = Hooks {}
- data Hook ctx inp out
- defaultHooks :: Hooks
- type ModifySpecRegistryHook = Hook ModifySpecRegistryHookContext SpecRegistry SpecRegistry
- data ModifySpecRegistryHookContext = ModifySpecRegistryHookContext {}
- type RunTestHook = Hook RunTestHookContext () TestResult
- data RunTestHookContext = RunTestHookContext {}
- type OnTestFailureHook = Hook OnTestFailureHookContext SomeException TestResult
- data OnTestFailureHookContext = OnTestFailureHookContext {}
- type RunSpecsHook = Hook RunSpecsHookContext SpecRegistry TestExitCode
- data RunSpecsHookContext = RunSpecsHookContext
- type ModifyTestSummaryHook = Hook ModifyTestSummaryHookContext Text Text
- data ModifyTestSummaryHookContext = ModifyTestSummaryHookContext
- runEarly :: Hook ctx inp out -> Hook ctx inp out
- runLate :: Hook ctx inp out -> Hook ctx inp out
- mkHook :: (ctx -> (inp -> IO out) -> inp -> IO out) -> Hook ctx inp out
- mkHook_ :: (ctx -> inp -> IO ()) -> (ctx -> inp -> out -> IO ()) -> Hook ctx inp out
- mkPreHook :: (ctx -> inp -> IO inp) -> Hook ctx inp out
- mkPreHook_ :: (ctx -> inp -> IO ()) -> Hook ctx inp out
- mkPostHook :: (ctx -> inp -> out -> IO out) -> Hook ctx inp out
- mkPostHook_ :: (ctx -> inp -> out -> IO ()) -> Hook ctx inp out
- data TestResult = TestResult {}
- data TestResultMessage
- type BoxSpec = [BoxSpecContent]
- data BoxSpecContent
- data TestInfo = TestInfo {}
- findMarker :: IsMarker a => [SomeMarker] -> Maybe a
- hasMarker :: IsMarker a => [SomeMarker] -> Bool
- hasMarkerNamed :: String -> [SomeMarker] -> Bool
- type SpecRegistry = [SpecInfo]
- type Spec = SpecM ()
- data SpecInfo = SpecInfo {}
- data SpecTree
- = SpecTree_Group { }
- | SpecTree_Test SpecTest
- data SpecTest = SpecTest {
- name :: Text
- markers :: [SomeMarker]
- action :: IO TestResult
- getSpecTrees :: Spec -> [SpecTree]
- withSpecTrees :: Monad m => ([SpecTree] -> m [SpecTree]) -> Spec -> m Spec
- mapSpecTrees :: ((SpecTree -> SpecTree) -> [SpecTree] -> [SpecTree]) -> Spec -> Spec
- traverseSpecTrees :: Monad m => ((SpecTree -> m SpecTree) -> [SpecTree] -> m [SpecTree]) -> Spec -> m Spec
- mapSpecTests :: (SpecTest -> SpecTest) -> Spec -> Spec
- traverseSpecTests :: Monad m => (SpecTest -> m SpecTest) -> Spec -> m Spec
- filterSpecTests :: (SpecTest -> Bool) -> Spec -> Spec
- mapSpecs :: (Spec -> Spec) -> SpecRegistry -> SpecRegistry
- traverseSpecs :: Applicative f => (Spec -> f Spec) -> SpecRegistry -> f SpecRegistry
Hooks
Hooks for extending Skeletest.
Use defaultHooks instead of using Hooks directly, to minimize
breaking changes.
Constructors
| 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
ctxwith extra read-only information that may be relevant for the hook. - The hook takes an action of type
inp -> IO outand 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.
defaultHooks :: Hooks Source #
Specific hooks
modifySpecRegistry
type ModifySpecRegistryHook = Hook ModifySpecRegistryHookContext SpecRegistry SpecRegistry Source #
Modify the specs in the test suite.
data ModifySpecRegistryHookContext Source #
Constructors
| ModifySpecRegistryHookContext | |
Fields | |
runTest
type RunTestHook = Hook RunTestHookContext () TestResult Source #
Modify how a test is executed
data RunTestHookContext Source #
Constructors
| RunTestHookContext | |
onTestFailure
type OnTestFailureHook = Hook OnTestFailureHookContext SomeException TestResult Source #
Modify what happens if a test fails.
data OnTestFailureHookContext Source #
Constructors
| OnTestFailureHookContext | |
runSpecs
type RunSpecsHook = Hook RunSpecsHookContext SpecRegistry TestExitCode Source #
Modify the action to run specs.
data RunSpecsHookContext Source #
Constructors
| RunSpecsHookContext |
modifyTestSummary
type ModifyTestSummaryHook = Hook ModifyTestSummaryHookContext Text Text Source #
Modify the test summary at the end of the report.
data ModifyTestSummaryHookContext Source #
Constructors
| ModifyTestSummaryHookContext |
Implementing a hook
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 #
Constructors
| TestResult | |
Fields
| |
Instances
| HasField "reportTestPost" TestReporter (TestInfo -> (TestResult, NominalDiffTime) -> IO ()) Source # | |
Defined in Skeletest.Internal.Spec.TestReporter Methods getField :: TestReporter -> TestInfo -> (TestResult, NominalDiffTime) -> IO () # | |
data TestResultMessage Source #
type BoxSpec = [BoxSpecContent] Source #
The specification for boxed output.
data BoxSpecContent Source #
Instances
| Show BoxSpecContent Source # | |
Defined in Skeletest.Internal.Spec.Output Methods showsPrec :: Int -> BoxSpecContent -> ShowS # show :: BoxSpecContent -> String # showList :: [BoxSpecContent] -> ShowS # | |
| Eq BoxSpecContent Source # | |
Defined in Skeletest.Internal.Spec.Output Methods (==) :: BoxSpecContent -> BoxSpecContent -> Bool # (/=) :: BoxSpecContent -> BoxSpecContent -> Bool # | |
TestInfo
Constructors
| TestInfo | |
Fields
| |
Instances
Markers
findMarker :: IsMarker a => [SomeMarker] -> Maybe a Source #
Find the first marker in the given list with the given type.
hasMarkerNamed :: String -> [SomeMarker] -> Bool Source #
Return true if the given marker name is present.
SpecRegistry
type SpecRegistry = [SpecInfo] Source #
Instances
| HasField "run" SpecRunner (SpecRegistry -> IO TestExitCode) Source # | |
Defined in Skeletest.Internal.Spec Methods getField :: SpecRunner -> SpecRegistry -> IO TestExitCode # | |
| HasField "runFile" SpecRunner (SpecInfo -> IO TestExitCode) Source # | |
Defined in Skeletest.Internal.Spec Methods getField :: SpecRunner -> SpecInfo -> IO TestExitCode # | |
Constructors
| SpecTree_Group | |
| SpecTree_Test SpecTest | |
Instances
| HasField "runGroup" SpecRunner (TestInfo -> Text -> [SpecTree] -> IO TestExitCode) Source # | |
Defined in Skeletest.Internal.Spec Methods getField :: SpecRunner -> TestInfo -> Text -> [SpecTree] -> IO TestExitCode # | |
| HasField "runTrees" SpecRunner (TestInfo -> [SpecTree] -> IO TestExitCode) Source # | |
Defined in Skeletest.Internal.Spec Methods getField :: SpecRunner -> TestInfo -> [SpecTree] -> IO TestExitCode # | |
Constructors
| SpecTest | |
Fields
| |
Instances
| HasField "runTest" SpecRunner (TestInfo -> SpecTest -> IO TestExitCode) Source # | |
Defined in Skeletest.Internal.Spec Methods getField :: SpecRunner -> TestInfo -> SpecTest -> IO TestExitCode # | |
getSpecTrees :: Spec -> [SpecTree] 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
mapSpecs :: (Spec -> Spec) -> SpecRegistry -> SpecRegistry Source #
traverseSpecs :: Applicative f => (Spec -> f Spec) -> SpecRegistry -> f SpecRegistry Source #