2014-05-10 13:10:34 +00:00
|
|
|
module TestUtils (
|
|
|
|
run
|
|
|
|
, runD
|
2014-08-12 16:11:32 +00:00
|
|
|
, runD'
|
2014-05-10 13:10:34 +00:00
|
|
|
, runI
|
|
|
|
, runID
|
|
|
|
, runIsolatedGhcMod
|
|
|
|
, isolateCradle
|
2014-08-12 16:11:32 +00:00
|
|
|
, shouldReturnError
|
2014-05-10 13:10:34 +00:00
|
|
|
, module Language.Haskell.GhcMod.Monad
|
|
|
|
, module Language.Haskell.GhcMod.Types
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Language.Haskell.GhcMod.Monad
|
|
|
|
import Language.Haskell.GhcMod.Types
|
|
|
|
|
2014-08-12 16:11:32 +00:00
|
|
|
import Test.Hspec
|
|
|
|
|
2014-07-12 09:16:16 +00:00
|
|
|
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-08-21 05:16:56 +00:00
|
|
|
extract :: Show e => IO (Either e a, w) -> IO a
|
2014-07-22 17:45:48 +00:00
|
|
|
extract action = do
|
2014-08-21 05:16:56 +00:00
|
|
|
(r,_) <- action
|
|
|
|
case r of
|
|
|
|
Right a -> return a
|
|
|
|
Left e -> error $ show e
|
2014-07-22 17:45:48 +00:00
|
|
|
|
2014-07-12 09:16:16 +00:00
|
|
|
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
|
2014-07-12 09:16:16 +00:00
|
|
|
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
|
2014-07-12 09:16:16 +00:00
|
|
|
runD :: GhcModT IO a -> IO a
|
2014-07-22 17:45:48 +00:00
|
|
|
runD = extract . runGhcModT defaultOptions
|
2014-08-12 16:11:32 +00:00
|
|
|
|
|
|
|
runD' :: GhcModT IO a -> IO (Either GhcModError a, GhcModLog)
|
|
|
|
runD' = runGhcModT defaultOptions
|
|
|
|
|
|
|
|
shouldReturnError :: Show a
|
|
|
|
=> IO (Either GhcModError a, GhcModLog)
|
|
|
|
-> Expectation
|
|
|
|
shouldReturnError action = do
|
|
|
|
(a,_) <- action
|
|
|
|
a `shouldSatisfy` isLeft
|
|
|
|
where
|
|
|
|
isLeft (Left _) = True
|
|
|
|
isLeft _ = False
|