[project @ 2001-05-18 16:54:04 by simonmar]
[ghc-hetmet.git] / ghc / tests / lib / IO / hFlush001.hs
1 -- !!! Flushing
2 module Main(main) where
3
4 import IO
5 import Directory ( removeFile, doesFileExist )
6 import Monad
7
8 main = do
9   hFlush stdin `catch` \ _ -> putStrLn "No can do - flushing read-only handles isn't legal"
10   putStr "Hello,"
11   hFlush stdout
12   putStr "Hello - "
13   hFlush stderr
14   hdl <- openFile "hFlush001.hs" ReadMode
15   hFlush hdl `catch` \ _ -> putStrLn "No can do - flushing read-only handles isn't legal"
16   hClose hdl
17   remove
18   hdl <- openFile "hFlush001.out" WriteMode
19   hFlush hdl
20   hClose hdl
21   remove
22   hdl <- openFile "hFlush001.out" AppendMode
23   hFlush hdl
24   hClose hdl
25   remove
26   hdl <- openFile "hFlush001.out" ReadWriteMode
27   hFlush hdl
28   hClose hdl
29  where remove = do
30          f <- doesFileExist "hFlush001.out"
31          when f (removeFile "hFlush001.out")