module Test.Hspec.Core.Tree (
SpecTree
, Tree (..)
, Item (..)
, specGroup
, specItem
) where
import Data.CallStack
import Control.Exception
import Prelude ()
import Test.Hspec.Core.Compat
import Test.Hspec.Core.Example
data Tree c a =
Node String [Tree c a]
| NodeWithCleanup c [Tree c a]
| Leaf a
deriving (Functor, Foldable, Traversable)
type SpecTree a = Tree (ActionWith a) (Item a)
data Item a = Item {
itemRequirement :: String
, itemLocation :: Maybe Location
, itemIsParallelizable :: Bool
, itemExample :: Params -> (ActionWith a -> IO ()) -> ProgressCallback -> IO (Either SomeException Result)
}
specGroup :: String -> [SpecTree a] -> SpecTree a
specGroup s = Node msg
where
msg
| null s = "(no description given)"
| otherwise = s
specItem :: (HasCallStack, Example a) => String -> a -> SpecTree (Arg a)
specItem s e = Leaf $ Item requirement location False (safeEvaluateExample e)
where
requirement
| null s = "(unspecified behavior)"
| otherwise = s
location :: Maybe Location
location = case reverse callStack of
(_, loc) : _ -> Just (Location (srcLocFile loc) (srcLocStartLine loc) (srcLocStartCol loc) ExactLocation)
_ -> Nothing