test-fixture 0.4.0.0 → 0.4.1.0
raw patch · 3 files changed
+15/−13 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Monad.TestFixture: instance Control.Monad.Error.Class.MonadError e m => Control.Monad.Error.Class.MonadError e (Control.Monad.TestFixture.TestFixtureT fixture log state m)
Files
- src/Control/Monad/TestFixture.hs +11/−3
- src/Control/Monad/TestFixture/TH.hs +3/−9
- test-fixture.cabal +1/−1
src/Control/Monad/TestFixture.hs view
@@ -1,6 +1,9 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE UndecidableInstances #-} #if __GLASGOW_HASKELL__ >= 800 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-}@@ -160,7 +163,7 @@ > instance Monoid log => LookupUser (TestFixture Fixture log state) where > lookupUser userId = do > fn <- asks _lookupUser- > lift $ fn userId+ > fn userId Now we can write our tests using the 'unTestFixture' function, along with the similar 'logTestFixture' functions and friends:@@ -219,6 +222,7 @@ import qualified Control.Monad.Writer.Class import qualified Control.Monad.State.Class +import Control.Monad.Error.Class import Control.Monad.RWS import Data.Functor.Identity @@ -242,6 +246,10 @@ instance MonadTrans (TestFixtureT fixture log state) where lift = TestFixtureT . lift +instance MonadError e m => MonadError e (TestFixtureT fixture log state m) where+ throwError = lift . throwError+ catchError m h = TestFixtureT (getRWST m `catchError` \e -> getRWST (h e))+ -- | The transformer equivalent of 'unTestFixture'. unTestFixtureT :: Monad m => TestFixtureT fixture () () m a -> fixture (TestFixtureT fixture () () m) -> m a unTestFixtureT stack env = fmap fst (evalTestFixtureT stack env)@@ -313,7 +321,7 @@ > instance Monoid log => MonadSomething (TestFixture Fixture log state) where > getSomething = do > something <- asks _getSomething- > lift something+ > something Using 'arg0', it can be rewritten like this: @@ -333,7 +341,7 @@ > instance Monoid log => MonadSomething (TestFixture Fixture log state) where > doSomething x = do > fn <- asks _doSomething- > lift $ fn x+ > fn x Using 'arg1', it can be rewritten like this:
src/Control/Monad/TestFixture/TH.hs view
@@ -59,33 +59,27 @@ > } > > type FixturePure = Fixture (TestFixture Fixture () ())- > > type FixtureLog log = Fixture (TestFixture Fixture log ())- > > type FixtureState state = Fixture (TestFixture Fixture () state)- > > type FixtureLogState log state = Fixture (TestFixture Fixture log state) > > type FixturePureT m = Fixture (TestFixture Fixture () () m)- > > type FixtureLogT log m = Fixture (TestFixture Fixture log () m)- > > type FixtureStateT state m = Fixture (TestFixture Fixture () state m)- > > type FixtureLogStateT log state m = Fixture (TestFixtureT Fixture log state m) > > instance Monad m => DB (TestFixtureT Fixture w s m) where > fetchRecord r = do > fn <- asks _fetchRecord- > lift $ fn r+ > fn r > insertRecord r = do > fn <- asks _insertRecord- > lift $ fn r+ > fn r > > instance Monad m => HTTP (TestFixtureT Fixture w s m) where > sendRequest r = do > fn <- asks _sendRequest- > lift $ fn r+ > fn r This type can then be used in tandem with "Control.Monad.TestFixture" to create stubbed typeclass instances and run computations using them.
test-fixture.cabal view
@@ -1,7 +1,7 @@ name: test-fixture version:- 0.4.0.0+ 0.4.1.0 synopsis: Test monadic side-effects description: