[project @ 2001-06-29 13:42:19 by simonmar]
authorsimonmar <unknown>
Fri, 29 Jun 2001 13:42:19 +0000 (13:42 +0000)
committersimonmar <unknown>
Fri, 29 Jun 2001 13:42:19 +0000 (13:42 +0000)
Test that openFile in WriteMode doesn't truncate the file if an error
occurs.

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

diff --git a/ghc/tests/lib/IO/openFile007.hs b/ghc/tests/lib/IO/openFile007.hs
new file mode 100644 (file)
index 0000000..9c3f8be
--- /dev/null
@@ -0,0 +1,17 @@
+-- !!! check that we don't truncate files if the open fails
+
+import IO
+import Monad
+
+tmp = "openFile007.out"
+
+main = do
+  h <- openFile tmp WriteMode
+  hPutStrLn h "hello, world"
+
+  -- second open in write mode better fail, but better not truncate the file
+  try (openFile tmp WriteMode) >>= print
+  
+  hClose h
+  s <- readFile tmp -- make sure our "hello, world" is still there
+  putStr s
diff --git a/ghc/tests/lib/IO/openFile007.stdout b/ghc/tests/lib/IO/openFile007.stdout
new file mode 100644 (file)
index 0000000..a19d317
--- /dev/null
@@ -0,0 +1,5 @@
+Left resource busy
+Action: openFile
+Reason: file is locked
+File: openFile007.out
+hello, world