Commit d1270a0b authored by Simon Marlow's avatar Simon Marlow
Browse files

add test for #1753

parent 5a361f1c
......@@ -8,8 +8,8 @@ test('IOError001', compose(omit_ways(['ghci']), set_stdin('IOError001.hs')),
test('IOError002', normal, compile_and_run, [''])
test('finalization001', normal, compile_and_run, [''])
test('hClose001', normal, compile_and_run, [''])
clean(['hClose001.tmp'])
test('hClose001', extra_clean(['hClose001.tmp']), compile_and_run, [''])
test('hClose002', extra_clean(['hClose002.tmp']), compile_and_run, [''])
test('hFileSize001', normal, compile_and_run, [''])
test('hFileSize002', omit_ways(['ghci']), compile_and_run, [''])
clean(['hFileSize002.out'])
......
import System.IO
import Control.Exception
import GHC.IOBase
import GHC.Handle
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:
try (hClose h) >>= print
-- second hClose should success (Handle is already closed)
try (hClose h) >>= print
-- this should succeed (checking that the lock on the file has
-- been released:
h <- openFile "hClose002.tmp" ReadMode
try (hClose h) >>= print
try (hClose h) >>= print
naughtyClose h =
withHandle_ "naughtyClose" h $ \ h_ -> do
let fd = haFD h_
c_close fd
Left hClose: invalid argument (Bad file descriptor)
Right ()
Right ()
Right ()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment