hidden-char 0.1.0.0 → 0.1.0.1
raw patch · 4 files changed
+56/−3 lines, 4 filesdep +hidden-charPVP ok
version bump matches the API change (PVP)
Dependencies added: hidden-char
API changes (from Hackage documentation)
Files
- README.md +4/−0
- hidden-char.cabal +4/−2
- src/System/IO/HiddenChar/Windows.hs +3/−1
- test/HiddenCharSpec.hs +45/−0
README.md view
@@ -1,5 +1,9 @@ # `hidden-char` +[](https://travis-ci.org/rcook/hidden-char)+[](http://hackage.haskell.org/package/hidden-char)+[](https://raw.githubusercontent.com/rcook/hidden-char/master/LICENSE)+ Provides a `getHiddenChar` function that works on Windows, Linux and macOS ## Licence
@@ -1,5 +1,5 @@ name: hidden-char-version: 0.1.0.0+version: 0.1.0.1 synopsis: Provides getHiddenChar function description: Provides a @getHiddenChar@ function that works on Windows, Linux and macOS homepage: https://github.com/rcook/hidden-char#readme@@ -32,10 +32,11 @@ test-suite hidden-char-test type: exitcode-stdio-1.0 default-language: Haskell2010- ghc-options: -W -Wall+ ghc-options: -W -Wall -threaded hs-source-dirs: test main-is: Main.hs build-depends: base >= 4.7 && < 5+ , hidden-char , hspec if os(linux) cpp-options: -DOS_LINUX@@ -43,3 +44,4 @@ cpp-options: -DOS_WINDOWS if os(darwin) cpp-options: -DOS_MACOS+ other-modules: HiddenCharSpec
src/System/IO/HiddenChar/Windows.hs view
@@ -15,7 +15,9 @@ import Data.Char import Foreign.C.Types -foreign import ccall unsafe "conio.h getch" c_getch :: IO CInt+-- Must import as "safe" in order to prevent FFI call from blocking other threads+-- https://github.com/rcook/hidden-char/issues/1+foreign import ccall safe "conio.h getch" c_getch :: IO CInt -- | Read a character from the standard input device with buffering and echoing disabled -- Hack based on http://stackoverflow.com/questions/2983974/haskell-read-input-character-from-console-immediately-not-after-newline
+ test/HiddenCharSpec.hs view
@@ -0,0 +1,45 @@+{-|+Module : HiddenCharSpec+Description : Tests for @System.IO.HiddenChar@ module+Copyright : (C) Richard Cook, 2017+Licence : MIT+Maintainer : rcook@rcook.org+Stability : stable+Portability : portable+-}++{-# LANGUAGE ScopedTypeVariables #-}++module HiddenCharSpec (spec) where++import Control.Concurrent+import Control.Exception+import System.IO.HiddenChar+import System.Timeout+import Test.Hspec++spec :: Spec+spec = do+ describe "concurrent use of getHiddenChar" $+ it "doesn't block other threads" $ do+ -- Run getHiddenChar in a bound thread and swallow all exceptions+ _ <- forkOS $ do+ _ <- getHiddenChar `catch` (\(_ :: SomeException) -> return ' ')+ return ()++ -- On another bound thread, count up to a given value with a small+ -- delay at each step. runInBoundThread should terminate and return+ -- the expected value if getHiddenChar works correctly. In the presence+ -- of calls to functions via the "unsafe", then this thread will block.+ -- This is a behaviour we would like to avoid.+ -- https://github.com/rcook/hidden-char/issues/1+ let countUpTo :: Int -> IO Int+ countUpTo n = helper n n+ where+ helper n' i+ | i == 0 = return n'+ | otherwise = do+ threadDelay 1+ helper n' (i - 1)+ result <- timeout 1000000 $ runInBoundThread (countUpTo 5)+ result `shouldBe` Just 5