Skip to content

Commit

Permalink
runHandler, evalHander do not include an environment argument. Patch
Browse files Browse the repository at this point in the history
mirrors format of Snap.Snaplet.Internal.Initializer.runSnaplet.
  • Loading branch information
cjeast committed Jun 14, 2013
1 parent 7da5a64 commit 9e9f796
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/Snap/Snaplet/Test.hs
Expand Up @@ -15,6 +15,7 @@ import Control.Concurrent.MVar
import Control.Exception.Base (finally)
import qualified Control.Exception as E
import Control.Monad.IO.Class
import Data.Maybe (fromMaybe)
import Data.Text
import System.Directory
import System.IO.Error
Expand Down Expand Up @@ -56,12 +57,13 @@ removeFileMayNotExist f = catchNonExistence (removeFile f) ()
-- 'runHandler' defined in Snap.Test, because due to the fact running
-- the initializer inside 'SnapletInit' can throw an exception.
runHandler :: MonadIO m
=> RequestBuilder m ()
=> Maybe String
-> RequestBuilder m ()
-> Handler b b a
-> SnapletInit b b
-> m (Either Text Response)
runHandler rq h s = do
app <- getSnaplet s
runHandler env rq h s = do
app <- getSnaplet env s
case app of
(Left e) -> return $ Left e
(Right (a,_)) -> do
Expand All @@ -81,12 +83,13 @@ runHandler rq h s = do
-- 'evalHandler defined in Snap.Test, because due to the fact running
-- the initializer inside 'SnapletInit' can throw an exception.
evalHandler :: MonadIO m
=> RequestBuilder m ()
=> Maybe String
-> RequestBuilder m ()
-> Handler b b a
-> SnapletInit b b
-> m (Either Text a)
evalHandler rq h s = do
app <- getSnaplet s
evalHandler env rq h s = do
app <- getSnaplet env s
case app of
(Left e) -> return $ Left e
(Right (a,_)) -> do
Expand All @@ -99,10 +102,11 @@ evalHandler rq h s = do
-- a @Snaplet b@, or an error message whether the initializer threw an
-- exception.
getSnaplet :: MonadIO m
=> SnapletInit b b
=> Maybe String
-> SnapletInit b b
-> m (Either Text (Snaplet b, InitializerState b))
getSnaplet (SnapletInit initializer) = liftIO $ do
getSnaplet env (SnapletInit initializer) = liftIO $ do
mvar <- newEmptyMVar
let resetter f = modifyMVar_ mvar (return . f)
runInitializer resetter "" initializer
runInitializer resetter (fromMaybe "devel" env) initializer

0 comments on commit 9e9f796

Please sign in to comment.