packages feed

silently 1.2.0.1 → 1.2.0.2

raw patch · 3 files changed

+81/−3 lines, 3 filesdep +HUnitdep +silentlydep +transformersdep ~basePVP ok

version bump matches the API change (PVP)

Dependencies added: HUnit, silently, transformers

Dependency ranges changed: base

API changes (from Hackage documentation)

Files

silently.cabal view
@@ -1,5 +1,5 @@ name: silently-version: 1.2.0.1+version: 1.2.0.2 cabal-version: >= 1.8 build-type: Simple license: BSD3@@ -36,3 +36,48 @@     cpp-options: -DWINDOWS   if os(linux) || os(osx) || os(freebsd) || os(openbsd) || os(netbsd)     cpp-options: -DUNIX++-- This tests the platform specific implementation.+--+-- NOTE: Cabal 1.10 can not deal with conditional (== if-else) options.  This+-- is why we depend on silently to test the platform specific implementation.+--+-- As a consequence we can not use Hspec for testing, as this would result in+-- depending on two different versions of silently at the same time!+test-suite spec-specific+  main-is:+      Spec.hs+  type:+      exitcode-stdio-1.0+  ghc-options:+      -Wall -Werror -threaded+  hs-source-dirs:+      test++  cpp-options: -DUSE_NANOSPEC++  build-depends:+      base+    , silently+    , HUnit+    , directory+    , transformers++-- This tests the generic implementation, that should work on all platforms.+test-suite spec-generic+  main-is:+      Spec.hs+  type:+      exitcode-stdio-1.0+  ghc-options:+      -Wall -threaded+      -- FIXME: use -Werror+      -- -Wall -Werror -threaded+  hs-source-dirs:+      src+    , test++  build-depends:+      base+    , directory+    , deepseq
src/System/IO/Silently.hs view
@@ -7,10 +7,10 @@   capture, hCapture ) where +import Prelude hiding (catch) import GHC.IO.Handle (hDuplicate, hDuplicateTo) import System.IO-import System.IO.Error-import Control.Exception (bracket)+import Control.Exception (bracket, catch) import Control.DeepSeq import System.Directory (removeFile,getTemporaryDirectory) @@ -52,6 +52,11 @@  getTempOrCurrentDirectory :: IO String getTempOrCurrentDirectory = getTemporaryDirectory `catchIOError` (\_ -> return ".")+  where+    -- 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  -- | 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.
+ test/Spec.hs view
@@ -0,0 +1,28 @@+module Main (main) where++import           NanoSpec+import           System.IO+import           System.IO.Silently+import           System.Directory++import           Control.Exception++main :: IO ()+main = hspec spec++spec :: Spec+spec = do++  describe "hSilence" $ do+    it "prevents output to a given handle" $ let file = "foo.txt" in do+      h <- openFile file ReadWriteMode+      hSilence [h] $ do+        hPutStrLn h "foo bar baz"+        hFlush h+      hSeek h AbsoluteSeek 0+      hGetContents h `shouldReturn` ""+      `finally` removeFile file++  describe "capture" $ do+    it "captures stdout" $ do+      capture (putStr "foo" >> return 23) `shouldReturn` ("foo", 23 :: Int)