diff options
Diffstat (limited to 'testsuite/tests/lib/IO/hClose002.hs')
-rw-r--r-- | testsuite/tests/lib/IO/hClose002.hs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/testsuite/tests/lib/IO/hClose002.hs b/testsuite/tests/lib/IO/hClose002.hs new file mode 100644 index 0000000000..ebf26b4663 --- /dev/null +++ b/testsuite/tests/lib/IO/hClose002.hs @@ -0,0 +1,32 @@ +import System.IO +import Control.Exception + +import qualified GHC.IO.Device as IODevice +import GHC.IO.Handle +import GHC.IO.Handle.Internals +import GHC.IO.Handle.Types +import System.Posix.Internals + +main = do + h <- openFile "hClose002.tmp" WriteMode + -- close the FD without telling the IO library: + naughtyClose h + -- first hClose will raise an exception, but close the + -- Handle anyway: + showPossibleException (hClose h) + -- second hClose should success (Handle is already closed) + showPossibleException (hClose h) + -- this should succeed (checking that the lock on the file has + -- been released: + h <- openFile "hClose002.tmp" ReadMode + showPossibleException (hClose h) + showPossibleException (hClose h) + +showPossibleException :: IO () -> IO () +showPossibleException f = do e <- try f + print (e :: Either SomeException ()) + +naughtyClose h = + withHandle_ "naughtyClose" h $ \ Handle__{haDevice=dev} -> do + IODevice.close dev + |