io004_RUNTEST_OPTS += -x 42
io016_RUNTEST_OPTS += io016.hs io016.out
io017_RUNTEST_OPTS += -i io017.stdin
+io018_RUNTEST_OPTS += -i io018.hs
io021_RUNTEST_OPTS += -i io021.hs
io022_RUNTEST_OPTS += -i io022.hs
io028_RUNTEST_OPTS += -i io028.hs
--- Sigbjorn and I don't understand what this test is meant to do
--- It simply hangs on stdin!
+--!!! Testing RW handles
+module Main(main) where
-import IO -- 1.3
+
+import IO
import Directory (removeFile)
-main = let username = "io018.inout" in
- openFile username ReadWriteMode >>= \ cd ->
- removeFile username >>
- hSetBuffering stdin NoBuffering >>
- hSetBuffering stdout NoBuffering >>
- hSetBuffering cd NoBuffering >>
- hPutStr cd speakString >>
- speak cd
+-- This test is weird, full marks to whoever dreamt it up!
-speakString = "Someone wants to speak with you\n"
+main :: IO ()
+main = do
+ let username = "io018.inout"
+ cd <- openFile username ReadWriteMode
+ removeFile username
+ hSetBuffering stdin NoBuffering
+ hSetBuffering stdout NoBuffering
+ hSetBuffering cd NoBuffering
+ hPutStr cd speakString
+ hSeek cd AbsoluteSeek 0
+ speak cd `catch` \ err -> if isEOFError err then putStrLn "\nCaught EOF" else fail err
+ hSeek cd AbsoluteSeek 0
+ hSetBuffering cd LineBuffering
+ speak cd `catch` \ err -> if isEOFError err then putStrLn "\nCaught EOF" else fail err
+ hSeek cd AbsoluteSeek 0
+ hSetBuffering cd (BlockBuffering Nothing)
+ speak cd `catch` \ err -> if isEOFError err then putStrLn "\nCaught EOF" else fail err
-speak cd = return ()
-{-
- (hReady cd >>= \ ready ->
- if ready then (hGetChar cd >>= putChar)
- else return () >>
+speakString = "Someone wants to speak with you\n"
- hReady stdin >>= \ ready ->
- if ready then (getChar >>= hPutChar cd)
- else return ()) >>
+speak cd = do
+ (do
+ ready <- hReady cd
+ if ready then
+ hGetChar cd >>= putChar
+ else
+ return ()
+ ready <- hReady stdin
+ if ready then (do { ch <- getChar; hPutChar cd ch})
+ else return ())
+ speak cd
- speak cd
--}
--- /dev/null
+--!!! RW files
+module Main(main) where
+
+import IO
+import Directory ( removeFile )
+
+main = do
+ hdl <- openFile "io031.inout" ReadWriteMode
+ removeFile "io031.inout"
+ hSetBuffering hdl LineBuffering
+ hPutStr hdl "as"
+ hSeek hdl AbsoluteSeek 0
+ ch <- hGetChar hdl
+ print ch
+ hPutStr hdl "ase"
+ hSeek hdl AbsoluteSeek 0
+ putChar '\n'
+ ls <- hGetContents hdl
+ putStrLn ls
+