Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion glean.cabal.in
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ library stubs
glean:if-glean-hs,
glean:if-index-hs,
mangle,
template-haskell
template-haskell,
tasty,
tasty-hunit-adapter

library logger
import: fb-haskell, fb-cpp, deps
Expand Down Expand Up @@ -2228,6 +2230,9 @@ test-suite glean-snapshot-hack
if !flag(hack-tests)
buildable: False

-- The Haskell indexer tests *only* work when run using Cabal with
-- `cabal run` or `cabal test`, because Cabal puts the `hie-indexer`
-- binary in the PATH.
test-suite glean-snapshot-haskell
import: fb-haskell, fb-cpp, deps, exe, haskell-indexer
hs-source-dirs: glean/lang/haskell/tests
Expand Down
32 changes: 26 additions & 6 deletions glean/github/TestRunner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,36 @@

module TestRunner (module TestRunner) where

import Control.Monad
import System.Exit
import System.Environment (withArgs)
import Test.HUnit
import qualified Test.Tasty as Tasty
import qualified Test.Tasty.HUnit.Adapter as Tasty

-- | Wraps the HUnit test using tasty, so we get parallel test runs,
-- test listing, and test selection.
testRunner :: Test -> IO ()
testRunner t = do
Counts{..} <- runTestTT t
when (errors + failures > 0) $ exitWith (ExitFailure 1)
testRunner t =
Tasty.defaultMain $
Tasty.testGroup "test" $
Tasty.hUnitTestToTestTree t

data TestAction = TestAction

-- | This entry point is designed for combining the test runner's
-- option parser with the program's own options. Ideally we would use
-- this to combine Tasty's option parser with the program's parser,
-- but Tasty's option parser depends on the `Test`, and we don't have
-- that when parsing options (it might depend on the options), so
-- there's a circular dependency.
--
-- Therefore we run Tasty's CLI parser with empty arguments. We can
-- still use the environment variables to set Tasty options, e.g.
--
-- > TASTY_NUM_THREADS=12 cabal run my-test
--
testRunnerAction :: TestAction -> Test -> IO ()
testRunnerAction _ = testRunner
testRunnerAction _ t =
withArgs [] $
Tasty.defaultMain $
Tasty.testGroup "test" $
Tasty.hUnitTestToTestTree t
17 changes: 1 addition & 16 deletions glean/lang/clang/Glean/Indexer/Cpp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import Glean.LocalOrRemote ( BackendKind(..),
import Glean.Util.Service
import qualified Glean.Interprocess.Worklist as Worklist
import qualified Glean.Handler as GleanHandler
import System.Posix (changeWorkingDirectory)
import Data.Aeson (decode, Object, Value (String))
import Data.Foldable (toList)

Expand Down Expand Up @@ -225,13 +224,10 @@ indexerWith deriveToo = Indexer {
, "--worker_index", show i
, "--worker_count", show workers
]
currentDir <- getCurrentDirectory
let cdUp = not $ isPathPrefixOf currentDir buildDir
forConcurrently_ [0 .. workers-1] $ \i -> bracket
-- createProcess_ because we don't want the stdout/stderr handles
-- to be closed
( (if cdUp then pushd ".." else id) $
createProcess_
(createProcess_
"Cpp.index"
(proc clangIndex $ workerargs i)
{std_out = stream, std_err = stream})
Expand All @@ -246,17 +242,6 @@ indexerWith deriveToo = Indexer {
-- return data file names
return $ map dataFile [0 .. workers-1]

isPathPrefixOf :: FilePath -> FilePath -> Bool
isPathPrefixOf prefix path = prefix == take (length prefix) path

pushd :: FilePath -> IO a -> IO a
pushd dir f = do
currentDir <- getCurrentDirectory
changeWorkingDirectory dir
res <- f
changeWorkingDirectory currentDir
pure res

writeToDB backend repo = mapM_ $ \dataFile -> do
dat <- BS.readFile dataFile
case deserializeGen (Proxy :: Proxy Compact) dat of
Expand Down
Loading