TOP = ../..
+
include $(TOP)/mk/boilerplate.mk
+
+ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+OMITTED_RUNTESTS = io005.run io033.run
+endif
+
include $(TOP)/mk/should_run.mk
HC_OPTS += -dcore-lint
io022_HC_OPTS += -fglasgow-exts
io010_HC_OPTS += -fglasgow-exts
io011_HC_OPTS += -fglasgow-exts
+io018_HC_OPTS += -fglasgow-exts
+io030_HC_OPTS += -fglasgow-exts
io032_HC_OPTS += -fglasgow-exts
io004_RUNTEST_OPTS += -x 42
+-- Not run on mingw, because of /dev/null use
+
import System (system, ExitCode(..), exitWith)
main =
-import IO -- 1.3
+import IO
main = do
hClose stderr
-import IO -- 1.3
+import IO
main =
openFile "io007.hs" ReadMode >>= \ hIn ->
-import IO -- 1.3
+import IO
main =
openFile "io007.hs" ReadMode >>= \ hIn ->
+-- !!! Test file positioning
+
module Main(main) where
-import IO -- 1.3
---import IOBase -- tryIO 1.3
---import GHCio
+import IO
+import Monad
-import Directory (removeFile)
+import Directory (removeFile, doesFileExist)
main = do
- hIn <- openFile "io008.in" ReadMode
- hOut <- openFile "io008.out" ReadWriteMode
- removeFile "io008.out"
+ hIn <- openFile "io008.in" ReadMode
+ f <- doesFileExist "io008.out"
+ when f (removeFile "io008.out")
+ hOut <- openFile "io008.out" ReadWriteMode
bof <- hGetPosn hIn
copy hIn hOut
hSetPosn bof
try (hGetChar hIn) >>=
either (\ err -> if isEOFError err then return () else error "copy")
( \ x -> hPutChar hOut x >> copy hIn hOut)
-
-import IO -- 1.3
+import IO
import Directory
import IOExts (trace)
-import IO -- 1.3
+-- !!! Test getCPUTime
+
+import IO
import CPUTime
main = do
- h <- openFile "/dev/null" WriteMode
- hPrint h (nfib 30)
+ print (nfib 30)
t <- getCPUTime
print (length (show t)) -- printing the CPU time itself is un-cool if you want to diff the output..
--- If you're testing on a Win32 box, be aware that
--- line termination conventions differ (and that
--- io013 uses /dev/null, which is also unix centric.)
+-- !!! Test seeking
-import IO -- 1.3
+import IO
main = do
h <- openFile "io013.in" ReadMode
hSeek h RelativeSeek (-2)
w <- hGetChar h
putStr (w:"\n")
- ~True <- hIsSeekable h
- hClose h
- h <- openFile "/dev/null" ReadMode
- ~False <- hIsSeekable h
+ True <- hIsSeekable h
hClose h
-import IO -- 1.3
+import IO
main =
sequence (map hIsOpen [stdin, stdout, stderr]) >>= \ opens ->
sequence (map hIsNotBuffered [stdin, stdout, stderr]) >>= \ buffereds ->
print buffereds
where
- -- these didn't make it into 1.3
hIsBlockBuffered h = hGetBuffering h >>= \ b -> return $ case b of { BlockBuffering _ -> True; _ -> False }
hIsLineBuffered h = hGetBuffering h >>= \ b -> return $ case b of { LineBuffering -> True; _ -> False }
hIsNotBuffered h = hGetBuffering h >>= \ b -> return $ case b of { NoBuffering -> True; _ -> False }
-import IO -- 1.3
+import IO
main =
isEOF >>= \ eof ->
-import IO -- 1.3
+import IO
import System (getArgs)
import Char (toUpper)
-import Directory (removeFile)
+import Directory (removeFile, doesFileExist)
main = getArgs >>= \ [f1,f2] ->
openFile f1 ReadMode >>= \ h1 ->
+ doesFileExist f2 >>= \ f ->
+ if f then removeFile f2 else return () >>
openFile f2 WriteMode >>= \ h2 ->
- removeFile f2 >>
copyFile h1 h2 >>
hClose h1 >>
hClose h2
-import IO -- 1.3
+import IO
main =
hSetBuffering stdout NoBuffering >>
-- !!! Testing RW handles
module Main(main) where
-
import IO
-import Directory (removeFile)
+import IOExts
+import Directory (removeFile, doesFileExist)
+import Monad
-- This test is weird, full marks to whoever dreamt it up!
main :: IO ()
main = do
let username = "io018.inout"
+ f <- doesFileExist username
+ when f (removeFile username)
cd <- openFile username ReadWriteMode
- removeFile username
+ hSetBinaryMode cd True
hSetBuffering stdin NoBuffering
hSetBuffering stdout NoBuffering
hSetBuffering cd NoBuffering
speakString = "Someone wants to speak with you\n"
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 ())
+ 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
-import IO -- 1.3
+import IO
main =
hSetBuffering stdin NoBuffering >>
module Main(main) where
import IO
-import Directory ( removeFile )
+import Directory ( removeFile, doesFileExist )
+import Monad
main = do
sz <- hFileSize stdin `catch` (\ _ -> return (-1))
print sz
- let fn = "io025.out"
+ let fn = "io025.out"
+ f <- doesFileExist fn
+ when f (removeFile fn)
hdl <- openFile fn WriteMode
- removeFile fn
- hPutStrLn hdl "file_size"
+ hPutStr hdl "file_size"
-- with default buffering
sz <- hFileSize hdl
print sz
hSetBuffering hdl NoBuffering
- hPutStrLn hdl "file_size"
+ hPutStr hdl "file_size"
-- with no buffering
sz <- hFileSize hdl
print sz
hSetBuffering hdl LineBuffering
- hPutStrLn hdl "file_size"
+ hPutStr hdl "file_size"
-- with line buffering
sz <- hFileSize hdl
print sz
hSetBuffering hdl (BlockBuffering (Just 4))
-- with block buffering
- hPutStrLn hdl "file_size"
+ hPutStr hdl "file_size"
sz <- hFileSize hdl
print sz
hClose hdl
-1
-10
-20
-30
-40
+9
+18
+27
+36
module Main(main) where
import IO
-import Directory ( removeFile )
+import Directory ( removeFile, doesFileExist )
+import Monad
main = do
hFlush stdin `catch` \ _ -> putStrLn "No can do - flushing read-only handles isn't legal"
hdl <- openFile "io029.hs" ReadMode
hFlush hdl `catch` \ _ -> putStrLn "No can do - flushing read-only handles isn't legal"
hClose hdl
+ remove
hdl <- openFile "io029.out" WriteMode
- removeFile "io029.out"
hFlush hdl
hClose hdl
+ remove
hdl <- openFile "io029.out" AppendMode
- removeFile "io029.out"
hFlush hdl
hClose hdl
+ remove
hdl <- openFile "io029.out" ReadWriteMode
- removeFile "io029.out"
hFlush hdl
hClose hdl
+ where remove = do
+ f <- doesFileExist "io029.out"
+ when f (removeFile "io029.out")
module Main(main) where
import IO
-import Directory ( removeFile )
+import Directory ( removeFile, doesFileExist )
+import Monad
-main = do
+main = do
+ f <- doesFileExist "io031.inout"
+ when f (removeFile "io031.inout")
hdl <- openFile "io031.inout" ReadWriteMode
- removeFile "io031.inout"
hSetBuffering hdl LineBuffering
hPutStr hdl "as"
hSeek hdl AbsoluteSeek 0