Skip to content

Commit fc98d47

Browse files
authored
Merge pull request #168 from erikd/topic/test-runner
Add a runTests function
2 parents e6387b2 + e5631be commit fc98d47

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

hedgehog/src/Hedgehog.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ module Hedgehog (
139139

140140
, Show1
141141
, showsPrec1
142+
143+
-- * Test runner
144+
, runTests
142145
) where
143146

144147
import Data.Functor.Classes (Eq1, eq1, Ord1, compare1, Show1, showsPrec1)
@@ -164,6 +167,8 @@ import Hedgehog.Internal.Property (Test, TestT, property, test)
164167
import Hedgehog.Internal.Property (TestLimit, withTests)
165168
import Hedgehog.Internal.Range (Range, Size(..))
166169
import Hedgehog.Internal.Runner (check, recheck, checkSequential, checkParallel)
170+
import Hedgehog.Internal.Runner (runTests)
171+
167172
import Hedgehog.Internal.Seed (Seed(..))
168173
import Hedgehog.Internal.State (Command(..), Callback(..))
169174
import Hedgehog.Internal.State (Action, Sequential(..), Parallel(..))

hedgehog/src/Hedgehog/Internal/Runner.hs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ module Hedgehog.Internal.Runner (
1717
, checkSequential
1818
, checkGroup
1919

20+
-- * Top level testsuite runner
21+
, runTests
22+
2023
-- * Internal
2124
, checkReport
2225
, checkRegion
@@ -25,6 +28,7 @@ module Hedgehog.Internal.Runner (
2528

2629
import Control.Concurrent.STM (TVar, atomically)
2730
import qualified Control.Concurrent.STM.TVar as TVar
31+
import Control.Monad (unless)
2832
import Control.Monad.Catch (MonadCatch(..), catchAll)
2933
import Control.Monad.IO.Class (MonadIO(..))
3034

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

4751
import Language.Haskell.TH.Lift (deriveLift)
4852

53+
import System.Exit (exitFailure)
4954
#if mingw32_HOST_OS
50-
import System.IO (hSetEncoding, stdout, stderr, utf8)
55+
import System.IO (BufferMode (LineBuffering), hSetBuffering, hSetEncoding, stdout, stderr, utf8)
56+
#else
57+
import System.IO (BufferMode (LineBuffering), hSetBuffering, stderr, stdout)
5158
#endif
5259

5360
-- | Configuration for a property test run.
@@ -402,6 +409,16 @@ checkParallel =
402409
Nothing
403410
}
404411

412+
-- | Like `runTests` but exit with `exitFailure` if one or more of the tests
413+
-- fail.
414+
runTests :: [IO Bool] -> IO ()
415+
runTests tests = do
416+
hSetBuffering stdout LineBuffering
417+
hSetBuffering stderr LineBuffering
418+
result <- and <$> sequence tests
419+
unless result
420+
exitFailure
421+
405422
------------------------------------------------------------------------
406423
-- FIXME Replace with DeriveLift when we drop 7.10 support.
407424

hedgehog/test/test.hs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
import Control.Monad (unless)
2-
import System.IO (BufferMode(..), hSetBuffering, stdout, stderr)
3-
import System.Exit (exitFailure)
1+
import Hedgehog (runTests)
42

53
import qualified Test.Hedgehog.Seed
64
import qualified Test.Hedgehog.Text
75

86

97
main :: IO ()
10-
main = do
11-
hSetBuffering stdout LineBuffering
12-
hSetBuffering stderr LineBuffering
13-
14-
results <- sequence [
8+
main =
9+
runTests [
1510
Test.Hedgehog.Text.tests
1611
, Test.Hedgehog.Seed.tests
1712
]
18-
19-
unless (and results) $
20-
exitFailure

0 commit comments

Comments
 (0)