From 74ca59c3835dde6ee18c7ee43ff0ef8b63e2ce1c Mon Sep 17 00:00:00 2001 From: simonmar Date: Fri, 29 Jun 2001 13:42:19 +0000 Subject: [PATCH] [project @ 2001-06-29 13:42:19 by simonmar] Test that openFile in WriteMode doesn't truncate the file if an error occurs. --- ghc/tests/lib/IO/openFile007.hs | 17 +++++++++++++++++ ghc/tests/lib/IO/openFile007.stdout | 5 +++++ 2 files changed, 22 insertions(+) create mode 100644 ghc/tests/lib/IO/openFile007.hs create mode 100644 ghc/tests/lib/IO/openFile007.stdout diff --git a/ghc/tests/lib/IO/openFile007.hs b/ghc/tests/lib/IO/openFile007.hs new file mode 100644 index 0000000..9c3f8be --- /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 0000000..a19d317 --- /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 -- 1.7.10.4