33320087857f6c4a46bdd62a737718038c79917b
[ghc-hetmet.git] / ghc / tests / lib / should_run / exceptions001.hs
1 module Main where
2
3 import Prelude hiding (catch)
4 import Exception 
5 import IO hiding (try, catch)
6
7 main = do
8   ioTest
9   errorTest
10   noMethodTest
11   patMatchTest
12   guardTest
13   dynTest
14
15 ioTest :: IO ()
16 ioTest = catchIO justIoErrors (ioError (userError "wibble")) 
17            (\ex -> if isUserError ex then putStr "io exception caught\n" 
18                                      else error "help!")
19
20 errorTest :: IO ()
21 errorTest = tryAll (1 + error "call to 'error'") >>= \r ->
22             case r of
23                 Left exception -> putStr "error call caught\n"
24                 Right _        -> error "help!"
25
26 instance (Show a, Eq a) => Num (Maybe a) where {}
27
28 noMethodTest :: IO ()
29 noMethodTest = tryAll (Just () + Just ()) >>= \ r ->
30         case r of
31                 Left (NoMethodError err) -> putStr "no method error\n"
32                 Right _                  -> error "help!"
33
34 patMatchTest :: IO ()
35 patMatchTest = catchAllIO (case test1 [1..10] of () -> return ())
36   (\ex -> case ex of
37                 PatternMatchFail err -> putStr err
38                 other                -> error "help!")
39                   
40 test1 [] = ()
41
42 guardTest = catchAllIO (case test2 of () -> return ())
43   (\ex -> case ex of
44                 PatternMatchFail err -> putStr err
45                 other                -> error "help!")
46
47 test2 | all (==0) [1] = ()
48
49 dynTest = catchDyn (case throwDyn (42::Int, (+1)::Int->Int) of () -> return ())
50   (\(i,f) -> let x = f (i::Int) :: Int in putStr (show x))
51
52 {-
53 recSelTest
54 recConTest
55 recUpdTest
56 assertTest
57 arithTest
58 -}