Skip to content

Commit

Permalink
Merge pull request #168 from erikd/topic/test-runner
Browse files Browse the repository at this point in the history
Add a runTests function
  • Loading branch information
jacobstanley authored Mar 19, 2019
2 parents e6387b2 + e5631be commit fc98d47
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions hedgehog/src/Hedgehog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ module Hedgehog (

, Show1
, showsPrec1

-- * Test runner
, runTests
) where

import Data.Functor.Classes (Eq1, eq1, Ord1, compare1, Show1, showsPrec1)
Expand All @@ -164,6 +167,8 @@ import Hedgehog.Internal.Property (Test, TestT, property, test)
import Hedgehog.Internal.Property (TestLimit, withTests)
import Hedgehog.Internal.Range (Range, Size(..))
import Hedgehog.Internal.Runner (check, recheck, checkSequential, checkParallel)
import Hedgehog.Internal.Runner (runTests)

import Hedgehog.Internal.Seed (Seed(..))
import Hedgehog.Internal.State (Command(..), Callback(..))
import Hedgehog.Internal.State (Action, Sequential(..), Parallel(..))
Expand Down
19 changes: 18 additions & 1 deletion hedgehog/src/Hedgehog/Internal/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module Hedgehog.Internal.Runner (
, checkSequential
, checkGroup

-- * Top level testsuite runner
, runTests

-- * Internal
, checkReport
, checkRegion
Expand All @@ -25,6 +28,7 @@ module Hedgehog.Internal.Runner (

import Control.Concurrent.STM (TVar, atomically)
import qualified Control.Concurrent.STM.TVar as TVar
import Control.Monad (unless)
import Control.Monad.Catch (MonadCatch(..), catchAll)
import Control.Monad.IO.Class (MonadIO(..))

Expand All @@ -46,8 +50,11 @@ import Hedgehog.Range (Size)

import Language.Haskell.TH.Lift (deriveLift)

import System.Exit (exitFailure)
#if mingw32_HOST_OS
import System.IO (hSetEncoding, stdout, stderr, utf8)
import System.IO (BufferMode (LineBuffering), hSetBuffering, hSetEncoding, stdout, stderr, utf8)
#else
import System.IO (BufferMode (LineBuffering), hSetBuffering, stderr, stdout)
#endif

-- | Configuration for a property test run.
Expand Down Expand Up @@ -402,6 +409,16 @@ checkParallel =
Nothing
}

-- | Like `runTests` but exit with `exitFailure` if one or more of the tests
-- fail.
runTests :: [IO Bool] -> IO ()
runTests tests = do
hSetBuffering stdout LineBuffering
hSetBuffering stderr LineBuffering
result <- and <$> sequence tests
unless result
exitFailure

------------------------------------------------------------------------
-- FIXME Replace with DeriveLift when we drop 7.10 support.

Expand Down
14 changes: 3 additions & 11 deletions hedgehog/test/test.hs
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import Control.Monad (unless)
import System.IO (BufferMode(..), hSetBuffering, stdout, stderr)
import System.Exit (exitFailure)
import Hedgehog (runTests)

import qualified Test.Hedgehog.Seed
import qualified Test.Hedgehog.Text


main :: IO ()
main = do
hSetBuffering stdout LineBuffering
hSetBuffering stderr LineBuffering

results <- sequence [
main =
runTests [
Test.Hedgehog.Text.tests
, Test.Hedgehog.Seed.tests
]

unless (and results) $
exitFailure

0 comments on commit fc98d47

Please sign in to comment.