summaryrefslogtreecommitdiff
path: root/testsuite/tests/codeGen/should_run/T5129.hs
blob: 2808f54eaec918a3b8ec713cd4b61553ecea3c3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{-# LANGUAGE DeriveDataTypeable #-}
import Control.Exception as E
import Data.Typeable

throwIfNegative :: Int -> String
throwIfNegative n | n < 0     = error "negative"
                  | otherwise = "no worries"
{-# NOINLINE throwIfNegative #-}

data HUnitFailure = HUnitFailure String deriving (Show,Typeable)
instance Exception HUnitFailure

assertFailure :: String -> a -- Not an IO function!
assertFailure msg = E.throw (HUnitFailure msg)

main :: IO ()
main =
    handleJust errorCalls (const (return ())) (do
        evaluate (throwIfNegative (-1)) -- Pure expression evaluated in IO
        assertFailure "must throw when given a negative number")
  where errorCalls (ErrorCall _) = Just ()