diff --git a/silently.cabal b/silently.cabal index 8cbf2fc..fe326fe 100644 --- a/silently.cabal +++ b/silently.cabal @@ -63,50 +63,21 @@ Library ghc-options: -Wcompat --- 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 - type: - exitcode-stdio-1.0 - hs-source-dirs: - test - main-is: - Spec.hs - default-language: - Haskell98 - ghc-options: - -Wall -threaded - build-depends: - base - , silently - , directory - , nanospec - , temporary - -- This tests the generic implementation, that should work on all platforms. test-suite spec-generic type: exitcode-stdio-1.0 hs-source-dirs: - src - , test + test main-is: Spec.hs default-language: Haskell98 ghc-options: - -Wall -threaded - other-modules: - System.IO.Silently - + -Wall -threaded -rtsopts build-depends: base - , deepseq + , silently , directory , nanospec , temporary diff --git a/src/System/IO/Silently.hs b/src/System/IO/Silently.hs index ec6a53c..8efe9d7 100644 --- a/src/System/IO/Silently.hs +++ b/src/System/IO/Silently.hs @@ -27,6 +27,10 @@ import System.IO , openFile, openTempFile, stdout ) +#if defined(WINDOWS) && __GLASGOW_HASKELL__ >= 900 +import GHC.IO.SubSystem (()) +#endif + mNullDevice :: Maybe FilePath #ifdef WINDOWS mNullDevice = Just "\\\\.\\NUL" @@ -110,7 +114,15 @@ hCapture handles action = withTempFile "capture" prepareAndRun go (h:hs) = goBracket go tmpHandle h hs goBracket :: ([Handle] -> IO a) -> Handle -> Handle -> [Handle] -> IO a -goBracket go tmpHandle h hs = do +#if defined(WINDOWS) && __GLASGOW_HASKELL__ >= 900 +goBracket = goBracketPosix giveUp + where giveUp go _ _ _ = go [] +#else +goBracket = goBracketPosix +#endif + +goBracketPosix :: ([Handle] -> IO a) -> Handle -> Handle -> [Handle] -> IO a +goBracketPosix go tmpHandle h hs = do buffering <- hGetBuffering h let redirect = do old <- hDuplicate h