[project @ 1998-08-12 11:05:14 by simonm]
authorsimonm <unknown>
Wed, 12 Aug 1998 11:05:16 +0000 (11:05 +0000)
committersimonm <unknown>
Wed, 12 Aug 1998 11:05:16 +0000 (11:05 +0000)
Exception library tests.

ghc/tests/lib/should_run/Makefile
ghc/tests/lib/should_run/exceptions001.hs [new file with mode: 0644]
ghc/tests/lib/should_run/exceptions001.stdout [new file with mode: 0644]

index 2df3154..ca76c0f 100644 (file)
@@ -1,5 +1,5 @@
 #-----------------------------------------------------------------------------
-# $Id: Makefile,v 1.4 1998/08/11 21:08:51 sof Exp $
+# $Id: Makefile,v 1.5 1998/08/12 11:05:14 simonm Exp $
 
 TOP = ../..
 include $(TOP)/mk/boilerplate.mk
@@ -8,6 +8,8 @@ include $(TOP)/mk/should_run.mk
 SRC_HC_OPTS += -dcore-lint
 
 packedstring001_HC_OPTS = -syslib misc
+exceptions001_HC_OPTS   = -fglasgow-exts
+
 stableptr001_RUNTEST_OPTS = +RTS -K4m
 dynamic001_HC_OPTS = -syslib exts
 
diff --git a/ghc/tests/lib/should_run/exceptions001.hs b/ghc/tests/lib/should_run/exceptions001.hs
new file mode 100644 (file)
index 0000000..38411a8
--- /dev/null
@@ -0,0 +1,57 @@
+module Main where
+
+import Prelude hiding (catch)
+import Exception
+import IO hiding (try)
+
+main = do
+  ioTest
+  errorTest
+  noMethodTest
+  patMatchTest
+  guardTest
+  dynTest
+
+ioTest :: IO ()
+ioTest = catchIO (fail (userError "wibble")) 
+          (\ex -> if isUserError ex then putStr "io exception caught\n" 
+                                    else error "help!")
+
+errorTest :: IO ()
+errorTest = case getExceptions (1 + error "call to 'error'") of
+               Left exceptions -> putStr "error call caught\n"
+               Right val       -> error "help!"
+
+instance (Show a, Eq a) => Num (Maybe a) where {}
+
+noMethodTest :: IO ()
+noMethodTest = catch (case Just () + Just () of Nothing -> return ())
+  (\exs -> case unsafePromiseSingleton exs of
+               NoMethodError err -> putStr "no method error\n"
+               other             -> error "help!")
+
+patMatchTest :: IO ()
+patMatchTest = catchOne (case test1 [1..10] of () -> return ())
+  (\ex -> case ex of
+               PatternMatchFail err -> putStr err
+               other                -> error "help!")
+                 
+test1 [] = ()
+
+guardTest = catchOne (case test2 of () -> return ())
+  (\ex -> case ex of
+               NonExhaustiveGuards err -> putStr err
+               other                -> error "help!")
+
+test2 | all (==0) [1] = ()
+
+dynTest = catchDyn (case throwDyn (42::Int, (+1)::Int->Int) of () -> return ())
+  (\(i,f) -> let x = f (i::Int) :: Int in putStr (show x))
+
+{-
+recSelTest
+recConTest
+recUpdTest
+assertTest
+arithTest
+-}
diff --git a/ghc/tests/lib/should_run/exceptions001.stdout b/ghc/tests/lib/should_run/exceptions001.stdout
new file mode 100644 (file)
index 0000000..e69de29