module Test.Hspec.Core.Runner.Result (
-- RE-EXPORTED from Test.Hspec.Core.Runner
  SpecResult(SpecResult)
, specResultItems
, specResultSuccess

, ResultItem(ResultItem)
, resultItemPath
, resultItemStatus
, resultItemIsFailure

, ResultItemStatus(..)
-- END RE-EXPORTED from Test.Hspec.Core.Runner

, toSpecResult
) where

import           Prelude ()
import           Test.Hspec.Core.Compat

import           Test.Hspec.Core.Util
import qualified Test.Hspec.Core.Format as Format

-- |
-- @since 2.10.0
data SpecResult = SpecResult {
  -- |
  -- @since 2.10.0
  SpecResult -> [ResultItem]
specResultItems :: [ResultItem]

  -- |
  -- @since 2.10.0
, 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)

-- |
-- @since 2.10.0
data ResultItem = ResultItem {
  -- |
  -- @since 2.10.0
  ResultItem -> Path
resultItemPath :: Path

  -- |
  -- @since 2.10.0
, 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)

-- |
-- @since 2.10.0
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 :: Bool -> [(Path, Format.Item)] -> SpecResult
toSpecResult :: Bool -> [(Path, Item)] -> SpecResult
toSpecResult Bool
failOnEmpty [(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 = Bool -> Bool
not (Bool
failOnEmpty Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Path, Item)]
results) Bool -> Bool -> Bool
&& 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