summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsimonmar <unknown>2001-06-29 13:42:19 +0000
committersimonmar <unknown>2001-06-29 13:42:19 +0000
commit74ca59c3835dde6ee18c7ee43ff0ef8b63e2ce1c (patch)
tree7d1631d152eee0633f7c006dd48fe80e9fdeaf14
parentacf37abcd5d48b74c2cd9285a69eb35bd6959b10 (diff)
downloadhaskell-74ca59c3835dde6ee18c7ee43ff0ef8b63e2ce1c.tar.gz
[project @ 2001-06-29 13:42:19 by simonmar]
Test that openFile in WriteMode doesn't truncate the file if an error occurs.
-rw-r--r--ghc/tests/lib/IO/openFile007.hs17
-rw-r--r--ghc/tests/lib/IO/openFile007.stdout5
2 files changed, 22 insertions, 0 deletions
diff --git a/ghc/tests/lib/IO/openFile007.hs b/ghc/tests/lib/IO/openFile007.hs
new file mode 100644
index 0000000000..9c3f8be440
--- /dev/null
+++ b/ghc/tests/lib/IO/openFile007.hs
@@ -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
index 0000000000..a19d317eff
--- /dev/null
+++ b/ghc/tests/lib/IO/openFile007.stdout
@@ -0,0 +1,5 @@
+Left resource busy
+Action: openFile
+Reason: file is locked
+File: openFile007.out
+hello, world