Skip to content

Commit

Permalink
hspec-contrib: Add specListFromHUnitTest to Test.Hspec.Contrib.HUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Nov 19, 2014
1 parent 03ed22b commit b8f60fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion hspec-contrib/hspec-contrib.cabal
@@ -1,5 +1,5 @@
name: hspec-contrib
version: 0.1.0
version: 0.2.0
license: MIT
license-file: LICENSE
copyright: (c) 2011-2014 Simon Hengel,
Expand Down
25 changes: 16 additions & 9 deletions hspec-contrib/src/Test/Hspec/Contrib/HUnit.hs
Expand Up @@ -3,6 +3,7 @@
module Test.Hspec.Contrib.HUnit (
-- * Interoperability with HUnit
fromHUnitTest
, specListFromHUnitTest
) where

import Test.Hspec.Core.Spec
Expand All @@ -12,14 +13,20 @@ import Test.HUnit (Test (..))
-- Convert a HUnit test suite to a spec. This can be used to run existing
-- HUnit tests with Hspec.
fromHUnitTest :: Test -> Spec
fromHUnitTest t = case t of
TestList xs -> mapM_ go xs
x -> go x
fromHUnitTest = fromSpecList . specListFromHUnitTest

-- |
-- @specListFromHUnitTest@ is similar to `fromHUnitTest`, but it constructs a
-- list of `SpecTree`s instead of a `Spec`.
specListFromHUnitTest :: Test -> [SpecTree ()]
specListFromHUnitTest t = case t of
TestList xs -> map go xs
x -> [go x]
where
go :: Test -> Spec
go :: Test -> SpecTree ()
go t_ = case t_ of
TestLabel s (TestCase e) -> it s e
TestLabel s (TestList xs) -> describe s (mapM_ go xs)
TestLabel s x -> describe s (go x)
TestList xs -> describe "<unlabeled>" (mapM_ go xs)
TestCase e -> it "<unlabeled>" e
TestLabel s (TestCase e) -> specItem s e
TestLabel s (TestList xs) -> specGroup s (map go xs)
TestLabel s x -> specGroup s [go x]
TestList xs -> specGroup "<unlabeled>" (map go xs)
TestCase e -> specItem "<unlabeled>" e

0 comments on commit b8f60fd

Please sign in to comment.