mockcat-1.0.1.0: Declarative mocking with a single arrow `~>`.
Safe HaskellNone
LanguageHaskell2010

Test.MockCat.Verify

Synopsis

Documentation

verify :: (ResolvableMock m, Eq (ResolvableParamsOf m), Show (ResolvableParamsOf m)) => m -> VerifyMatchType (ResolvableParamsOf m) -> IO () Source #

Class for verifying mock function.

verifyResolvedAny :: ResolvedMock params -> IO () Source #

Verify that a resolved mock function was called at least once. This is used internally by typeclass mock verification.

countWithArgsMismatchMessage :: Maybe MockName -> CountVerifyMethod -> Int -> String Source #

Generate error message for count mismatch with arguments

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 Or (a :: Bool) (b :: Bool) :: Bool where ... Source #

Equations

Or 'True _1 = 'True 
Or _1 'True = 'True 
Or 'False 'False = 'False 

type family Not (a :: Bool) :: Bool where ... Source #

Equations

Not 'True = 'False 
Not 'False = 'True 

type family IsFunctionType target :: Bool where ... Source #

Equations

IsFunctionType (_a -> _b) = 'True 
IsFunctionType _1 = 'False 

type family IsIOType target :: Bool where ... Source #

Equations

IsIOType (IO _1) = 'True 
IsIOType _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

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

Instances details
(ResolvableMockWithParams m params, Eq params, Show params, RequireCallable "shouldBeCalled" m) => ShouldBeCalled m (VerificationSpec params) Source #

Instance for VerificationSpec (handles all verification types)

Instance details

Defined in Test.MockCat.Verify

Methods

shouldBeCalled :: m -> VerificationSpec params -> IO () Source #

newtype TimesSpec Source #

Times condition for count verification

Instances

Instances details
(ResolvableMockWithParams m params, RequireCallable "shouldBeCalled" m) => ShouldBeCalled m TimesSpec Source #

Instance for times spec alone (without arguments)

Instance details

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

Instance details

Defined in Test.MockCat.Verify

Associated Types

type WithResult TimesSpec params 
Instance details

Defined in Test.MockCat.Verify

Methods

with :: TimesSpec -> params -> WithResult TimesSpec params Source #

type WithResult TimesSpec params Source # 
Instance details

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 (>).

lessThan :: Int -> TimesSpec Source #

Create a times condition for less than count (<).

once :: TimesSpec Source #

Create a times condition for exactly once. Equivalent to 'times 1'.

never :: TimesSpec Source #

Create a times condition for never (zero times). Equivalent to 'times 0'.

newtype OrderSpec Source #

Order condition for order verification

inOrder :: OrderSpec Source #

Create an order condition for exact sequence

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

Instances details
(Eq params, Show params) => WithArgs TimesSpec params Source #

Instance for times condition with arguments

Instance details

Defined in Test.MockCat.Verify

Associated Types

type WithResult TimesSpec params 
Instance details

Defined in Test.MockCat.Verify

Methods

with :: TimesSpec -> params -> WithResult TimesSpec params Source #

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)

Instances

Instances details
(NormalizeWithArg a ~ Param a, WrapParam a) => ToNormalizedArg a Source # 
Instance details

Defined in Test.MockCat.Verify

ToNormalizedArg (Param a) Source # 
Instance details

Defined in Test.MockCat.Verify

ToNormalizedArg (Param a :> rest) Source # 
Instance details

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 #

New function for combining times condition with arguments (supports raw values) This will replace with once the old with is removed

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

Instances details
(ResolvableMockWithParams m params, RequireCallable "shouldBeCalled" m) => ShouldBeCalled m TimesSpec Source #

Instance for times spec alone (without arguments)

Instance details

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

Instance details

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")

Instance details

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)

Instance details

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")

Instance details

Defined in Test.MockCat.Verify

Methods

shouldBeCalled :: m -> (Param a :> rest) -> IO () Source #