{-# LANGUAGE CPP, TypeFamilies, DeriveDataTypeable #-}
module Test.Tasty.HUnit
(
testCase
, testCaseInfo
, testCaseSteps
, assertFailure
, assertBool
, assertEqual
, (@=?)
, (@?=)
, (@?)
, AssertionPredicable(..)
, Assertion
, HUnitFailure(..)
#if MIN_VERSION_base(4,5,0)
, HasCallStack
#endif
, assertString
, Assertable(..)
, AssertionPredicate
) where
import Test.Tasty.Providers
import Test.Tasty.HUnit.Orig
import Test.Tasty.HUnit.Steps
import Control.Exception
import Data.Typeable
#if MIN_VERSION_base(4,5,0)
import Data.CallStack (HasCallStack)
#else
#define HasCallStack Eq ()
#endif
testCase :: TestName -> Assertion -> TestTree
testCase :: TestName -> Assertion -> TestTree
testCase TestName
name = TestName -> TestCase -> TestTree
forall t. IsTest t => TestName -> t -> TestTree
singleTest TestName
name (TestCase -> TestTree)
-> (Assertion -> TestCase) -> Assertion -> TestTree
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO TestName -> TestCase
TestCase (IO TestName -> TestCase)
-> (Assertion -> IO TestName) -> Assertion -> TestCase
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((() -> TestName) -> Assertion -> IO TestName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (TestName -> () -> TestName
forall a b. a -> b -> a
const TestName
""))
testCaseInfo :: TestName -> IO String -> TestTree
testCaseInfo :: TestName -> IO TestName -> TestTree
testCaseInfo TestName
name = TestName -> TestCase -> TestTree
forall t. IsTest t => TestName -> t -> TestTree
singleTest TestName
name (TestCase -> TestTree)
-> (IO TestName -> TestCase) -> IO TestName -> TestTree
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO TestName -> TestCase
TestCase
newtype TestCase = TestCase (IO String)
deriving Typeable
instance IsTest TestCase where
run :: OptionSet -> TestCase -> (Progress -> Assertion) -> IO Result
run OptionSet
_ (TestCase IO TestName
assertion) Progress -> Assertion
_ = do
Either HUnitFailure TestName
hunitResult <- IO TestName -> IO (Either HUnitFailure TestName)
forall e a. Exception e => IO a -> IO (Either e a)
try IO TestName
assertion
Result -> IO Result
forall (m :: * -> *) a. Monad m => a -> m a
return (Result -> IO Result) -> Result -> IO Result
forall a b. (a -> b) -> a -> b
$
case Either HUnitFailure TestName
hunitResult of
Right TestName
info -> TestName -> Result
testPassed TestName
info
Left (HUnitFailure Maybe SrcLoc
mbloc TestName
message) -> TestName -> Result
testFailed (TestName -> Result) -> TestName -> Result
forall a b. (a -> b) -> a -> b
$ Maybe SrcLoc -> TestName -> TestName
prependLocation Maybe SrcLoc
mbloc TestName
message
testOptions :: Tagged TestCase [OptionDescription]
testOptions = [OptionDescription] -> Tagged TestCase [OptionDescription]
forall (m :: * -> *) a. Monad m => a -> m a
return []