Skip to content

Commit 5578e2e

Browse files
committed
Use Tasty as the test runner in the OSS build
This gives us * Parallel test runs * Test listing via `--list-tests` * Test selection via `-p <pattern>`
1 parent 2894b27 commit 5578e2e

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

glean.cabal.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ library stubs
225225
glean:if-glean-hs,
226226
glean:if-index-hs,
227227
mangle,
228-
template-haskell
228+
template-haskell,
229+
tasty,
230+
tasty-hunit-adapter
229231

230232
library logger
231233
import: fb-haskell, fb-cpp, deps
@@ -2228,6 +2230,9 @@ test-suite glean-snapshot-hack
22282230
if !flag(hack-tests)
22292231
buildable: False
22302232

2233+
-- The Haskell indexer tests *only* work when run using Cabal with
2234+
-- `cabal run` or `cabal test`, because Cabal puts the `hie-indexer`
2235+
-- binary in the PATH.
22312236
test-suite glean-snapshot-haskell
22322237
import: fb-haskell, fb-cpp, deps, exe, haskell-indexer
22332238
hs-source-dirs: glean/lang/haskell/tests

glean/github/TestRunner.hs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,36 @@
88

99
module TestRunner (module TestRunner) where
1010

11-
import Control.Monad
12-
import System.Exit
11+
import System.Environment (withArgs)
1312
import Test.HUnit
13+
import qualified Test.Tasty as Tasty
14+
import qualified Test.Tasty.HUnit.Adapter as Tasty
1415

16+
-- | Wraps the HUnit test using tasty, so we get parallel test runs,
17+
-- test listing, and test selection.
1518
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
1923

2024
data TestAction = TestAction
2125

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+
--
2238
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

Comments
 (0)