exception-transformers 0.3.0.3 → 0.3.0.4
raw patch · 3 files changed
+136/−68 lines, 3 filesdep +test-frameworkdep +test-framework-hunitdep ~exception-transformersdep ~transformersPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: test-framework, test-framework-hunit
Dependency ranges changed: exception-transformers, transformers
API changes (from Hackage documentation)
- Control.Monad.Exception: class (Typeable e, Show e) => Exception e
+ Control.Monad.Exception: class (Typeable * e, Show e) => Exception e
- Control.Monad.Exception: class Monad m => MonadException m where act finally sequel = do { a <- act `onException` sequel; _ <- sequel; return a }
+ Control.Monad.Exception: class Monad m => MonadException m where act `finally` sequel = do { a <- act `onException` sequel; _ <- sequel; return a }
Files
- Control/Monad/Exception.hs +32/−7
- exception-transformers.cabal +14/−12
- tests/unit/Main.hs +90/−49
Control/Monad/Exception.hs view
@@ -1,16 +1,17 @@--- |--- Module : Control.Monad.Exception--- Copyright : (c) Harvard University 2008-2011--- (c) Geoffrey Mainland 2011-2012--- License : BSD-style--- Maintainer : mainland@eecs.harvard.edu- {-# LANGUAGE CPP #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE UnboxedTuples #-}+{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-} +-- |+-- Module : Control.Monad.Exception+-- Copyright : (c) Harvard University 2008-2011+-- (c) Geoffrey Mainland 2011-2014+-- License : BSD-style+-- Maintainer : mainland@cs.drexel.edu+ module Control.Monad.Exception ( E.Exception(..), E.SomeException,@@ -27,7 +28,9 @@ liftException ) where +#if defined(__GLASGOW_HASKELL__) && (__GLASGOW_HASKELL__ < 706) import Prelude hiding (catch)+#endif import Control.Applicative import qualified Control.Exception as E (Exception(..),@@ -50,6 +53,11 @@ ErrorT(..), mapErrorT, runErrorT)+#if MIN_VERSION_transformers(0,4,0)+import Control.Monad.Trans.Except (ExceptT(..),+ mapExceptT,+ runExceptT)+#endif /* MIN_VERSION_transformers(0,4,0) */ import Control.Monad.Trans.Identity (IdentityT(..), mapIdentityT, runIdentityT)@@ -295,7 +303,17 @@ act `finally` sequel = mapErrorT (\act' -> act' `finally` runErrorT sequel) act +#if MIN_VERSION_transformers(0,4,0) instance (MonadException m) =>+ MonadException (ExceptT e' m) where+ throw = lift . throw+ m `catch` h = mapExceptT (\m' -> m' `catch` \e -> runExceptT (h e)) m++ act `finally` sequel =+ mapExceptT (\act' -> act' `finally` runExceptT sequel) act+#endif /* MIN_VERSION_transformers(0,4,0) */++instance (MonadException m) => MonadException (IdentityT m) where throw = lift . throw m `catch` h = mapIdentityT (\m' -> m' `catch` \e -> runIdentityT (h e)) m@@ -363,6 +381,13 @@ MonadAsyncException (ErrorT e m) where mask act = ErrorT $ mask $ \restore -> runErrorT $ act (mapErrorT restore)++#if MIN_VERSION_transformers(0,4,0)+instance (MonadAsyncException m) =>+ MonadAsyncException (ExceptT e' m) where+ mask act = ExceptT $ mask $ \restore ->+ runExceptT $ act (mapExceptT restore)+#endif /* MIN_VERSION_transformers(0,4,0) */ instance (MonadAsyncException m) => MonadAsyncException (IdentityT m) where
exception-transformers.cabal view
@@ -1,14 +1,14 @@ name: exception-transformers-version: 0.3.0.3+version: 0.3.0.4 cabal-version: >= 1.10 license: BSD3 license-file: LICENSE copyright: (c) 2009-2010 Harvard University- (c) 2011-2012 Geoffrey Mainland-author: Geoffrey Mainland <mainland@eecs.harvard.edu>-maintainer: mainland@eecs.harvard.edu+ (c) 2011-2014 Geoffrey Mainland+author: Geoffrey Mainland <mainland@cs.drexel.edu>+maintainer: Geoffrey Mainland <mainland@cs.drexel.edu> stability: alpha-homepage: http://www.eecs.harvard.edu/~mainland/+homepage: http://www.cs.drexel.edu/~mainland/ 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@@ -25,9 +25,9 @@ Control.Monad.Exception build-depends:- base >=4 && <5,- stm >=2.1 && <2.5,- transformers >=0.2 && <0.4+ base >= 4 && < 5,+ stm >= 2.1 && < 2.5,+ transformers >= 0.2 && < 0.5 ghc-options: -Wall@@ -39,10 +39,12 @@ default-language: Haskell98 build-depends:- HUnit >= 1.2 && <1.3,- base >= 4 && <5,- exception-transformers >= 0.3 && <0.4,- transformers >= 0.2 && <0.4+ HUnit >= 1.2 && < 1.3,+ base >= 4 && < 5,+ exception-transformers >= 0.3 && < 0.5,+ test-framework >= 0.8 && < 0.9,+ test-framework-hunit >= 0.3 && < 0.4,+ transformers >= 0.2 && < 0.5 ghc-options: -Wall
tests/unit/Main.hs view
@@ -1,49 +1,90 @@-{-# 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" +{-# LANGUAGE CPP #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}++-- |+-- Module : Main+-- Copyright : (c) Geoffrey Mainland 2011-2014+-- License : BSD-style+-- Maintainer : mainland@cs.drexel.edu++module Main where++#if defined(__GLASGOW_HASKELL__) && (__GLASGOW_HASKELL__ < 706)+import Prelude hiding (catch)+#endif++import Control.Monad.Exception+import Control.Monad.Trans.Error+#if MIN_VERSION_transformers(0,4,0)+import Control.Monad.Trans.Except+#endif /* MIN_VERSION_transformers(0,4,0) */+import Control.Monad.IO.Class+import Data.IORef+import Test.Framework+import Test.Framework.Providers.HUnit+import Test.HUnit (Assertion, (@?=))++main :: IO ()+main = defaultMain tests++tests :: [Test]+tests = [ errorTests+ , exceptTests+ ]++errorTests :: Test+errorTests = testGroup "ErrorT tests"+ [testCase (conl ++ " " ++ whatl) (mkErrorTest 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)]++ mkErrorTest :: (ErrorT String IO () -> ErrorT String IO () -> ErrorT String IO ())+ -> ErrorT String IO ()+ -> Assertion+ mkErrorTest con what = 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+ expected @?= actual+ where+ expected :: String+ expected = "sequel called"++exceptTests :: Test+exceptTests = testGroup "ExceptT tests"+#if MIN_VERSION_transformers(0,4,0)+ [testCase (conl ++ " " ++ whatl) (mkExceptTest con what) | (conl, con) <- cons, (whatl, what) <- whats]+ where+ whats :: [(String, ExceptT String IO ())]+ whats = [("return", return ()),+ ("error", error "error"),+ ("throwE", throwE "throwE")]++ cons :: [(String, ExceptT String IO () -> ExceptT String IO () -> ExceptT String IO ())]+ cons = [("finally", \what sequel -> what `finally` sequel),+ ("bracket_", \what sequel -> bracket_ (return ()) sequel what)]++ mkExceptTest :: (ExceptT String IO () -> ExceptT String IO () -> ExceptT String IO ())+ -> ExceptT String IO ()+ -> Assertion+ mkExceptTest con what = do+ ref <- newIORef "sequel not called"+ let sequel = liftIO $ writeIORef ref expected+ _ <- runExceptT (con what sequel) `catch` \(e :: SomeException) -> return (Left (show e))+ actual <- readIORef ref+ expected @?= actual+ where+ expected :: String+ expected = "sequel called"+#else /* !MIN_VERSION_transformers(0,4,0) */+ []+#endif /* !MIN_VERSION_transformers(0,4,0) */