module Test.Sandbox.HUnit (
assertFailure
, assertBool
, assertEqual
, assertString
, assertException
) where
import Test.Sandbox
import Control.Exception.Lifted
import qualified Test.HUnit
import Test.HUnit.Lang (HUnitFailure (..))
assertFailure :: String
-> Sandbox ()
assertFailure = wrap . liftIO . Test.HUnit.assertFailure
assertBool :: String
-> Bool
-> Sandbox ()
assertBool s b = wrap $ liftIO (Test.HUnit.assertBool s b)
assertEqual :: (Eq a, Show a)
=> String
-> a
-> a
-> Sandbox ()
assertEqual s a b = wrap $ liftIO (Test.HUnit.assertEqual s a b)
assertString :: String
-> Sandbox ()
assertString s = wrap $ liftIO (Test.HUnit.assertString s)
assertException :: String
-> Sandbox a
-> Sandbox ()
assertException s a =
assertBool s =<< (a >> return False) `catchError` const (return True)
wrap :: Sandbox () -> Sandbox ()
wrap action = action `catches` [ Handler hunitHandler ]
where hunitHandler (HUnitFailure e) = throwError e