Typo
[packages/base.git] / tests / IO / hClose002.hs
1 import System.IO
2 import Control.Exception
3
4 import qualified GHC.IO.Device as IODevice
5 import GHC.IO.Handle
6 import GHC.IO.Handle.Internals
7 import GHC.IO.Handle.Types
8 import System.Posix.Internals
9
10 main = do
11 h <- openFile "hClose002.tmp" WriteMode
12 -- close the FD without telling the IO library:
13 naughtyClose h
14 -- first hClose will raise an exception, but close the
15 -- Handle anyway:
16 showPossibleException (hClose h)
17 -- second hClose should success (Handle is already closed)
18 showPossibleException (hClose h)
19 -- this should succeed (checking that the lock on the file has
20 -- been released:
21 h <- openFile "hClose002.tmp" ReadMode
22 showPossibleException (hClose h)
23 showPossibleException (hClose h)
24
25 showPossibleException :: IO () -> IO ()
26 showPossibleException f = do e <- try f
27 print (e :: Either SomeException ())
28
29 naughtyClose h =
30 withHandle_ "naughtyClose" h $ \ Handle__{haDevice=dev} -> do
31 IODevice.close dev
32