Skip to content

Commit

Permalink
testsuite: Port to tasty and tasty-hunit
Browse files Browse the repository at this point in the history
  • Loading branch information
bgamari committed Jan 24, 2025
1 parent 2d6e7a3 commit 4fbf0b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
5 changes: 2 additions & 3 deletions hsc2hs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ test-suite spec
ghc-options: -Wall -threaded
type: exitcode-stdio-1.0
build-depends: base >= 4.3.0 && < 4.22,
test-framework >= 0.8.2.0 && < 0.9,
test-framework-hunit >= 0.3.0.2 && < 0.4,
HUnit >= 1.3.1.2 && < 1.4 || >= 1.6.0.0 && < 1.7
tasty >= 1.5 && < 1.6,
tasty-hunit >= 0.10 && < 0.11

default-language: Haskell2010
13 changes: 6 additions & 7 deletions test/BDD.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
module BDD where

import Control.Monad (ap)
import Test.Framework (defaultMain, TestName, Test, testGroup)
import Test.Framework.Providers.HUnit (testCase)
import Test.HUnit (Assertion, (@?=))
import Test.Tasty
import Test.Tasty.HUnit

#if !MIN_VERSION_base(4,8,0)
import Control.Applicative (Applicative (..))
Expand All @@ -24,13 +23,13 @@ import GHC.Stack (HasCallStack)
-------------------------------------------------------------------------------

specMain :: TestM () -> IO ()
specMain t = runTestM t >>= defaultMain
specMain t = runTestM t >>= defaultMain . testGroup "specs"

newtype TestM a = TestM { unTestM :: [Test] -> IO ([Test], a) }
newtype TestM a = TestM { unTestM :: [TestTree] -> IO ([TestTree], a) }
deriving (Functor)

-- accumulating in reverse order.
tell1 :: Test -> TestM ()
tell1 :: TestTree -> TestM ()
tell1 t = TestM $ \ts -> return (t : ts, ())

instance Applicative TestM where
Expand All @@ -44,7 +43,7 @@ instance Monad TestM where
(ys, x) <- unTestM m xs
unTestM (k x) ys

runTestM :: TestM () -> IO [Test]
runTestM :: TestM () -> IO [TestTree]
runTestM (TestM m) = fmap (reverse . fst) (m [])

runIO :: IO a -> TestM a
Expand Down

0 comments on commit 4fbf0b9

Please sign in to comment.