{-# LANGUAGE CPP #-}
module Test.Hspec.Core.Runner.Result (
SpecResult(SpecResult)
, specResultItems
, specResultSuccess
, ResultItem(ResultItem)
, resultItemPath
, resultItemStatus
, resultItemIsFailure
, ResultItemStatus(..)
, Summary(..)
, toSummary
, isSuccess
, toSpecResult
) where
import Prelude ()
import Test.Hspec.Core.Compat
import Test.Hspec.Core.Util
import qualified Test.Hspec.Core.Format as Format
data SpecResult = SpecResult {
SpecResult -> [ResultItem]
specResultItems :: [ResultItem]
, SpecResult -> Bool
specResultSuccess :: !Bool
} deriving (SpecResult -> SpecResult -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SpecResult -> SpecResult -> Bool
$c/= :: SpecResult -> SpecResult -> Bool
== :: SpecResult -> SpecResult -> Bool
$c== :: SpecResult -> SpecResult -> Bool
Eq, Int -> SpecResult -> ShowS
[SpecResult] -> ShowS
SpecResult -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SpecResult] -> ShowS
$cshowList :: [SpecResult] -> ShowS
show :: SpecResult -> String
$cshow :: SpecResult -> String
showsPrec :: Int -> SpecResult -> ShowS
$cshowsPrec :: Int -> SpecResult -> ShowS
Show)
data ResultItem = ResultItem {
ResultItem -> Path
resultItemPath :: Path
, ResultItem -> ResultItemStatus
resultItemStatus :: ResultItemStatus
} deriving (ResultItem -> ResultItem -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultItem -> ResultItem -> Bool
$c/= :: ResultItem -> ResultItem -> Bool
== :: ResultItem -> ResultItem -> Bool
$c== :: ResultItem -> ResultItem -> Bool
Eq, Int -> ResultItem -> ShowS
[ResultItem] -> ShowS
ResultItem -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResultItem] -> ShowS
$cshowList :: [ResultItem] -> ShowS
show :: ResultItem -> String
$cshow :: ResultItem -> String
showsPrec :: Int -> ResultItem -> ShowS
$cshowsPrec :: Int -> ResultItem -> ShowS
Show)
resultItemIsFailure :: ResultItem -> Bool
resultItemIsFailure :: ResultItem -> Bool
resultItemIsFailure ResultItem
item = case ResultItem -> ResultItemStatus
resultItemStatus ResultItem
item of
ResultItemStatus
ResultItemSuccess -> Bool
False
ResultItemStatus
ResultItemPending -> Bool
False
ResultItemStatus
ResultItemFailure -> Bool
True
data ResultItemStatus =
ResultItemSuccess
| ResultItemPending
| ResultItemFailure
deriving (ResultItemStatus -> ResultItemStatus -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultItemStatus -> ResultItemStatus -> Bool
$c/= :: ResultItemStatus -> ResultItemStatus -> Bool
== :: ResultItemStatus -> ResultItemStatus -> Bool
$c== :: ResultItemStatus -> ResultItemStatus -> Bool
Eq, Int -> ResultItemStatus -> ShowS
[ResultItemStatus] -> ShowS
ResultItemStatus -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResultItemStatus] -> ShowS
$cshowList :: [ResultItemStatus] -> ShowS
show :: ResultItemStatus -> String
$cshow :: ResultItemStatus -> String
showsPrec :: Int -> ResultItemStatus -> ShowS
$cshowsPrec :: Int -> ResultItemStatus -> ShowS
Show)
toSpecResult :: [(Path, Format.Item)] -> SpecResult
toSpecResult :: [(Path, Item)] -> SpecResult
toSpecResult [(Path, Item)]
results = [ResultItem] -> Bool -> SpecResult
SpecResult [ResultItem]
items Bool
success
where
items :: [ResultItem]
items = forall a b. (a -> b) -> [a] -> [b]
map (Path, Item) -> ResultItem
toResultItem [(Path, Item)]
results
success :: Bool
success = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. ResultItem -> Bool
resultItemIsFailure) [ResultItem]
items
toResultItem :: (Path, Format.Item) -> ResultItem
toResultItem :: (Path, Item) -> ResultItem
toResultItem (Path
path, Item
item) = Path -> ResultItemStatus -> ResultItem
ResultItem Path
path ResultItemStatus
status
where
status :: ResultItemStatus
status = case Item -> Result
Format.itemResult Item
item of
Format.Success{} -> ResultItemStatus
ResultItemSuccess
Format.Pending{} -> ResultItemStatus
ResultItemPending
Format.Failure{} -> ResultItemStatus
ResultItemFailure
data Summary = Summary {
Summary -> Int
summaryExamples :: !Int
, Summary -> Int
summaryFailures :: !Int
} deriving (Summary -> Summary -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Summary -> Summary -> Bool
$c/= :: Summary -> Summary -> Bool
== :: Summary -> Summary -> Bool
$c== :: Summary -> Summary -> Bool
Eq, Int -> Summary -> ShowS
[Summary] -> ShowS
Summary -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Summary] -> ShowS
$cshowList :: [Summary] -> ShowS
show :: Summary -> String
$cshow :: Summary -> String
showsPrec :: Int -> Summary -> ShowS
$cshowsPrec :: Int -> Summary -> ShowS
Show)
instance Monoid Summary where
mempty :: Summary
mempty = Int -> Int -> Summary
Summary Int
0 Int
0
#if MIN_VERSION_base(4,11,0)
instance Semigroup Summary where
#endif
(Summary Int
x1 Int
x2)
#if MIN_VERSION_base(4,11,0)
<> :: Summary -> Summary -> Summary
<>
#else
`mappend`
#endif
(Summary Int
y1 Int
y2) = Int -> Int -> Summary
Summary (Int
x1 forall a. Num a => a -> a -> a
+ Int
y1) (Int
x2 forall a. Num a => a -> a -> a
+ Int
y2)
toSummary :: SpecResult -> Summary
toSummary :: SpecResult -> Summary
toSummary SpecResult
result = Summary {
summaryExamples :: Int
summaryExamples = forall (t :: * -> *) a. Foldable t => t a -> Int
length [ResultItem]
items
, summaryFailures :: Int
summaryFailures = forall (t :: * -> *) a. Foldable t => t a -> Int
length [ResultItem]
failures
} where
items :: [ResultItem]
items = SpecResult -> [ResultItem]
specResultItems SpecResult
result
failures :: [ResultItem]
failures = forall a. (a -> Bool) -> [a] -> [a]
filter ResultItem -> Bool
resultItemIsFailure [ResultItem]
items
isSuccess :: Summary -> Bool
isSuccess :: Summary -> Bool
isSuccess Summary
summary = Summary -> Int
summaryFailures Summary
summary forall a. Eq a => a -> a -> Bool
== Int
0