HMock-0.1.0.1: A flexible mock framework for testing effectful code.
Safe HaskellNone
LanguageHaskell2010

Test.HMock.Internal.MockT

Synopsis

Documentation

newtype MockT m a where Source #

Monad transformer for running mocks.

Constructors

MockT 

Fields

Instances

Instances details
MonadTrans MockT Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

lift :: Monad m => m a -> MockT m a #

ExpectContext MockT Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

fromExpectSet :: forall (m :: Type -> Type). MonadIO m => ExpectSet (Step m) -> MockT m () Source #

(MonadReader r m, MonadWriter w m, MonadState s m) => MonadRWS r w s (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

MonadBase b m => MonadBase b (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

liftBase :: b α -> MockT m α #

MonadWriter w m => MonadWriter w (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

writer :: (a, w) -> MockT m a #

tell :: w -> MockT m () #

listen :: MockT m a -> MockT m (a, w) #

pass :: MockT m (a, w -> w) -> MockT m a #

MonadState s m => MonadState s (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

get :: MockT m s #

put :: s -> MockT m () #

state :: (s -> (a, s)) -> MockT m a #

MonadReader r m => MonadReader r (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

ask :: MockT m r #

local :: (r -> r) -> MockT m a -> MockT m a #

reader :: (r -> a) -> MockT m a #

MonadError e m => MonadError e (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

throwError :: e -> MockT m a #

catchError :: MockT m a -> (e -> MockT m a) -> MockT m a #

Monad m => Monad (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

(>>=) :: MockT m a -> (a -> MockT m b) -> MockT m b #

(>>) :: MockT m a -> MockT m b -> MockT m b #

return :: a -> MockT m a #

Functor m => Functor (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

fmap :: (a -> b) -> MockT m a -> MockT m b #

(<$) :: a -> MockT m b -> MockT m a #

MonadFail m => MonadFail (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

fail :: String -> MockT m a #

Applicative m => Applicative (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

pure :: a -> MockT m a #

(<*>) :: MockT m (a -> b) -> MockT m a -> MockT m b #

liftA2 :: (a -> b -> c) -> MockT m a -> MockT m b -> MockT m c #

(*>) :: MockT m a -> MockT m b -> MockT m b #

(<*) :: MockT m a -> MockT m b -> MockT m a #

MonadIO m => MonadIO (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

liftIO :: IO a -> MockT m a #

MonadThrow m => MonadThrow (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

throwM :: Exception e => e -> MockT m a #

MonadCatch m => MonadCatch (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

catch :: Exception e => MockT m a -> (e -> MockT m a) -> MockT m a #

MonadMask m => MonadMask (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

mask :: ((forall a. MockT m a -> MockT m a) -> MockT m b) -> MockT m b #

uninterruptibleMask :: ((forall a. MockT m a -> MockT m a) -> MockT m b) -> MockT m b #

generalBracket :: MockT m a -> (a -> ExitCase b -> MockT m c) -> (a -> MockT m b) -> MockT m (b, c) #

MonadCont m => MonadCont (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

callCC :: ((a -> MockT m b) -> MockT m a) -> MockT m a #

MonadUnliftIO m => MonadUnliftIO (MockT m) Source # 
Instance details

Defined in Test.HMock.Internal.MockT

Methods

withRunInIO :: ((forall a. MockT m a -> IO a) -> IO b) -> MockT m b #

mapMockT :: (m a -> m b) -> MockT m a -> MockT m b Source #

initClassIfNeeded :: forall cls m proxy. (Mockable cls, Typeable m, MonadIO m) => proxy cls -> MockT m () Source #

runMockT :: forall m a. MonadIO m => MockT m a -> m a Source #

Runs a test in the MockT monad, handling all of the mocks.

withMockT :: forall m b. MonadIO m => ((forall a. MockT m a -> m a) -> MockT m b) -> m b Source #

Runs a test in the MockT monad. The test can unlift other MockT pieces to the base monad while still acting on the same set of expectations. This can be useful for testing concurrency or similar mechanisms.

test = withMockT $ inMockT -> do
   expect $ ...

   liftIO $ forkIO $ inMockT firstThread
   liftIO $ forkIO $ inMockT secondThread

This is a low-level primitive. Consider using the unliftio package for higher level implementations of multithreading and other primitives.

describeExpectations :: MonadIO m => MockT m String Source #

Fetches a String that describes the current set of outstanding expectations. This is sometimes useful for debugging test code. The exact format is not specified.

verifyExpectations :: MonadIO m => MockT m () Source #

Verifies that all mock expectations are satisfied. You normally don't need to do this, because it happens automatically at the end of your test in runMockT. However, it's occasionally useful to check expectations in the middle of a test, such as before going on to the next stage.

Use of verifyExpectations might signify that you are doing too much in a single test. Consider splitting large tests into a separate test for each case.

byDefault :: forall cls name m r. (MonadIO m, MockableMethod cls name m r) => Rule cls name m r -> MockT m () Source #

Changes the default response for matching actions.

Without byDefault, actions with no explicit response will return the Default value for the type, or undefined if the return type isn't an instance of Default. byDefault replaces that with a new default response, also overriding any previous defaults. The rule passed in must have exactly one response.

mockMethodImpl :: forall cls name m r. (HasCallStack, MonadIO m, MockableMethod cls name m r) => r -> Action cls name m r -> MockT m r Source #

mockMethod :: forall cls name m r. (HasCallStack, MonadIO m, MockableMethod cls name m r, Default r) => Action cls name m r -> MockT m r Source #

Implements a method in a Mockable monad by delegating to the mock framework. If the method is called unexpectedly, an exception will be thrown. However, an expected invocation without a specified response will return the default value.

mockDefaultlessMethod :: forall cls name m r. (HasCallStack, MonadIO m, MockableMethod cls name m r) => Action cls name m r -> MockT m r Source #

Implements a method in a Mockable monad by delegating to the mock framework. If the method is called unexpectedly, an exception will be thrown. However, an expected invocation without a specified response will return undefined. This can be used in place of mockMethod when the return type has no default.

noMatchError Source #

Arguments

:: (HasCallStack, Mockable cls) 
=> Action cls name m a

The action that was received.

-> String 

partialMatchError Source #

Arguments

:: (HasCallStack, Mockable cls) 
=> Action cls name m a

The action that was received.

-> [String]

Descriptions of the matchers that most closely matched, closest first.

-> String