Fix tests
This commit is contained in:
@@ -41,18 +41,17 @@ findCradle' dir = run $
|
||||
]
|
||||
where run a = fillTempDir =<< (fromJust <$> runMaybeT a)
|
||||
|
||||
findSpecCradle :: FilePath -> IO Cradle
|
||||
findSpecCradle :: (IOish m, GmOut m) => FilePath -> m Cradle
|
||||
findSpecCradle dir = do
|
||||
let cfs = [cabalCradle, sandboxCradle]
|
||||
let cfs = [stackCradle, cabalCradle, sandboxCradle]
|
||||
cs <- catMaybes <$> mapM (runMaybeT . ($ dir)) cfs
|
||||
gcs <- filterM isNotGmCradle cs
|
||||
fillTempDir =<< case gcs of
|
||||
[] -> fromJust <$> runMaybeT (plainCradle dir)
|
||||
c:_ -> return c
|
||||
where
|
||||
isNotGmCradle :: Cradle -> IO Bool
|
||||
isNotGmCradle crdl = do
|
||||
not <$> doesFileExist (cradleRootDir crdl </> "ghc-mod.cabal")
|
||||
isNotGmCradle crdl =
|
||||
liftIO $ not <$> doesFileExist (cradleRootDir crdl </> "ghc-mod.cabal")
|
||||
|
||||
cleanupCradle :: Cradle -> IO ()
|
||||
cleanupCradle crdl = removeDirectoryRecursive $ cradleTempDir crdl
|
||||
|
||||
@@ -26,6 +26,7 @@ module Language.Haskell.GhcMod.Monad (
|
||||
, runGmlTWith
|
||||
, runGmPkgGhc
|
||||
, withGhcModEnv
|
||||
, withGhcModEnv'
|
||||
, module Language.Haskell.GhcMod.Monad.Types
|
||||
) where
|
||||
|
||||
@@ -52,9 +53,15 @@ import System.Directory
|
||||
import Prelude
|
||||
|
||||
withGhcModEnv :: (IOish m, GmOut m) => FilePath -> Options -> (GhcModEnv -> m a) -> m a
|
||||
withGhcModEnv dir opts f =
|
||||
withGhcModEnv = withGhcModEnv' withCradle
|
||||
where
|
||||
withCradle dir =
|
||||
gbracket (findCradle' dir) (liftIO . cleanupCradle)
|
||||
|
||||
withGhcModEnv' :: (IOish m, GmOut m) => (FilePath -> (Cradle -> m a) -> m a) -> FilePath -> Options -> (GhcModEnv -> m a) -> m a
|
||||
withGhcModEnv' withCradle dir opts f =
|
||||
withStdoutGateway $
|
||||
withCradle $ \crdl ->
|
||||
withCradle dir $ \crdl ->
|
||||
withCradleRootDir crdl $
|
||||
f $ GhcModEnv opts crdl
|
||||
where
|
||||
@@ -62,9 +69,6 @@ withGhcModEnv dir opts f =
|
||||
c <- gmoChan <$> gmoAsk
|
||||
gbracket_ (liftIO $ forkIO $ stdoutGateway c) (liftIO . killThread) a
|
||||
|
||||
withCradle =
|
||||
gbracket (findCradle' dir) (liftIO . cleanupCradle)
|
||||
|
||||
withCradleRootDir (cradleRootDir -> projdir) =
|
||||
gbracket_ (liftIO $ setCurrentDirectory projdir >> getCurrentDirectory)
|
||||
(liftIO . setCurrentDirectory)
|
||||
|
||||
Reference in New Issue
Block a user