no good reason these tests should be expect_fail, as far as I can tell
[packages/unix.git] / tests / fdReadBuf001.hs
1 {-# LANGUAGE NoMonomorphismRestriction #-}
2 import System.Posix
3 import Control.Monad
4 import Foreign
5 import Control.Concurrent
6 import Data.Char
7 import System.Exit
8
9 size = 10000
10 block = 512
11
12 main = do
13 (rd,wr) <- createPipe
14 let bytes = take size (map (fromIntegral.ord) (cycle ['a'..'z']))
15 allocaBytes size $ \p -> do
16 pokeArray p bytes
17 forkIO $ do r <- fdWriteBuf wr p (fromIntegral size)
18 when (fromIntegral r /= size) $ error "fdWriteBuf failed"
19 allocaBytes block $ \p -> do
20 let loop text = do
21 r <- fdReadBuf rd p block
22 let (chunk,rest) = splitAt (fromIntegral r) text
23 chars <- peekArray (fromIntegral r) p
24 when (chars /= chunk) $ error "mismatch"
25 when (null rest) $ exitWith ExitSuccess
26 loop rest
27 loop bytes