| Copyright | © 2018-2020 IOHK |
|---|---|
| License | Apache-2.0 |
| Safe Haskell | None |
| Language | Haskell2010 |
Test.Utils.Trace
Description
Provides functions for setting up and capturing logging so that expectations about logging can be asserted in test scenarios.
Documentation
withLogging :: ((Tracer IO msg, IO [msg]) -> IO a) -> IO a Source #
Run an action with a logging Trace object, and a function to get all
messages that have been traced.
captureLogging :: (Tracer IO msg -> IO a) -> IO ([msg], a) Source #
Run an action with a Trace, returning captured log messages along with
the result of the action.
countMsg :: Prism' s a -> [s] -> Int Source #
Count elements in the list matching the given Prism. Handy for counting log messages which are typically constructed as sum types with many constructors.
A Prism look scary but can be obtained very easily if the target type is
deriving Generic. From there, use
`Data.Generics.Sum.Constructor#_Ctor` from `generic-lens`.
Example:
>>>data MySumType = MyConstructor | MyOtherConstructor deriving Generic
>>>xs = [ MyConstructor, MyOtherConstructor, MyConstructor ]
>>>count (_Ctor @"MyConstructor") xs2