| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.MockCat.Verify
Synopsis
- verify :: (ResolvableMock m, Eq (ResolvableParamsOf m), Show (ResolvableParamsOf m)) => m -> VerifyMatchType (ResolvableParamsOf m) -> IO ()
- doVerify :: (Eq a, Show a) => Maybe MockName -> InvocationList a -> VerifyMatchType a -> Maybe VerifyFailed
- readInvocationList :: TVar (InvocationRecord params) -> IO (InvocationList params)
- verifyResolvedAny :: ResolvedMock params -> IO ()
- compareCount :: CountVerifyMethod -> Int -> Bool
- verifyCount :: (ResolvableMock m, Eq (ResolvableParamsOf m)) => m -> ResolvableParamsOf m -> CountVerifyMethod -> IO ()
- countWithArgsMismatchMessage :: Maybe MockName -> CountVerifyMethod -> Int -> String
- verifyOrder :: (ResolvableMock m, Eq (ResolvableParamsOf m), Show (ResolvableParamsOf m)) => VerifyOrderMethod -> m -> [ResolvableParamsOf m] -> IO ()
- doVerifyOrder :: (Eq a, Show a) => VerifyOrderMethod -> Maybe MockName -> InvocationList a -> [a] -> Maybe VerifyFailed
- verifyFailedPartiallySequence :: Show a => Maybe MockName -> InvocationList a -> [a] -> VerifyFailed
- isOrderNotMatched :: Eq a => InvocationList a -> [a] -> Bool
- verifyFailedOrderParamCountMismatch :: Maybe MockName -> InvocationList a -> [a] -> VerifyFailed
- verifyFailedSequence :: Show a => Maybe MockName -> [VerifyOrderResult a] -> VerifyFailed
- collectUnExpectedOrder :: Eq a => InvocationList a -> [a] -> [VerifyOrderResult a]
- mapWithIndex :: (Int -> a -> b) -> [a] -> [b]
- type family PrependParam a rest where ...
- type family FunctionParams fn where ...
- type family ResolvableParamsOf target where ...
- type family Or (a :: Bool) (b :: Bool) :: Bool where ...
- type family Not (a :: Bool) :: Bool where ...
- type family IsFunctionType target :: Bool where ...
- type family IsIOType target :: Bool where ...
- type family IsPureConstant target :: Bool where ...
- type family RequireCallable (fn :: Symbol) target where ...
- type family RequireCallableImpl (fn :: Symbol) (isPure :: Bool) target where ...
- type ResolvableMock m = (Typeable (ResolvableParamsOf m), Typeable (InvocationRecorder (ResolvableParamsOf m)))
- type ResolvableMockWithParams m params = (ResolvableParamsOf m ~ params, ResolvableMock m)
- resolveForVerification :: forall target params. (params ~ ResolvableParamsOf target, Typeable params, Typeable (InvocationRecorder params)) => target -> IO (Maybe (Maybe MockName, InvocationRecorder params))
- verifyCallCount :: Maybe MockName -> InvocationRecorder params -> CountVerifyMethod -> IO ()
- countMismatchMessage :: Maybe MockName -> CountVerifyMethod -> Int -> String
- verificationFailure :: IO a
- data ResolvedMock params = ResolvedMock {}
- requireResolved :: forall target params. (params ~ ResolvableParamsOf target, Typeable params, Typeable (InvocationRecorder params)) => target -> IO (ResolvedMock params)
- verificationFailureMessage :: String
- data VerificationSpec params where
- CountVerification :: forall params. CountVerifyMethod -> params -> VerificationSpec params
- CountAnyVerification :: forall params. CountVerifyMethod -> VerificationSpec params
- OrderVerification :: forall params. VerifyOrderMethod -> [params] -> VerificationSpec params
- SimpleVerification :: forall params. params -> VerificationSpec params
- AnyVerification :: forall params. VerificationSpec params
- newtype TimesSpec = TimesSpec CountVerifyMethod
- times :: Int -> TimesSpec
- atLeast :: Int -> TimesSpec
- atMost :: Int -> TimesSpec
- greaterThan :: Int -> TimesSpec
- lessThan :: Int -> TimesSpec
- once :: TimesSpec
- never :: TimesSpec
- newtype OrderSpec = OrderSpec VerifyOrderMethod
- inOrder :: OrderSpec
- inPartialOrder :: OrderSpec
- calledWith :: params -> VerificationSpec params
- anything :: VerificationSpec params
- class WithArgs spec params where
- type WithResult spec params
- with :: spec -> params -> WithResult spec params
- type family NormalizeWithArg a where ...
- class ToNormalizedArg a where
- toNormalizedArg :: a -> NormalizeWithArg a
- withArgs :: (ToNormalizedArg params, Eq (NormalizeWithArg params), Show (NormalizeWithArg params)) => TimesSpec -> params -> VerificationSpec (NormalizeWithArg params)
- inOrderWith :: (ToNormalizedArg params, Eq (NormalizeWithArg params), Show (NormalizeWithArg params)) => [params] -> VerificationSpec (NormalizeWithArg params)
- inPartialOrderWith :: (ToNormalizedArg params, Eq (NormalizeWithArg params), Show (NormalizeWithArg params)) => [params] -> VerificationSpec (NormalizeWithArg params)
- class ShouldBeCalled m spec where
- shouldBeCalled :: m -> spec -> IO ()
Documentation
verify :: (ResolvableMock m, Eq (ResolvableParamsOf m), Show (ResolvableParamsOf m)) => m -> VerifyMatchType (ResolvableParamsOf m) -> IO () Source #
Class for verifying mock function.
doVerify :: (Eq a, Show a) => Maybe MockName -> InvocationList a -> VerifyMatchType a -> Maybe VerifyFailed Source #
readInvocationList :: TVar (InvocationRecord params) -> IO (InvocationList params) Source #
verifyResolvedAny :: ResolvedMock params -> IO () Source #
Verify that a resolved mock function was called at least once. This is used internally by typeclass mock verification.
compareCount :: CountVerifyMethod -> Int -> Bool Source #
verifyCount :: (ResolvableMock m, Eq (ResolvableParamsOf m)) => m -> ResolvableParamsOf m -> CountVerifyMethod -> IO () Source #
countWithArgsMismatchMessage :: Maybe MockName -> CountVerifyMethod -> Int -> String Source #
Generate error message for count mismatch with arguments
verifyOrder :: (ResolvableMock m, Eq (ResolvableParamsOf m), Show (ResolvableParamsOf m)) => VerifyOrderMethod -> m -> [ResolvableParamsOf m] -> IO () Source #
doVerifyOrder :: (Eq a, Show a) => VerifyOrderMethod -> Maybe MockName -> InvocationList a -> [a] -> Maybe VerifyFailed Source #
verifyFailedPartiallySequence :: Show a => Maybe MockName -> InvocationList a -> [a] -> VerifyFailed Source #
isOrderNotMatched :: Eq a => InvocationList a -> [a] -> Bool Source #
verifyFailedOrderParamCountMismatch :: Maybe MockName -> InvocationList a -> [a] -> VerifyFailed Source #
verifyFailedSequence :: Show a => Maybe MockName -> [VerifyOrderResult a] -> VerifyFailed Source #
collectUnExpectedOrder :: Eq a => InvocationList a -> [a] -> [VerifyOrderResult a] Source #
mapWithIndex :: (Int -> a -> b) -> [a] -> [b] Source #
type family PrependParam a rest where ... Source #
Equations
| PrependParam a () = Param a | |
| PrependParam a rest = Param a :> rest |
type family FunctionParams fn where ... Source #
Equations
| FunctionParams (a -> fn) = PrependParam a (FunctionParams fn) | |
| FunctionParams fn = () |
type family ResolvableParamsOf target where ... Source #
Equations
| ResolvableParamsOf (a -> fn) = FunctionParams (a -> fn) | |
| ResolvableParamsOf target = () |
type family IsFunctionType target :: Bool where ... Source #
Equations
| IsFunctionType (_a -> _b) = 'True | |
| IsFunctionType _1 = 'False |
type family IsPureConstant target :: Bool where ... Source #
Equations
| IsPureConstant target = Not (Or (IsFunctionType target) (IsIOType target)) |
type family RequireCallable (fn :: Symbol) target where ... Source #
Equations
| RequireCallable fn target = RequireCallableImpl fn (IsPureConstant target) target |
type family RequireCallableImpl (fn :: Symbol) (isPure :: Bool) target where ... Source #
Equations
| RequireCallableImpl fn 'True target = TypeError ((('Text fn ':<>: 'Text " is not available for pure constant mocks.") ':$$: ('Text " target type: " ':<>: 'ShowType target)) ':$$: 'Text " hint: convert it into a callable mock or use shouldBeCalled with 'anything'.") :: Constraint | |
| RequireCallableImpl _1 'False _2 = () |
type ResolvableMock m = (Typeable (ResolvableParamsOf m), Typeable (InvocationRecorder (ResolvableParamsOf m))) Source #
Constraint alias for resolvable mock types.
type ResolvableMockWithParams m params = (ResolvableParamsOf m ~ params, ResolvableMock m) Source #
Constraint alias for resolvable mock types with specific params.
resolveForVerification :: forall target params. (params ~ ResolvableParamsOf target, Typeable params, Typeable (InvocationRecorder params)) => target -> IO (Maybe (Maybe MockName, InvocationRecorder params)) Source #
verifyCallCount :: Maybe MockName -> InvocationRecorder params -> CountVerifyMethod -> IO () Source #
Verify that a function was called the expected number of times
countMismatchMessage :: Maybe MockName -> CountVerifyMethod -> Int -> String Source #
Generate error message for count mismatch
verificationFailure :: IO a Source #
data ResolvedMock params Source #
Constructors
| ResolvedMock | |
Fields
| |
requireResolved :: forall target params. (params ~ ResolvableParamsOf target, Typeable params, Typeable (InvocationRecorder params)) => target -> IO (ResolvedMock params) Source #
data VerificationSpec params where Source #
Verification specification for shouldBeCalled
Constructors
| CountVerification :: forall params. CountVerifyMethod -> params -> VerificationSpec params | Count verification with specific arguments |
| CountAnyVerification :: forall params. CountVerifyMethod -> VerificationSpec params | Count verification without arguments (any arguments) |
| OrderVerification :: forall params. VerifyOrderMethod -> [params] -> VerificationSpec params | Order verification |
| SimpleVerification :: forall params. params -> VerificationSpec params | Simple verification with arguments (at least once) |
| AnyVerification :: forall params. VerificationSpec params | Simple verification without arguments (at least once, any arguments) |
Instances
| (ResolvableMockWithParams m params, Eq params, Show params, RequireCallable "shouldBeCalled" m) => ShouldBeCalled m (VerificationSpec params) Source # | Instance for VerificationSpec (handles all verification types) |
Defined in Test.MockCat.Verify Methods shouldBeCalled :: m -> VerificationSpec params -> IO () Source # | |
Times condition for count verification
Constructors
| TimesSpec CountVerifyMethod |
Instances
| (ResolvableMockWithParams m params, RequireCallable "shouldBeCalled" m) => ShouldBeCalled m TimesSpec Source # | Instance for times spec alone (without arguments) | ||||
Defined in Test.MockCat.Verify Methods shouldBeCalled :: m -> TimesSpec -> IO () Source # | |||||
| (Eq params, Show params) => WithArgs TimesSpec params Source # | Instance for times condition with arguments | ||||
Defined in Test.MockCat.Verify Associated Types
| |||||
| type WithResult TimesSpec params Source # | |||||
Defined in Test.MockCat.Verify | |||||
times :: Int -> TimesSpec Source #
Create a times condition for exact count.
f `shouldBeCalled` times 3 f `shouldBeCalled` (times 3 `with` "arg")
atLeast :: Int -> TimesSpec Source #
Create a times condition for at least count (>=).
f `shouldBeCalled` atLeast 1
atMost :: Int -> TimesSpec Source #
Create a times condition for at most count (<=).
f `shouldBeCalled` atMost 2
greaterThan :: Int -> TimesSpec Source #
Create a times condition for greater than count (>).
Create a times condition for never (zero times). Equivalent to 'times 0'.
Order condition for order verification
Constructors
| OrderSpec VerifyOrderMethod |
inPartialOrder :: OrderSpec Source #
Create an order condition for partial sequence
calledWith :: params -> VerificationSpec params Source #
Create a simple verification with arguments. This accepts both raw values and Param chains.
f `shouldBeCalled` calledWith "a"
anything :: VerificationSpec params Source #
Create a simple verification without arguments. It verifies that the function was called at least once, with ANY arguments.
f `shouldBeCalled` anything
class WithArgs spec params where Source #
Type class for combining times condition with arguments
Associated Types
type WithResult spec params Source #
Methods
with :: spec -> params -> WithResult spec params Source #
Instances
| (Eq params, Show params) => WithArgs TimesSpec params Source # | Instance for times condition with arguments | ||||
Defined in Test.MockCat.Verify Associated Types
| |||||
type family NormalizeWithArg a where ... Source #
Type family to normalize argument types for withArgs
Equations
| NormalizeWithArg (Param a :> rest) = Param a :> rest | |
| NormalizeWithArg (Param a) = Param a | |
| NormalizeWithArg a = Param a |
class ToNormalizedArg a where Source #
Type class to normalize argument types (to Param or Param chain)
Methods
toNormalizedArg :: a -> NormalizeWithArg a Source #
Instances
| (NormalizeWithArg a ~ Param a, WrapParam a) => ToNormalizedArg a Source # | |
Defined in Test.MockCat.Verify Methods toNormalizedArg :: a -> NormalizeWithArg a Source # | |
| ToNormalizedArg (Param a) Source # | |
Defined in Test.MockCat.Verify Methods toNormalizedArg :: Param a -> NormalizeWithArg (Param a) Source # | |
| ToNormalizedArg (Param a :> rest) Source # | |
Defined in Test.MockCat.Verify Methods toNormalizedArg :: (Param a :> rest) -> NormalizeWithArg (Param a :> rest) Source # | |
withArgs :: (ToNormalizedArg params, Eq (NormalizeWithArg params), Show (NormalizeWithArg params)) => TimesSpec -> params -> VerificationSpec (NormalizeWithArg params) infixl 8 Source #
inOrderWith :: (ToNormalizedArg params, Eq (NormalizeWithArg params), Show (NormalizeWithArg params)) => [params] -> VerificationSpec (NormalizeWithArg params) Source #
Verify that the mock was called with the specified sequence of arguments in exact order.
f `shouldBeCalled` inOrderWith ["a", "b"]
inPartialOrderWith :: (ToNormalizedArg params, Eq (NormalizeWithArg params), Show (NormalizeWithArg params)) => [params] -> VerificationSpec (NormalizeWithArg params) Source #
Verify that the mock was called with the specified sequence of arguments, allowing other calls in between.
f `shouldBeCalled` inPartialOrderWith ["a", "c"] -- This passes if calls were: "a", "b", "c"
class ShouldBeCalled m spec where Source #
Main verification function class
Methods
shouldBeCalled :: m -> spec -> IO () Source #
Instances
| (ResolvableMockWithParams m params, RequireCallable "shouldBeCalled" m) => ShouldBeCalled m TimesSpec Source # | Instance for times spec alone (without arguments) |
Defined in Test.MockCat.Verify Methods shouldBeCalled :: m -> TimesSpec -> IO () Source # | |
| (ResolvableMockWithParams m (Param a), Eq (Param a), Show (Param a), Show a, Eq a) => ShouldBeCalled m a Source # | Instance for raw values (e.g., "a") This converts raw values to Param at runtime |
Defined in Test.MockCat.Verify Methods shouldBeCalled :: m -> a -> IO () Source # | |
| (ResolvableMockWithParams m (Param a), Eq (Param a), Show (Param a)) => ShouldBeCalled m (Param a) Source # | Instance for single Param (e.g., param "a") |
Defined in Test.MockCat.Verify Methods shouldBeCalled :: m -> Param a -> IO () Source # | |
| (ResolvableMockWithParams m params, Eq params, Show params, RequireCallable "shouldBeCalled" m) => ShouldBeCalled m (VerificationSpec params) Source # | Instance for VerificationSpec (handles all verification types) |
Defined in Test.MockCat.Verify Methods shouldBeCalled :: m -> VerificationSpec params -> IO () Source # | |
| (ResolvableMockWithParams m (Param a :> rest), Eq (Param a :> rest), Show (Param a :> rest)) => ShouldBeCalled m (Param a :> rest) Source # | Instance for Param chains (e.g., "a" ~> "b") |
Defined in Test.MockCat.Verify | |