1 --!!! Testing File I/O operations and errors
5 testFile = "test/iohandle.tst"
6 unreadable = "test/unreadable.tst"
7 unwritable = "test/unwritable.tst"
8 nonexistent = "test/nonexistent.tst"
11 a1 = writeFile testFile (show [1..10])
12 a2 = readFile testFile >>= \ s -> putStr s
13 a3 = appendFile testFile (show [11..20])
14 a4 = readFile testFile >>= \ s -> putStr s
16 -- Same stuff - but using handle-based operations
17 b1 = openFile testFile WriteMode >>= \ h ->
18 hPutStr h (show [1..10])
19 b2 = openFile testFile ReadMode >>= \ h ->
20 hGetContents h >>= \ s ->
22 b3 = openFile testFile AppendMode >>= \ h ->
23 hPutStr h (show [11..20])
24 b4 = openFile testFile ReadMode >>= \ h ->
25 hGetContents h >>= \ s ->
28 -- Miscellaneous little functions
29 c1 = openFile testFile WriteMode >>= \ h ->
30 mapM_ (hPutChar h) (show [1..10]) >>
32 c2 = openFile testFile ReadMode >>= \ h ->
39 c3 = openFile testFile AppendMode >>= \ h ->
40 hPutStr h (show [11..20]) >>
42 c4 = openFile testFile ReadMode >>= \ h ->
48 loop `catch` (\err -> if isEOFError err then return () else fail err)
49 -- If this function raises an uncaught EOF error, then hIsEOF probably
50 -- implements ANSI C feof semantics which is quite different from
51 -- Haskell 1.3 semantics (but much easier to implement).
52 c5 = openFile testFile ReadMode >>= \ h ->
55 if eof then return () else
62 c6 = openFile testFile ReadMode >>= \ h ->
64 hGetContents h >>= \ s ->
67 -- should print first 10 characters of file twice
68 c7 = openFile testFile ReadMode >>= \ h ->
69 hGetContents h >>= \ s ->
75 -- Deliberately trying to trigger IOErrors:
77 -- Note: Linux allows a file to be opened twice
78 d1 = openFile testFile WriteMode >>= \ h1 ->
79 openFile testFile WriteMode >>= \ h2 ->
80 let x = [h1,h2] in -- try to make sure both pointers remain live
83 d2 = openFile testFile WriteMode >>= \ h ->
84 hGetContents h >>= \ s ->
87 d3 = openFile testFile ReadMode >>= \ h ->
88 hPutStr h (show [5..10])
90 -- This should succeed
91 d4 = openFile unreadable WriteMode >>= \ h ->
95 d5 = openFile unreadable ReadMode >>= \ h ->
98 -- This should succeed
99 d6 = openFile unwritable ReadMode >>= \ h ->
103 d7 = openFile unwritable WriteMode >>= \ h ->
106 d8 = openFile testFile ReadMode >>= \ h ->
108 hGetContents h >>= \ s ->
111 d9 = openFile testFile ReadMode >>= \ h ->
116 d10 = openFile testFile ReadMode >>= \ h ->
117 hGetContents h >>= \ s1 ->
118 hGetContents h >>= \ s2 ->