Fix tests

This commit is contained in:
Daniel Gröber
2015-09-14 05:59:01 +02:00
parent a7e2f3d2a6
commit ba14e1790c
4 changed files with 17 additions and 14 deletions

View File

@@ -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

View File

@@ -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)