packages feed

silently 1.2.3 → 1.2.4

raw patch · 3 files changed

+28/−21 lines, 3 filesdep +nanospecdep −HUnitdep −transformers

Dependencies added: nanospec

Dependencies removed: HUnit, transformers

Files

silently.cabal view
@@ -1,5 +1,5 @@ name: silently-version: 1.2.3+version: 1.2.4 cabal-version: >= 1.8 build-type: Simple license: BSD3@@ -26,8 +26,6 @@     , directory     , deepseq   exposed-modules: System.IO.Silently-  exposed: True-  buildable: True    hs-source-dirs:       src@@ -53,15 +51,11 @@       -Wall -threaded   hs-source-dirs:       test--  cpp-options: -DUSE_NANOSPEC-   build-depends:       base     , silently-    , HUnit     , directory-    , transformers+    , nanospec  -- This tests the generic implementation, that should work on all platforms. test-suite spec-generic@@ -77,5 +71,6 @@    build-depends:       base-    , directory     , deepseq+    , directory+    , nanospec
src/System/IO/Silently.hs view
@@ -3,14 +3,18 @@ -- your own means? Now you can, with 'silence' and 'capture'.  module System.IO.Silently (-  silence, hSilence,-  capture, hCapture+  silence,+  hSilence,+  capture,+  capture_,+  hCapture,+  hCapture_, ) where -import Prelude hiding (catch)+import Prelude import GHC.IO.Handle (hDuplicate, hDuplicateTo) import System.IO-import Control.Exception (bracket, catch)+import qualified Control.Exception as E import Control.DeepSeq import System.Directory (removeFile,getTemporaryDirectory) @@ -30,13 +34,13 @@ -- | Run an IO action while preventing all output to the given handles. hSilence :: [Handle] -> IO a -> IO a hSilence handles action = case mNullDevice of-  Just nullDevice -> bracket (openFile nullDevice AppendMode)+  Just nullDevice -> E.bracket (openFile nullDevice AppendMode)                              hClose                              prepareAndRun    Nothing -> do     tmpDir <- getTempOrCurrentDirectory-    bracket (openTempFile tmpDir "silence")+    E.bracket (openTempFile tmpDir "silence")                                cleanup                                (prepareAndRun . snd) @@ -56,19 +60,27 @@     -- NOTE: We can not use `catchIOError` from "System.IO.Error", it is only     -- availabel in base >= 4.4.     catchIOError :: IO a -> (IOError -> IO a) -> IO a-    catchIOError = catch+    catchIOError = E.catch  -- | Run an IO action while preventing and capturing all output to stdout. -- This will, as a side effect, create and delete a temp file in the temp directory or current directory if there is no temp directory. capture :: IO a -> IO (String, a) capture = hCapture [stdout] +-- | Like `capture`, but discards the result of given action.+capture_ :: IO a -> IO String+capture_ = fmap fst . capture++-- | Like `hCapture`, but discards the result of given action.+hCapture_ :: [Handle] -> IO a -> IO String+hCapture_ handles = fmap fst . hCapture handles+ -- | Run an IO action while preventing and capturing all output to the given handles. -- This will, as a side effect, create and delete a temp file in the temp directory or current directory if there is no temp directory. hCapture :: [Handle] -> IO a -> IO (String, a) hCapture handles action = do   tmpDir <- getTempOrCurrentDirectory-  bracket (openTempFile tmpDir "capture")+  E.bracket (openTempFile tmpDir "capture")                              cleanup                              (prepareAndRun . snd)  where@@ -86,8 +98,8 @@       go hs = goBracket go tmpHandle hs  goBracket :: ([Handle] -> IO a) -> Handle -> [Handle] -> IO a-goBracket go tmpHandle (h:hs) = bracket (do old <- hDuplicate h-                                            hDuplicateTo tmpHandle h-                                            return old)+goBracket go tmpHandle (h:hs) = E.bracket (do old <- hDuplicate h+                                              hDuplicateTo tmpHandle h+                                              return old)                                         (\old -> hDuplicateTo old h >> hClose old)                                         (\_   -> go hs)
test/Spec.hs view
@@ -1,6 +1,6 @@ module Main (main) where -import           NanoSpec+import           Test.Hspec import           System.IO import           System.IO.Silently import           System.Directory