Copy tests from GHC testsuite; part of #1161.
[packages/base.git] / tests / IO / readFile001.hs
1 -- !!! readFile test
2
3 import System.IO
4 import System.IO.Error
5
6 source = "readFile001.hs"
7 filename = "readFile001.out"
8
9 main = do
10 s <- readFile source
11 h <- openFile filename WriteMode
12 hPutStrLn h s
13 hClose h
14 s <- readFile filename
15
16 -- This open should fail, because the readFile hasn't been forced
17 -- and the file is therefore still locked.
18 tryIOError (openFile filename WriteMode) >>= print
19
20 putStrLn s
21
22 -- should be able to open it for writing now, because we've forced the
23 -- whole file.
24 h <- openFile filename WriteMode
25
26 print h