module Test.Hspec.HUnit (
fromHUnitTest
) where
import Data.List (intercalate)
import qualified Test.HUnit as HU
import Test.HUnit (Test (..))
import Test.Hspec.Core.Type
instance Example Test where
evaluateExample test _ _ = do
(counts, fails) <- HU.runTestText HU.putTextToShowS test
let r = if HU.errors counts + HU.failures counts == 0
then Success
else Fail (details $ fails "")
return r
where
details :: String -> String
details = intercalate "\n" . tail . init . lines
fromHUnitTest :: Test -> Spec
fromHUnitTest t = fromSpecList $ case t of
TestList xs -> map go xs
x -> [go x]
where
go :: Test -> SpecTree
go t_ = case t_ of
TestLabel s (TestCase e) -> it s e
TestLabel s (TestList xs) -> describe s (map go xs)
TestLabel s x -> describe s [go x]
TestList xs -> describe "<unlabeled>" (map go xs)
TestCase e -> it "<unlabeled>" e