[project @ 2001-08-22 11:45:06 by sewardj]
[ghc-hetmet.git] / ghc / tests / lib / IO / hFileSize002.hs
1 -- !!! Testing IO.hFileSize
2 module Main(main) where
3
4 import IO
5 import Directory ( removeFile, doesFileExist )
6 import Monad
7
8 main = do
9   sz <- hFileSize stdin `catch` (\ _ -> return (-1))
10   print sz
11   let fn = "hFileSize002.out"
12   f <- doesFileExist fn
13   when f (removeFile fn)
14   hdl <- openFile fn WriteMode
15   hPutStr hdl "file_size"
16    -- with default buffering
17   sz <- hFileSize hdl
18   print sz
19
20   hSetBuffering hdl NoBuffering
21   hPutStr hdl "file_size"
22    -- with no buffering
23   sz <- hFileSize hdl
24   print sz
25   hSetBuffering hdl LineBuffering
26   hPutStr hdl "file_size"
27    -- with line buffering
28   sz <- hFileSize hdl
29   print sz
30   hSetBuffering hdl (BlockBuffering (Just 4))
31    -- with block buffering
32   hPutStr hdl "file_size"
33   sz <- hFileSize hdl
34   print sz
35   hClose hdl