From: simonmar Date: Fri, 29 Jun 2001 13:40:50 +0000 (+0000) Subject: [project @ 2001-06-29 13:40:50 by simonmar] X-Git-Tag: Approximately_9120_patches~1651 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=d43b6f32e0cd09c6eaa1da2e8c532ff1141d3e07;p=ghc-hetmet.git [project @ 2001-06-29 13:40:50 by simonmar] Test that readFile doesn't leave the file locked after its output has been forced completely. --- diff --git a/ghc/tests/lib/IO/readFile001.hs b/ghc/tests/lib/IO/readFile001.hs new file mode 100644 index 0000000..82a0dc2 --- /dev/null +++ b/ghc/tests/lib/IO/readFile001.hs @@ -0,0 +1,28 @@ +-- !!! readFile test + +import IO + +source = "readFile001.hs" +filename = "readFile001.out" + +main = do + s <- readFile source + h <- openFile filename WriteMode + hPutStrLn h s + hClose h + s <- readFile filename + + -- This open should fail, because the readFile hasn't been forced + -- and the file is therefore still locked. But GHC currently has a + -- bug in that the openFile truncates the file before checking + -- whether it was locked or not. + -- r <- try (openFile filename WriteMode) + -- print r + + putStrLn s + + -- should be able to open it for writing now, because we've forced the + -- whole file. + h <- openFile filename WriteMode + + print h diff --git a/ghc/tests/lib/IO/readFile001.stdout b/ghc/tests/lib/IO/readFile001.stdout new file mode 100644 index 0000000..cd8caf6 --- /dev/null +++ b/ghc/tests/lib/IO/readFile001.stdout @@ -0,0 +1,31 @@ +-- !!! readFile test + +import IO + +source = "readFile001.hs" +filename = "readFile001.out" + +main = do + s <- readFile source + h <- openFile filename WriteMode + hPutStrLn h s + hClose h + s <- readFile filename + + -- This open should fail, because the readFile hasn't been forced + -- and the file is therefore still locked. But GHC currently has a + -- bug in that the openFile truncates the file before checking + -- whether it was locked or not. + -- r <- try (openFile filename WriteMode) + -- print r + + putStrLn s + + -- should be able to open it for writing now, because we've forced the + -- whole file. + h <- openFile filename WriteMode + + print h + + +{loc=readFile001.out,type=writable,binary=False,buffering=block (8192)}