| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.HMock.TH
Description
This module provides Template Haskell splices that can be used to derive boilerplate instances for HMock.
There are 20 splices described here, based on combinations of four choices:
- Whether to generate a
MockableBase, an instance forMockT, or both. - When generating
MockableBase, whether to also generate aMockableinstance with an empty setup. - Whether the argument is a class name, or a type which may be partially applied to concrete arguments.
- Whether options are passed to customize the behavior.
Synopsis
- data MockableOptions = MockableOptions {
- mockSuffix :: String
- mockVerbose :: Bool
- makeMockable :: Name -> Q [Dec]
- makeMockableType :: Q Type -> Q [Dec]
- makeMockableWithOptions :: MockableOptions -> Name -> Q [Dec]
- makeMockableTypeWithOptions :: MockableOptions -> Q Type -> Q [Dec]
- makeMockableBase :: Name -> Q [Dec]
- makeMockableBaseType :: Q Type -> Q [Dec]
- makeMockableBaseWithOptions :: MockableOptions -> Name -> Q [Dec]
- makeMockableBaseTypeWithOptions :: MockableOptions -> Q Type -> Q [Dec]
- deriveMockable :: Name -> Q [Dec]
- deriveMockableType :: Q Type -> Q [Dec]
- deriveMockableWithOptions :: MockableOptions -> Name -> Q [Dec]
- deriveMockableTypeWithOptions :: MockableOptions -> Q Type -> Q [Dec]
- deriveMockableBase :: Name -> Q [Dec]
- deriveMockableBaseType :: Q Type -> Q [Dec]
- deriveMockableBaseWithOptions :: MockableOptions -> Name -> Q [Dec]
- deriveMockableBaseTypeWithOptions :: MockableOptions -> Q Type -> Q [Dec]
- deriveForMockT :: Name -> Q [Dec]
- deriveTypeForMockT :: Q Type -> Q [Dec]
- deriveForMockTWithOptions :: MockableOptions -> Name -> Q [Dec]
- deriveTypeForMockTWithOptions :: MockableOptions -> Q Type -> Q [Dec]
Documentation
data MockableOptions Source #
Custom options for deriving a Mockable class.
Constructors
| MockableOptions | |
Fields
| |
Instances
| Default MockableOptions Source # | |
Defined in Test.HMock.TH Methods def :: MockableOptions # | |
makeMockable :: Name -> Q [Dec] Source #
Define all instances necessary to use HMock with the given class.
Equivalent to both deriveMockable and deriveForMockT.
If MyClass is a class and myMethod is one of its methods, then
generates all of the following:makeMockable MyClass
If MyClass is a class and myMethod is one of its methods, then
generates everything generated by
makeMockable MyClassmakeMockableBase, as well as a Mockable instance that does no setup.
makeMockableType :: Q Type -> Q [Dec] Source #
Define all instances necessary to use HMock with the given constraint type,
which should be a class applied to zero or more type arguments. Equivalent
to both deriveMockableType and deriveTypeForMockT.
See makeMockable for a list of what is generated by this splice.
makeMockableWithOptions :: MockableOptions -> Name -> Q [Dec] Source #
Define all instances necessary to use HMock with the given class. This is
like makeMockable, but with the ability to specify custom options.
See makeMockable for a list of what is generated by this splice.
makeMockableTypeWithOptions :: MockableOptions -> Q Type -> Q [Dec] Source #
Define all instances necessary to use HMock with the given constraint type,
which should be a class applied to zero or more type arguments. This is
like makeMockableType, but with the ability to specify custom options.
See makeMockable for a list of what is generated by this splice.
makeMockableBase :: Name -> Q [Dec] Source #
Defines almost all instances necessary to use HMock with the given class.
Equivalent to both deriveMockableBase and deriveForMockT.
makeMockableBaseType :: Q Type -> Q [Dec] Source #
Defines almost all instances necessary to use HMock with the given
constraint type, which should be a class applied to zero or more type
arguments. Equivalent to both deriveMockableBaseType and
deriveTypeForMockT.
makeMockableBaseWithOptions :: MockableOptions -> Name -> Q [Dec] Source #
Defines almost all instances necessary to use HMock with the given class.
This is like makeMockable, but with the ability to specify custom options.
makeMockableBaseTypeWithOptions :: MockableOptions -> Q Type -> Q [Dec] Source #
Defines almost all instances necessary to use HMock with the given
constraint type, which should be a class applied to zero or more type
arguments. This is like makeMockableType, but with the ability to specify
custom options.
deriveMockable :: Name -> Q [Dec] Source #
Defines the Mockable instance for the given class.
If MyClass is a class and myMethod is one of its methods, then
generates everything generated by
deriveMockable MyClassmakeMockableBase, as well as a Mockable instance that does no setup.
deriveMockableType :: Q Type -> Q [Dec] Source #
Defines the Mockable instance for the given constraint type, which should
be a class applied to zero or more type arguments.
See deriveMockable for a list of what is generated by this splice.
deriveMockableWithOptions :: MockableOptions -> Name -> Q [Dec] Source #
Defines the Mockable instance for the given class. This is like
deriveMockable, but with the ability to specify custom options.
See deriveMockable for a list of what is generated by this splice.
deriveMockableTypeWithOptions :: MockableOptions -> Q Type -> Q [Dec] Source #
Defines the Mockable instance for the given constraint type, which should
be a class applied to zero or more type arguments. This is like
deriveMockableType, but with the ability to specify custom options.
See deriveMockable for a list of what is generated by this splice.
deriveMockableBase :: Name -> Q [Dec] Source #
Defines the MockableBase instance for the given class.
If MyClass is a class and myMethod is one of its methods, then
generates all of the following:deriveMockableBase MyClass
- A
instance.MockableBaseMyClass - An associated type
, with a constructorActionMyClassMyMethod. - An associated type
, with a constructorMatcherMyClassMyMethod_. - An
Expectableinstance forwhich matches an exact set of arguments, if and only if all ofActionMyClassmyMethod's arguments haveEqandShowinstances.
deriveMockableBaseType :: Q Type -> Q [Dec] Source #
Defines the MockableBase instance for the given constraint type, which
should be a class applied to zero or more type arguments.
See deriveMockableBase for a list of what is generated by this splice.
deriveMockableBaseWithOptions :: MockableOptions -> Name -> Q [Dec] Source #
Defines the MockableBase instance for the given class. This is like
deriveMockableBase, but with the ability to specify custom options.
See deriveMockableBase for a list of what is generated by this splice.
deriveMockableBaseTypeWithOptions :: MockableOptions -> Q Type -> Q [Dec] Source #
Defines the MockableBase instance for the given constraint type, which
should be a class applied to zero or more type arguments. This is like
deriveMockableBaseType, but with the ability to specify custom options.
See deriveMockableBase for a list of what is generated by this splice.
deriveForMockT :: Name -> Q [Dec] Source #
Defines an instance of the given class for , delegating all of
its methods to MockT mmockMethod to be handled by HMock.
This may only be used if all members of the class are mockable methods. If the class contains some unmockable methods, associated types, or other members, you will need to define this instance yourself, delegating the mockable methods as follows:
instance MyClass (MockTm) where myMethod x y =mockMethod(MyMethod x y) ...
deriveTypeForMockT :: Q Type -> Q [Dec] Source #
Defines an instance of the given constraint type for ,
delegating all of its methods to MockT mmockMethod to be handled by HMock.
The type should be a class applied to zero or more type arguments.
See deriveForMockT for restrictions on the use of this splice.
deriveForMockTWithOptions :: MockableOptions -> Name -> Q [Dec] Source #
Defines an instance of the given class for , delegating all of
its methods to MockT mmockMethod to be handled by HMock. This is like
deriveForMockT, but with the ability to specify custom options.
See deriveForMockT for restrictions on the use of this splice.
deriveTypeForMockTWithOptions :: MockableOptions -> Q Type -> Q [Dec] Source #
Defines an instance of the given constraint type for ,
delegating all of its methods to MockT mmockMethod to be handled by HMock.
The type should be a class applied to zero or more type arguments. This is
like deriveTypeForMockT, but with the ability to specify custom options.
See deriveForMockT for restrictions on the use of this splice.