ghc-mod/test/TestUtils.hs

45 lines
1.1 KiB
Haskell
Raw Normal View History

2014-05-10 13:10:34 +00:00
module TestUtils (
run
, runD
, runI
, runID
, runIsolatedGhcMod
, isolateCradle
, module Language.Haskell.GhcMod.Monad
, module Language.Haskell.GhcMod.Types
) where
import Language.Haskell.GhcMod.Monad
import Language.Haskell.GhcMod.Types
isolateCradle :: IOish m => GhcModT m a -> GhcModT m a
2014-05-10 13:10:34 +00:00
isolateCradle action =
local modifyEnv $ action
where
modifyEnv e = e { gmCradle = (gmCradle e) { cradlePkgDbStack = [GlobalDb] } }
2014-07-22 17:45:48 +00:00
extract :: IO (Either e a, w) -> IO a
extract action = do
(Right a, _) <- action
return a
runIsolatedGhcMod :: Options -> GhcModT IO a -> IO a
2014-07-22 17:45:48 +00:00
runIsolatedGhcMod opt action = do
extract $ runGhcModT opt $ isolateCradle action
2014-05-10 13:10:34 +00:00
-- | Run GhcMod in isolated cradle with default options
2014-08-12 07:41:21 +00:00
runID :: GhcModT IO a -> IO a
2014-05-10 13:10:34 +00:00
runID = runIsolatedGhcMod defaultOptions
-- | Run GhcMod in isolated cradle
2014-08-12 07:41:21 +00:00
runI :: Options -> GhcModT IO a -> IO a
2014-05-10 13:10:34 +00:00
runI = runIsolatedGhcMod
-- | Run GhcMod
run :: Options -> GhcModT IO a -> IO a
2014-07-22 17:45:48 +00:00
run opt a = extract $ runGhcModT opt a
2014-05-10 13:10:34 +00:00
-- | Run GhcMod with default options
runD :: GhcModT IO a -> IO a
2014-07-22 17:45:48 +00:00
runD = extract . runGhcModT defaultOptions