exception-transformers 0.3 → 0.3.0.1
raw patch · 3 files changed
+77/−15 lines, 3 filesdep +HUnitdep +exception-transformersPVP ok
version bump matches the API change (PVP)
Dependencies added: HUnit, exception-transformers
API changes (from Hackage documentation)
Files
- Control/Monad/Exception.hs +3/−8
- exception-transformers.cabal +25/−7
- tests/unit/Main.hs +49/−0
Control/Monad/Exception.hs view
@@ -140,15 +140,12 @@ -- raised) -> m a act `finally` sequel = do- a <- act `catch` \(e :: E.SomeException) -> sequel >> throw e+ a <- act `onException` sequel _ <- sequel return a -- | If an exception is raised by the computation, then perform a final action--- and re-raise the exception. If a short-circuiting monad transformer such as--- ErrorT or MaybeT is used to transform a MonadException monad, then the--- onException implementation for the transformer must guarantee that the final--- action is also performed when any short-circuiting occurs.+-- and re-raise the exception. onException :: MonadException m => m a -- ^ The computation to run -> m b -- ^ Computation to run if an exception is raised@@ -177,9 +174,7 @@ bracket before after thing = mask $ \restore -> do a <- before- r <- restore (thing a) `onException` after a- _ <- after a- return r+ restore (thing a) `finally` after a -- | A variant of 'bracket' where the return value from the first computation is -- not required.
exception-transformers.cabal view
@@ -1,6 +1,6 @@ name: exception-transformers-version: 0.3-cabal-version: >= 1.6+version: 0.3.0.1+cabal-version: >= 1.10 license: BSD3 license-file: LICENSE copyright: (c) 2008-2011 Harvard University@@ -11,13 +11,15 @@ category: Control, Monad, Error Handling, Failure synopsis: Type classes and monads for unchecked extensible exceptions. description: This package provides type classes, a monad and a monad- transformer that support unchecked extensible exceptions as- well as asynchronous exceptions. It is compatible with- the transformers package.+ transformer that support unchecked extensible exceptions as+ well as asynchronous exceptions. It is compatible with+ the transformers package. build-type: Simple library+ default-language: Haskell98+ exposed-modules: Control.Monad.Exception @@ -29,6 +31,22 @@ ghc-options: -Wall +test-suite unit+ type: exitcode-stdio-1.0+ hs-source-dirs: tests/unit+ main-is: Main.hs+ default-language: Haskell98++ build-depends:+ HUnit >=1.2 && <1.3,+ base >=4 && <5,+ exception-transformers >=0.3 && <0.4,+ transformers >=0.2 && <0.3++ ghc-options:+ -Wall+ source-repository head- type: svn- location: http://senseless.eecs.harvard.edu/repos/mainland-projects/exception-transformers/trunk/+ type: git+ location: git://github.com/mainland/exception-transformers.git+
+ tests/unit/Main.hs view
@@ -0,0 +1,49 @@+{-# LANGUAGE ScopedTypeVariables #-} + +module Main where + +import Prelude hiding (catch) + +import Control.Monad.Exception +import Control.Monad.Trans.Error +import Control.Monad.IO.Class +import Data.IORef +import System.Exit (exitFailure, exitSuccess) +import Test.HUnit + +main :: IO () +main = do + count <- runTestTT tests + case failures count of + 0 -> exitSuccess + _ -> exitFailure + + +tests :: Test +tests = TestList [mkTest (conl ++ " " ++ whatl) con what | (conl, con) <- cons, (whatl, what) <- whats] + where + whats :: [(String, ErrorT String IO ())] + whats = [("return", return ()), + ("error", error "error"), + ("throwError", throwError "throwError")] + + cons :: [(String, ErrorT String IO () -> ErrorT String IO () -> ErrorT String IO ())] + cons = [("finally", \what sequel -> what `finally` sequel), + ("bracket_", \what sequel -> bracket_ (return ()) sequel what)] + +mkTest :: String + -> (ErrorT String IO () -> ErrorT String IO () -> ErrorT String IO ()) + -> ErrorT String IO () + -> Test +mkTest label con what = + label ~: tst + where + tst = do + ref <- newIORef "sequel not called" + let sequel = liftIO $ writeIORef ref expected + _ <- runErrorT (con what sequel) `catch` \(e :: SomeException) -> return (Left (show e)) + actual <- readIORef ref + return $ assertEqual "" expected actual + + expected :: String + expected = "sequel called"