summaryrefslogtreecommitdiff
path: root/libraries/base/tests/IO/encodingerror001.hs
blob: 2cfc6e6a012964f396cd354d379a07a726fb8629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import System.IO
import System.IO.Error
import Text.Printf
import Control.Monad

main = do
  hSetEncoding stdout latin1
  forM [NoBuffering,
        LineBuffering,
        BlockBuffering Nothing,
        BlockBuffering (Just 3),
        BlockBuffering (Just 9),
        BlockBuffering (Just 32)] $ \b -> do
     hSetBuffering stdout b
     checkedPutStr "test 1\n"
     checkedPutStr "ě\n" -- nothing gets written
     checkedPutStr "test 2\n"
     checkedPutStr "Hέllo\n" -- we should write at least the 'H'
     checkedPutStr "test 3\n"
     checkedPutStr "Hello αβγ\n" -- we should write at least the "Hello "

checkedPutStr str = do
  r <- tryIOError $ putStr str
  case r of
    Right _ -> return ()
    Left  e -> printf "Caught %s while trying to write %s\n"
                  (show e) (show str)