|
8 | 8 |
|
9 | 9 | module TestRunner (module TestRunner) where |
10 | 10 |
|
11 | | -import Control.Monad |
12 | | -import System.Exit |
| 11 | +import System.Environment (withArgs) |
13 | 12 | import Test.HUnit |
| 13 | +import qualified Test.Tasty as Tasty |
| 14 | +import qualified Test.Tasty.HUnit.Adapter as Tasty |
14 | 15 |
|
| 16 | +-- | Wraps the HUnit test using tasty, so we get parallel test runs, |
| 17 | +-- test listing, and test selection. |
15 | 18 | testRunner :: Test -> IO () |
16 | | -testRunner t = do |
17 | | - Counts{..} <- runTestTT t |
18 | | - when (errors + failures > 0) $ exitWith (ExitFailure 1) |
| 19 | +testRunner t = |
| 20 | + Tasty.defaultMain $ |
| 21 | + Tasty.testGroup "test" $ |
| 22 | + Tasty.hUnitTestToTestTree t |
19 | 23 |
|
20 | 24 | data TestAction = TestAction |
21 | 25 |
|
| 26 | +-- | This entry point is designed for combining the test runner's |
| 27 | +-- option parser with the program's own options. Ideally we would use |
| 28 | +-- this to combine Tasty's option parser with the program's parser, |
| 29 | +-- but Tasty's option parser depends on the `Test`, and we don't have |
| 30 | +-- that when parsing options (it might depend on the options), so |
| 31 | +-- there's a circular dependency. |
| 32 | +-- |
| 33 | +-- Therefore we run Tasty's CLI parser with empty arguments. We can |
| 34 | +-- still use the environment variables to set Tasty options, e.g. |
| 35 | +-- |
| 36 | +-- > TASTY_NUM_THREADS=12 cabal run my-test |
| 37 | +-- |
22 | 38 | testRunnerAction :: TestAction -> Test -> IO () |
23 | | -testRunnerAction _ = testRunner |
| 39 | +testRunnerAction _ t = |
| 40 | + withArgs [] $ |
| 41 | + Tasty.defaultMain $ |
| 42 | + Tasty.testGroup "test" $ |
| 43 | + Tasty.hUnitTestToTestTree t |
0 commit comments