Commit d421a688 authored by Ian Lynagh's avatar Ian Lynagh

Remove the haskell98 dependency from the lib/IO tests

parent 32bdc52e
-- !!! IOErrors should have Eq defined
import IO
import System.IO
main = print (userError "urk" == userError "urk")
......@@ -2,7 +2,8 @@
-- there are rather than closing the first read handle causing the
-- lock to be released.
import IO
import System.IO
import System.IO.Error
file = "countReaders001.txt"
......@@ -12,5 +13,5 @@ main = do
h1 <- openFile file ReadMode
h2 <- openFile file ReadMode
hClose h1
try (openFile file AppendMode) >>= print
tryIOError (openFile file AppendMode) >>= print
import IO
import System.IO
import System.IO.Error
main = do
h <- openFile "hClose001.tmp" WriteMode
hPutStr h "junk"
hClose h
hPutStr h "junk" `catch` \ err -> if isIllegalOperation err then putStr "Okay\n" else error "Not okay\n"
hPutStr h "junk" `catchIOError` \ err -> if isIllegalOperation err then putStr "Okay\n" else error "Not okay\n"
import GHC.Handle
import GHC.IOBase
import IO
import System.IO
import Control.Concurrent.MVar
import Data.Typeable
import qualified GHC.IO.FD as FD
......
import IO
import System.IO
-- !!! test hFileSize
......
-- !!! Testing IO.hFileSize
module Main(main) where
import IO
import Directory ( removeFile, doesFileExist )
import Monad
import Control.Monad
import System.Directory ( removeFile, doesFileExist )
import System.IO
main = do
sz <- hFileSize stdin `catch` (\ _ -> return (-1))
......
-- !!! Flushing
module Main(main) where
import IO
import Directory ( removeFile, doesFileExist )
import Monad
import Control.Monad
import System.Directory ( removeFile, doesFileExist )
import System.IO
main = do
hFlush stdin `catch` \ _ -> putStrLn "No can do - flushing read-only handles isn't legal"
......
import IO
import System.IO
main =
sequence (map hIsOpen [stdin, stdout, stderr]) >>= \ opens ->
......
import IO
import System.IO
main = do
hSetBuffering stdout NoBuffering
......
......@@ -5,7 +5,7 @@
--
-- However, we don't believe that this is the right behaviour.
import IO
import System.IO
main = catch loop (\e -> print e)
......
import IO
import System.IO
main = f stdin
where f h = do p <- hIsEOF h
......
-- !!! hIsEOF (on stdout)
import IO ( hIsEOF, stdout )
import System.IO ( hIsEOF, stdout )
main = do
flg <- hIsEOF stdout `catch` \ _ -> putStrLn "hIsEOF failed" >> return False
......
import IO
import System.IO
main =
hSetBuffering stdin NoBuffering >>
......
import IO
import System.IO
main =
hSetBuffering stdin NoBuffering >>
......
-- !!! Reconfiguring the buffering of a handle
module Main(main) where
import IO
import System.IO
queryBuffering :: String -> Handle -> IO ()
queryBuffering handle_nm handle = do
......
import IO
import System.IO
main = isEOF >>= print
import IO
import System.IO
import System (getArgs)
import Char (toUpper)
import Directory (removeFile, doesFileExist)
import Data.Char (toUpper)
import System.Directory (removeFile, doesFileExist)
import System.Environment (getArgs)
main = do
[f1,f2] <- getArgs
......
-- !!! test that a file opened in ReadMode can't be written to
import IO
import System.IO
import System.IO.Error
main = do
hIn <- openFile "openFile001.hs" ReadMode
hPutStr hIn "test" `catch` \ err ->
hPutStr hIn "test" `catchIOError` \ err ->
if isIllegalOperation err
then putStrLn "ok."
else error "Oh dear\n"
import Char
import IO
import Data.Char
import System.IO
-- !!! Open a non-existent file for reading (should fail)
......
import IO
import System.IO
import System.IO.Error
-- !!! Open a directory (should fail)
main = do
r <- try (openFile "." ReadMode)
r <- tryIOError (openFile "." ReadMode)
print r
r <- try (openFile "." WriteMode)
r <- tryIOError (openFile "." WriteMode)
print r
r <- try (openFile "." AppendMode)
r <- tryIOError (openFile "." AppendMode)
print r
r <- try (openFile "." ReadWriteMode)
r <- tryIOError (openFile "." ReadWriteMode)
print r
-- !!! Open a non-existent file for writing
import Char
import IO
import Directory
import Monad
import Control.Monad
import Data.Char
import System.Directory
import System.IO
file = "openFile004.out"
......
-- !!! test multiple-reader single-writer locking semantics
import IO
import System.IO
import System.IO.Error
file1 = "openFile005.out1"
file2 = "openFile005.out2"
......@@ -8,27 +9,27 @@ file2 = "openFile005.out2"
main = do
putStrLn "two writes (should fail)"
h <- openFile file1 WriteMode
try (openFile file1 WriteMode) >>= print
tryIOError (openFile file1 WriteMode) >>= print
hClose h
putStrLn "write and an append (should fail)"
h <- openFile file1 WriteMode
try (openFile file1 AppendMode) >>= print
tryIOError (openFile file1 AppendMode) >>= print
hClose h
putStrLn "read/write and a write (should fail)"
h <- openFile file1 ReadWriteMode
try (openFile file1 WriteMode) >>= print
tryIOError (openFile file1 WriteMode) >>= print
hClose h
putStrLn "read and a read/write (should fail)"
h <- openFile file1 ReadMode
try (openFile file1 ReadWriteMode) >>= print
tryIOError (openFile file1 ReadWriteMode) >>= print
hClose h
putStrLn "write and a read (should fail)"
h <- openFile file1 WriteMode
try (openFile file1 ReadMode) >>= print
tryIOError (openFile file1 ReadMode) >>= print
hClose h
putStrLn "two writes, different files (silly, but should succeed)"
......
-- !!! opening a file in WriteMode better truncate it
import IO
import System.IO
main = do
h <- openFile "openFile006.out" AppendMode
......
-- !!! check that we don't truncate files if the open fails
import IO
import Monad
import Control.Monad
import System.IO
import System.IO.Error
tmp = "openFile007.out"
......@@ -10,7 +11,7 @@ main = do
hPutStrLn h "hello, world"
-- second open in write mode better fail, but better not truncate the file
try (openFile tmp WriteMode) >>= print
tryIOError (openFile tmp WriteMode) >>= print
hClose h
s <- readFile tmp -- make sure our "hello, world" is still there
......
-- !!! readFile test
import IO
import System.IO
import System.IO.Error
source = "readFile001.hs"
filename = "readFile001.out"
......@@ -14,7 +15,7 @@ main = do
-- This open should fail, because the readFile hasn't been forced
-- and the file is therefore still locked.
try (openFile filename WriteMode) >>= print
tryIOError (openFile filename WriteMode) >>= print
putStrLn s
......
Left readFile001.out: openFile: resource busy (file is locked)
-- !!! readFile test
import IO
import System.IO
import System.IO.Error
source = "readFile001.hs"
filename = "readFile001.out"
......@@ -15,7 +16,7 @@ main = do
-- This open should fail, because the readFile hasn't been forced
-- and the file is therefore still locked.
try (openFile filename WriteMode) >>= print
tryIOError (openFile filename WriteMode) >>= print
putStrLn s
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment