Update tests following changes in base
[packages/base.git] / tests / IO / hFileSize002.hs
1 -- !!! Testing IO.hFileSize
2 module Main(main) where
3
4 import Control.Monad
5 import System.Directory ( removeFile, doesFileExist )
6 import System.IO
7 import System.IO.Error
8
9 main = do
10 sz <- hFileSize stdin `catchIOError` (\ _ -> return (-1))
11 print sz
12 let fn = "hFileSize002.out"
13 f <- doesFileExist fn
14 when f (removeFile fn)
15 hdl <- openFile fn WriteMode
16 hPutStr hdl "file_size"
17 -- with default buffering
18 sz <- hFileSize hdl
19 print sz
20
21 hSetBuffering hdl NoBuffering
22 hPutStr hdl "file_size"
23 -- with no buffering
24 sz <- hFileSize hdl
25 print sz
26 hSetBuffering hdl LineBuffering
27 hPutStr hdl "file_size"
28 -- with line buffering
29 sz <- hFileSize hdl
30 print sz
31 hSetBuffering hdl (BlockBuffering (Just 4))
32 -- with block buffering
33 hPutStr hdl "file_size"
34 sz <- hFileSize hdl
35 print sz
36 hClose hdl