Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module defines the MockableBase
and Mockable
classes that are
needed to use an MTL-style type class with MockT
. You
will typically derive MockableBase
with Template Haskell, since it's mostly
boilerplate. The Mockable
class adds a customizable setup method which you
can define yourself to add the right defaults for methods in the mocked
class.
Synopsis
- class MockableBase cls => Mockable (cls :: (Type -> Type) -> Constraint) where
- setupMockable :: (MonadIO m, Typeable m) => proxy cls -> MockSetup m ()
- class Typeable cls => MockableBase (cls :: (Type -> Type) -> Constraint) where
- data Action cls :: Symbol -> (Type -> Type) -> Type -> Type
- data Matcher cls :: Symbol -> (Type -> Type) -> Type -> Type
- showAction :: Action cls name m a -> String
- showMatcher :: Maybe (Action cls name m a) -> Matcher cls name m b -> String
- matchAction :: Matcher cls name m a -> Action cls name m a -> MatchResult
- data MatchResult where
- NoMatch :: [(Int, String)] -> MatchResult
- Match :: MatchResult
Documentation
class MockableBase cls => Mockable (cls :: (Type -> Type) -> Constraint) where Source #
A class for Monad
subclasses whose methods can be mocked. This class
augments MockableBase
with a setup method that is run before HMock touches
the Monad
subclass for the first time. The default implementation does
nothing, but you can derive your own instances that add setup behavior.
Nothing
setupMockable :: (MonadIO m, Typeable m) => proxy cls -> MockSetup m () Source #
An action to run and set up defaults for this class. The action will be run before HMock touches the class, either to add expectations or to delegate a method.
By default, unexpected actions throw errors, and actions with no explicit
default always return the default value of their return type, or
undefined
if there is none. You can change this on a per-class or
per-test basis.
- To change defaults on a per-class basis, you should use
allowUnexpected
and/orbyDefault
to perform the setup you need here. - To change defaults on a per-test basis, you should use
allowUnexpected
and/orbyDefault
directly from the test.
class Typeable cls => MockableBase (cls :: (Type -> Type) -> Constraint) where Source #
A base class for Monad
subclasses whose methods can be mocked. You
usually want to generate this instance using makeMockable
,
makeMockable
, or makeMockableWithOptions
,
since it's just boilerplate.
data Action cls :: Symbol -> (Type -> Type) -> Type -> Type Source #
An action that is performed. This data type will have one constructor for each method.
data Matcher cls :: Symbol -> (Type -> Type) -> Type -> Type Source #
A specification for matching actions. The actual arguments should be replaced with predicates.
showAction :: Action cls name m a -> String Source #
Gets a text description of an Action
, for use in error messages.
showMatcher :: Maybe (Action cls name m a) -> Matcher cls name m b -> String Source #
Gets a text description of a Matcher
, for use in error messages.
matchAction :: Matcher cls name m a -> Action cls name m a -> MatchResult Source #
data MatchResult where Source #
The result of matching a
with an Matcher
a
. Because the
types should already guarantee that the methods match, all that's left is to
match arguments.Action
b
NoMatch :: [(Int, String)] -> MatchResult | No match. The arg is explanations of mismatch. |
Match :: MatchResult | Match. Stores a witness to the equality of return types. |