hspec2-0.4.0: src/Test/Hspec/Runner/Tree.hs
{-# LANGUAGE DeriveFunctor #-}
module Test.Hspec.Runner.Tree where
import Control.Applicative
import Test.Hspec.Core.Type
data Tree a
= Node !String [Tree a]
| Leaf !String a
deriving (Eq, Show, Functor)
toTree :: SpecWith a -> IO [Tree (Item a)]
toTree spec = concat <$> (runSpecM spec >>= mapM go)
where
go x = case x of
SpecGroup label xs -> return . Node label . concat <$> mapM go xs
BuildSpecs xs -> concat <$> (xs >>= mapM go)
SpecItem r item -> return [Leaf r item]