38411a81b49680d947c9a34f85cd3144842e50c7
[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)
6
7 main = do
8   ioTest
9   errorTest
10   noMethodTest
11   patMatchTest
12   guardTest
13   dynTest
14
15 ioTest :: IO ()
16 ioTest = catchIO (fail (userError "wibble")) 
17            (\ex -> if isUserError ex then putStr "io exception caught\n" 
18                                      else error "help!")
19
20 errorTest :: IO ()
21 errorTest = case getExceptions (1 + error "call to 'error'") of
22                 Left exceptions -> putStr "error call caught\n"
23                 Right val       -> error "help!"
24
25 instance (Show a, Eq a) => Num (Maybe a) where {}
26
27 noMethodTest :: IO ()
28 noMethodTest = catch (case Just () + Just () of Nothing -> return ())
29   (\exs -> case unsafePromiseSingleton exs of
30                 NoMethodError err -> putStr "no method error\n"
31                 other             -> error "help!")
32
33 patMatchTest :: IO ()
34 patMatchTest = catchOne (case test1 [1..10] of () -> return ())
35   (\ex -> case ex of
36                 PatternMatchFail err -> putStr err
37                 other                -> error "help!")
38                   
39 test1 [] = ()
40
41 guardTest = catchOne (case test2 of () -> return ())
42   (\ex -> case ex of
43                 NonExhaustiveGuards err -> putStr err
44                 other                -> error "help!")
45
46 test2 | all (==0) [1] = ()
47
48 dynTest = catchDyn (case throwDyn (42::Int, (+1)::Int->Int) of () -> return ())
49   (\(i,f) -> let x = f (i::Int) :: Int in putStr (show x))
50
51 {-
52 recSelTest
53 recConTest
54 recUpdTest
55 assertTest
56 arithTest
57 -}