Lazyness.hs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. {-# LANGUAGE OverloadedStrings #-}
  2. module Lazyness (tests) where
  3. import Distribution.TestSuite
  4. import Control.Concurrent(forkIO)
  5. import qualified System.IO.Uniform as U
  6. import qualified System.IO.Uniform.Streamline as S
  7. import System.Timeout (timeout)
  8. tests :: IO [Test]
  9. tests = return [Test readLine]
  10. where
  11. readLine = TestInstance
  12. {run = testReadLine,
  13. name = "Lazyness of readLine",
  14. tags = [],
  15. options = [],
  16. setOption = \_ _ -> Right readLine
  17. }
  18. testReadLine :: IO Progress
  19. testReadLine = do
  20. recv <- U.bindPort 8888
  21. forkIO $ S.withClient (\_ _ -> do
  22. l <- S.receiveLine
  23. S.send l
  24. S.send "\n"
  25. return ()
  26. ) recv
  27. r <- timeout 1000000 $ S.withServer (do
  28. S.send "A test\n"
  29. S.receiveLine
  30. return ()
  31. ) "127.0.0.1" 8888
  32. case r of
  33. Just _ -> return . Finished $ Pass
  34. Nothing -> return . Finished . Fail $ "Timeout on Streamline.readLine"