Skip to content

Commit cf528b5

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 d77ae65 commit cf528b5

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ jobs:
172172
run: make glean-hie
173173

174174
- name: Run tests
175-
run: make test
175+
run: TASTY_NUM_THREADS=32 make test
176176

177177
# check the vscode extension builds
178178
vscode:

glean.cabal.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ library stubs
230230
glean:if-glean-hs,
231231
glean:if-index-hs,
232232
mangle,
233-
template-haskell
233+
template-haskell,
234+
tasty,
235+
tasty-hunit-adapter
234236

235237
library logger
236238
import: fb-haskell, fb-cpp, deps
@@ -2236,6 +2238,9 @@ test-suite glean-snapshot-hack
22362238
if !flag(hack-tests)
22372239
buildable: False
22382240

2241+
-- The Haskell indexer tests *only* work when run using Cabal with
2242+
-- `cabal run` or `cabal test`, because Cabal puts the `hie-indexer`
2243+
-- binary in the PATH.
22392244
test-suite glean-snapshot-haskell
22402245
import: fb-haskell, fb-cpp, deps, exe, haskell-indexer
22412246
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)