{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Control.Teardown.Internal.Types where
import RIO
import RIO.Time (NominalDiffTime)
#if MIN_VERSION_base(4,9,0)
import GHC.Generics (Generic)
#endif
type Description = Text
data TeardownResult
= BranchResult
{
resultDescription :: !Description
, resultElapsedTime :: !NominalDiffTime
, resultDidFail :: !Bool
, resultListing :: ![TeardownResult]
}
| LeafResult
{
resultDescription :: !Description
, resultElapsedTime :: !NominalDiffTime
, resultError :: !(Maybe SomeException)
}
| EmptyResult
{
resultDescription :: !Description
}
deriving (Generic, Show)
getElapsedTime :: TeardownResult -> NominalDiffTime
getElapsedTime result =
case result of
BranchResult {resultElapsedTime} -> resultElapsedTime
LeafResult {resultElapsedTime} -> resultElapsedTime
EmptyResult {} -> 0
instance NFData TeardownResult where
rnf result =
case result of
EmptyResult !_desc ->
()
LeafResult !_desc !_time !_err ->
()
BranchResult !_desc !_time !_didFail listing ->
rnf listing
newtype Teardown
= Teardown (IO TeardownResult)
deriving (Generic)
instance NFData Teardown where
rnf !_ = ()
class HasTeardown teardown where
getTeardown :: teardown -> Teardown
class IResource resource where
newTeardown :: Text -> resource -> IO Teardown