[project @ 2001-06-29 13:40:50 by simonmar]
authorsimonmar <unknown>
Fri, 29 Jun 2001 13:40:50 +0000 (13:40 +0000)
committersimonmar <unknown>
Fri, 29 Jun 2001 13:40:50 +0000 (13:40 +0000)
Test that readFile doesn't leave the file locked after its output has
been forced completely.

ghc/tests/lib/IO/readFile001.hs [new file with mode: 0644]
ghc/tests/lib/IO/readFile001.stdout [new file with mode: 0644]

diff --git a/ghc/tests/lib/IO/readFile001.hs b/ghc/tests/lib/IO/readFile001.hs
new file mode 100644 (file)
index 0000000..82a0dc2
--- /dev/null
@@ -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 (file)
index 0000000..cd8caf6
--- /dev/null
@@ -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)}