diff options
22 files changed, 45 insertions, 41 deletions
diff --git a/libraries/base/tests/IO/2122.hs b/libraries/base/tests/IO/2122.hs index 6807f3476a..3c0788d13b 100644 --- a/libraries/base/tests/IO/2122.hs +++ b/libraries/base/tests/IO/2122.hs @@ -22,6 +22,7 @@ Test.hs: writeFile: /tmp/test: openFile: resource busy (file is locked) import Control.Monad import System.Directory import System.IO +import System.IO.Error import System.Environment -- Used by test2: -- import System.Posix.IO @@ -37,26 +38,26 @@ main = do -- or when compiled. test :: Bool -> IO () test causeFailure = - do h1 <- openFile fp ReadMode `Prelude.catch` (\e -> error ("openFile 1: " ++ show e)) + do h1 <- openFile fp ReadMode `catchIOError` (\e -> error ("openFile 1: " ++ show e)) when causeFailure $ do - h2 <- openFile fp ReadMode `Prelude.catch` (\e -> error ("openFile 2: " ++ show e)) + h2 <- openFile fp ReadMode `catchIOError` (\e -> error ("openFile 2: " ++ show e)) hClose h2 hClose h1 removeFile fp - writeFile fp (show [1..100]) `Prelude.catch` (\e -> error ("writeFile: " ++ show e)) + writeFile fp (show [1..100]) `catchIOError` (\e -> error ("writeFile: " ++ show e)) {- -- this version never fails (except in GHCi, if test has previously failed). -- probably because openFd does not try to lock the file test2 :: Bool -> IO () test2 causeFailure = - do fd1 <- openFd fp ReadOnly Nothing defaultFileFlags `Prelude.catch` (\e -> error ("openFile 1: " ++ show e)) + do fd1 <- openFd fp ReadOnly Nothing defaultFileFlags `catchIOError` (\e -> error ("openFile 1: " ++ show e)) when causeFailure $ do - fd2 <- openFd fp ReadOnly Nothing defaultFileFlags `Prelude.catch` (\e -> error ("openFile 2: " ++ show e)) + fd2 <- openFd fp ReadOnly Nothing defaultFileFlags `catchIOError` (\e -> error ("openFile 2: " ++ show e)) closeFd fd2 closeFd fd1 removeFile fp - writeFile fp (show [1..100]) `Prelude.catch` (\e -> error ("writeFile: " ++ show e)) + writeFile fp (show [1..100]) `catchIOError` (\e -> error ("writeFile: " ++ show e)) -} {- @@ -64,10 +65,10 @@ test2 causeFailure = -- runhaskell or compiled test3 :: IO () test3 = - do h1 <- openFile fp ReadMode `Prelude.catch` (\e -> error ("openFile 1: " ++ show e)) - h2 <- openFile fp ReadMode `Prelude.catch` (\e -> error ("openFile 2: " ++ show e)) + do h1 <- openFile fp ReadMode `catchIOError` (\e -> error ("openFile 1: " ++ show e)) + h2 <- openFile fp ReadMode `catchIOError` (\e -> error ("openFile 2: " ++ show e)) removeFile fp - writeFile fp (show [1..100]) `Prelude.catch` (\e -> error ("writeFile: " ++ show e)) + writeFile fp (show [1..100]) `catchIOError` (\e -> error ("writeFile: " ++ show e)) print =<< hGetContents h1 print =<< hGetContents h2 hClose h2 diff --git a/libraries/base/tests/IO/IOError001.hs b/libraries/base/tests/IO/IOError001.hs index dee7f31e29..4f7c4b27d6 100644 --- a/libraries/base/tests/IO/IOError001.hs +++ b/libraries/base/tests/IO/IOError001.hs @@ -1,7 +1,9 @@ +import System.IO.Error + -- test for a bug in GHC <= 4.08.2: handles were being left locked after -- being shown in an error message. main = do getContents - catch getChar (\e -> print e >> return 'x') - catch getChar (\e -> print e >> return 'x') + catchIOError getChar (\e -> print e >> return 'x') + catchIOError getChar (\e -> print e >> return 'x') diff --git a/libraries/base/tests/IO/decodingerror001.hs b/libraries/base/tests/IO/decodingerror001.hs index 6c9dca1489..15663c412d 100644 --- a/libraries/base/tests/IO/decodingerror001.hs +++ b/libraries/base/tests/IO/decodingerror001.hs @@ -18,5 +18,5 @@ test file bufmode = do h <- openFile file ReadMode hSetEncoding h utf8 hSetBuffering h bufmode - e <- try $ forever $ hGetChar h >>= putChar + e <- tryIOError $ forever $ hGetChar h >>= putChar print (e :: Either IOError ()) diff --git a/libraries/base/tests/IO/decodingerror002.hs b/libraries/base/tests/IO/decodingerror002.hs index db610bdebd..06cc6fd45e 100644 --- a/libraries/base/tests/IO/decodingerror002.hs +++ b/libraries/base/tests/IO/decodingerror002.hs @@ -19,5 +19,5 @@ test file enc_name = do h <- openFile file ReadMode enc <- mkTextEncoding enc_name hSetEncoding h enc - e <- try $ forever $ hGetChar h >>= putChar + e <- tryIOError $ forever $ hGetChar h >>= putChar print (e :: Either IOError ()) diff --git a/libraries/base/tests/IO/encoding002.hs b/libraries/base/tests/IO/encoding002.hs index 65d60a3993..2a394582fb 100644 --- a/libraries/base/tests/IO/encoding002.hs +++ b/libraries/base/tests/IO/encoding002.hs @@ -12,8 +12,6 @@ import GHC.IO.Encoding (TextEncoding, mkTextEncoding) import Data.Char import Data.Word -import Prelude hiding (catch) - decode :: TextEncoding -> [Word8] -> IO String decode enc xs = withArrayLen xs (\sz p -> peekCStringLen enc (castPtr p, sz)) `catch` \e -> return (show (e :: IOException)) diff --git a/libraries/base/tests/IO/encodingerror001.hs b/libraries/base/tests/IO/encodingerror001.hs index 327b490adb..2cfc6e6a01 100644 --- a/libraries/base/tests/IO/encodingerror001.hs +++ b/libraries/base/tests/IO/encodingerror001.hs @@ -20,7 +20,7 @@ main = do checkedPutStr "Hello αβγ\n" -- we should write at least the "Hello " checkedPutStr str = do - r <- try $ putStr str + r <- tryIOError $ putStr str case r of Right _ -> return () Left e -> printf "Caught %s while trying to write %s\n" diff --git a/libraries/base/tests/IO/hFileSize002.hs b/libraries/base/tests/IO/hFileSize002.hs index 6c1ad2f57a..03caf1036a 100644 --- a/libraries/base/tests/IO/hFileSize002.hs +++ b/libraries/base/tests/IO/hFileSize002.hs @@ -4,9 +4,10 @@ module Main(main) where import Control.Monad import System.Directory ( removeFile, doesFileExist ) import System.IO +import System.IO.Error main = do - sz <- hFileSize stdin `catch` (\ _ -> return (-1)) + sz <- hFileSize stdin `catchIOError` (\ _ -> return (-1)) print sz let fn = "hFileSize002.out" f <- doesFileExist fn diff --git a/libraries/base/tests/IO/hFlush001.hs b/libraries/base/tests/IO/hFlush001.hs index 78c7b7eeb3..a061f9472d 100644 --- a/libraries/base/tests/IO/hFlush001.hs +++ b/libraries/base/tests/IO/hFlush001.hs @@ -4,15 +4,16 @@ module Main(main) where import Control.Monad import System.Directory ( removeFile, doesFileExist ) import System.IO +import System.IO.Error main = do - hFlush stdin `catch` \ _ -> putStrLn "No can do - flushing read-only handles isn't legal" + hFlush stdin `catchIOError` \ _ -> putStrLn "No can do - flushing read-only handles isn't legal" putStr "Hello," hFlush stdout putStr "Hello - " hFlush stderr hdl <- openFile "hFlush001.hs" ReadMode - hFlush hdl `catch` \ _ -> putStrLn "No can do - flushing read-only handles isn't legal" + hFlush hdl `catchIOError` \ _ -> putStrLn "No can do - flushing read-only handles isn't legal" hClose hdl remove hdl <- openFile "hFlush001.out" WriteMode diff --git a/libraries/base/tests/IO/hGetLine002.hs b/libraries/base/tests/IO/hGetLine002.hs index 5c08b716d1..5185d9eea9 100644 --- a/libraries/base/tests/IO/hGetLine002.hs +++ b/libraries/base/tests/IO/hGetLine002.hs @@ -6,8 +6,9 @@ -- However, we don't believe that this is the right behaviour. import System.IO +import System.IO.Error -main = catch loop (\e -> print e) +main = catchIOError loop (\e -> print e) loop = do hSetBuffering stdin LineBuffering diff --git a/libraries/base/tests/IO/hGetPosn001.hs b/libraries/base/tests/IO/hGetPosn001.hs index 5a0d7d4827..0a1a39b725 100644 --- a/libraries/base/tests/IO/hGetPosn001.hs +++ b/libraries/base/tests/IO/hGetPosn001.hs @@ -23,6 +23,6 @@ main = do copy :: Handle -> Handle -> IO () copy hIn hOut = - try (hGetChar hIn) >>= + tryIOError (hGetChar hIn) >>= either (\ err -> if isEOFError err then return () else error "copy") ( \ x -> hPutChar hOut x >> copy hIn hOut) diff --git a/libraries/base/tests/IO/hIsEOF001.hs b/libraries/base/tests/IO/hIsEOF001.hs index 2e5dbdcb0a..2230687edb 100644 --- a/libraries/base/tests/IO/hIsEOF001.hs +++ b/libraries/base/tests/IO/hIsEOF001.hs @@ -1,7 +1,8 @@ -- !!! hIsEOF (on stdout) import System.IO ( hIsEOF, stdout ) +import System.IO.Error main = do - flg <- hIsEOF stdout `catch` \ _ -> putStrLn "hIsEOF failed" >> return False + flg <- hIsEOF stdout `catchIOError` \ _ -> putStrLn "hIsEOF failed" >> return False print flg diff --git a/libraries/base/tests/IO/hReady001.hs b/libraries/base/tests/IO/hReady001.hs index 00888dac2d..bb7be1c78b 100644 --- a/libraries/base/tests/IO/hReady001.hs +++ b/libraries/base/tests/IO/hReady001.hs @@ -3,9 +3,10 @@ -- hReady should throw and EOF exception at the end of a file. Trac #1063. import System.IO +import System.IO.Error main = do h <- openFile "hReady001.hs" ReadMode hReady h >>= print hSeek h SeekFromEnd 0 - (hReady h >> return ()) `catch` print + (hReady h >> return ()) `catchIOError` print diff --git a/libraries/base/tests/IO/hSeek004.hs b/libraries/base/tests/IO/hSeek004.hs index 9ad7c13e7f..fd59741bc8 100644 --- a/libraries/base/tests/IO/hSeek004.hs +++ b/libraries/base/tests/IO/hSeek004.hs @@ -5,4 +5,4 @@ import System.IO.Error main = do h <- openFile "hSeek004.out" AppendMode - try (hSeek h AbsoluteSeek 0) >>= print + tryIOError (hSeek h AbsoluteSeek 0) >>= print diff --git a/libraries/base/tests/IO/hSetBuffering003.hs b/libraries/base/tests/IO/hSetBuffering003.hs index 74d399e4ff..3e66f6e524 100644 --- a/libraries/base/tests/IO/hSetBuffering003.hs +++ b/libraries/base/tests/IO/hSetBuffering003.hs @@ -2,6 +2,7 @@ module Main(main) where import System.IO +import System.IO.Error queryBuffering :: String -> Handle -> IO () queryBuffering handle_nm handle = do @@ -23,7 +24,7 @@ main = do hSetBuffering stdin (BlockBuffering Nothing) queryBuffering "stdin" stdin let bmo = BlockBuffering (Just (-3)) - hSetBuffering stdin bmo `catch` \ _ -> putStrLn ("Caught illegal op: hSetBuffering stdin " ++ showParen True (showsPrec 9 bmo) []) + hSetBuffering stdin bmo `catchIOError` \ _ -> putStrLn ("Caught illegal op: hSetBuffering stdin " ++ showParen True (showsPrec 9 bmo) []) putChar '\n' @@ -42,7 +43,7 @@ main = do queryBuffering "stdout" stdout hPutStr stdout "Hello stdout 5" let bmo = BlockBuffering (Just (-3)) - hSetBuffering stdout bmo `catch` \ _ -> putStrLn ("Caught illegal op: hSetBuffering stdout " ++ showParen True (showsPrec 9 bmo) []) + hSetBuffering stdout bmo `catchIOError` \ _ -> putStrLn ("Caught illegal op: hSetBuffering stdout " ++ showParen True (showsPrec 9 bmo) []) putChar '\n' @@ -61,7 +62,7 @@ main = do queryBuffering "stderr" stderr hPutStr stderr "Hello stderr 5" let bmo = BlockBuffering (Just (-3)) - hSetBuffering stderr bmo `catch` \ _ -> putStrLn ("Caught illegal op: hSetBuffering stderr " ++ showParen True (showsPrec 9 bmo) []) + hSetBuffering stderr bmo `catchIOError` \ _ -> putStrLn ("Caught illegal op: hSetBuffering stderr " ++ showParen True (showsPrec 9 bmo) []) ls <- hGetContents stdin ls' <- putLine ls diff --git a/libraries/base/tests/IO/ioeGetErrorString001.hs b/libraries/base/tests/IO/ioeGetErrorString001.hs index 5621136a55..361ae62437 100644 --- a/libraries/base/tests/IO/ioeGetErrorString001.hs +++ b/libraries/base/tests/IO/ioeGetErrorString001.hs @@ -7,7 +7,7 @@ import Data.Maybe main = do h <- openFile "ioeGetErrorString001.hs" ReadMode hSeek h SeekFromEnd 0 - (hGetChar h >> return ()) `catch` + (hGetChar h >> return ()) `catchIOError` \e -> if isEOFError e then print (ioeGetErrorString e) else putStrLn "failed." diff --git a/libraries/base/tests/IO/ioeGetFileName001.hs b/libraries/base/tests/IO/ioeGetFileName001.hs index 12c70c98b4..410093f027 100644 --- a/libraries/base/tests/IO/ioeGetFileName001.hs +++ b/libraries/base/tests/IO/ioeGetFileName001.hs @@ -6,7 +6,7 @@ import System.IO.Error main = do h <- openFile "ioeGetFileName001.hs" ReadMode hSeek h SeekFromEnd 0 - (hGetChar h >> return ()) `catch` + (hGetChar h >> return ()) `catchIOError` \e -> if isEOFError e then print (ioeGetFileName e) else putStrLn "failed." diff --git a/libraries/base/tests/IO/ioeGetHandle001.hs b/libraries/base/tests/IO/ioeGetHandle001.hs index a9ef58a8ca..1f9c22e20d 100644 --- a/libraries/base/tests/IO/ioeGetHandle001.hs +++ b/libraries/base/tests/IO/ioeGetHandle001.hs @@ -7,7 +7,7 @@ import Data.Maybe main = do h <- openFile "ioeGetHandle001.hs" ReadMode hSeek h SeekFromEnd 0 - (hGetChar h >> return ()) `catch` + (hGetChar h >> return ()) `catchIOError` \e -> if isEOFError e && fromJust (ioeGetHandle e) == h then putStrLn "ok." else putStrLn "failed." diff --git a/libraries/base/tests/IO/readwrite002.hs b/libraries/base/tests/IO/readwrite002.hs index 4bb607e395..4623f430a9 100644 --- a/libraries/base/tests/IO/readwrite002.hs +++ b/libraries/base/tests/IO/readwrite002.hs @@ -25,14 +25,14 @@ main = do -- hSetBuffering cd NoBuffering hPutStr cd speakString hSeek cd AbsoluteSeek 0 - speak cd `catch` \ err -> if isEOFError err then putStrLn "\nCaught EOF" else ioError err + speak cd `catchIOError` \ err -> if isEOFError err then putStrLn "\nCaught EOF" else ioError err hSeek cd AbsoluteSeek 0 hSetBuffering cd LineBuffering - speak cd `catch` \ err -> if isEOFError err then putStrLn "\nCaught EOF" else ioError err + speak cd `catchIOError` \ err -> if isEOFError err then putStrLn "\nCaught EOF" else ioError err return () hSeek cd AbsoluteSeek 0 hSetBuffering cd (BlockBuffering Nothing) - speak cd `catch` \ err -> if isEOFError err then putStrLn "\nCaught EOF" else ioError err + speak cd `catchIOError` \ err -> if isEOFError err then putStrLn "\nCaught EOF" else ioError err speakString = "##############################\n" diff --git a/libraries/base/tests/enum04.hs b/libraries/base/tests/enum04.hs index fed9e8c4ef..8120a5bb21 100644 --- a/libraries/base/tests/enum04.hs +++ b/libraries/base/tests/enum04.hs @@ -1,6 +1,5 @@ {-# LANGUAGE ScopedTypeVariables #-} import Control.Exception -import Prelude hiding (catch) -- enumFrom on basic numeric types should be strict -- (possibly a bug in the Haskell Report: it specifies that diff --git a/libraries/base/tests/exceptionsrun001.hs b/libraries/base/tests/exceptionsrun001.hs index c858ba5574..46ab9fa6cc 100644 --- a/libraries/base/tests/exceptionsrun001.hs +++ b/libraries/base/tests/exceptionsrun001.hs @@ -1,8 +1,7 @@ module Main where -import Prelude hiding (catch) import Control.Exception -import System.IO.Error hiding (catch, try) +import System.IO.Error main = do ioTest diff --git a/libraries/base/tests/exceptionsrun001.stdout b/libraries/base/tests/exceptionsrun001.stdout index a84f33ace9..4c3fa006b1 100644 --- a/libraries/base/tests/exceptionsrun001.stdout +++ b/libraries/base/tests/exceptionsrun001.stdout @@ -1,5 +1,5 @@ user exception caught error call caught no method error -exceptionsrun001.hs:39:1-13: Non-exhaustive patterns in function test1 -exceptionsrun001.hs:46:1-26: Non-exhaustive patterns in function test2 +exceptionsrun001.hs:38:1-13: Non-exhaustive patterns in function test1 +exceptionsrun001.hs:45:1-26: Non-exhaustive patterns in function test2 diff --git a/libraries/base/tests/exceptionsrun002.hs b/libraries/base/tests/exceptionsrun002.hs index 9503001a31..0dae46117d 100644 --- a/libraries/base/tests/exceptionsrun002.hs +++ b/libraries/base/tests/exceptionsrun002.hs @@ -1,9 +1,8 @@ module Main where import qualified Control.Exception as Exception -import System.IO.Error (mkIOError) +import System.IO.Error (mkIOError, catchIOError) import Data.IORef -import Prelude safeCatch :: IO () -> IO () safeCatch f = Exception.catch f @@ -79,7 +78,7 @@ bindCatcher = MkNamed ">>" (>>) preludeCatchCatcher :: Named Catcher preludeCatchCatcher = MkNamed "Prelude.catch" - (\f cc -> Prelude.catch (f >> (return ())) (const cc)) + (\f cc -> catchIOError (f >> (return ())) (const cc)) ceCatchCatcher :: Named Catcher ceCatchCatcher = MkNamed "Exception.catch" |