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) where run a = fillTempDir =<< (fromJust <$> runMaybeT a)
findSpecCradle :: FilePath -> IO Cradle findSpecCradle :: (IOish m, GmOut m) => FilePath -> m Cradle
findSpecCradle dir = do findSpecCradle dir = do
let cfs = [cabalCradle, sandboxCradle] let cfs = [stackCradle, cabalCradle, sandboxCradle]
cs <- catMaybes <$> mapM (runMaybeT . ($ dir)) cfs cs <- catMaybes <$> mapM (runMaybeT . ($ dir)) cfs
gcs <- filterM isNotGmCradle cs gcs <- filterM isNotGmCradle cs
fillTempDir =<< case gcs of fillTempDir =<< case gcs of
[] -> fromJust <$> runMaybeT (plainCradle dir) [] -> fromJust <$> runMaybeT (plainCradle dir)
c:_ -> return c c:_ -> return c
where where
isNotGmCradle :: Cradle -> IO Bool isNotGmCradle crdl =
isNotGmCradle crdl = do liftIO $ not <$> doesFileExist (cradleRootDir crdl </> "ghc-mod.cabal")
not <$> doesFileExist (cradleRootDir crdl </> "ghc-mod.cabal")
cleanupCradle :: Cradle -> IO () cleanupCradle :: Cradle -> IO ()
cleanupCradle crdl = removeDirectoryRecursive $ cradleTempDir crdl cleanupCradle crdl = removeDirectoryRecursive $ cradleTempDir crdl

View File

@ -26,6 +26,7 @@ module Language.Haskell.GhcMod.Monad (
, runGmlTWith , runGmlTWith
, runGmPkgGhc , runGmPkgGhc
, withGhcModEnv , withGhcModEnv
, withGhcModEnv'
, module Language.Haskell.GhcMod.Monad.Types , module Language.Haskell.GhcMod.Monad.Types
) where ) where
@ -52,9 +53,15 @@ import System.Directory
import Prelude import Prelude
withGhcModEnv :: (IOish m, GmOut m) => FilePath -> Options -> (GhcModEnv -> m a) -> m a 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 $ withStdoutGateway $
withCradle $ \crdl -> withCradle dir $ \crdl ->
withCradleRootDir crdl $ withCradleRootDir crdl $
f $ GhcModEnv opts crdl f $ GhcModEnv opts crdl
where where
@ -62,9 +69,6 @@ withGhcModEnv dir opts f =
c <- gmoChan <$> gmoAsk c <- gmoChan <$> gmoAsk
gbracket_ (liftIO $ forkIO $ stdoutGateway c) (liftIO . killThread) a gbracket_ (liftIO $ forkIO $ stdoutGateway c) (liftIO . killThread) a
withCradle =
gbracket (findCradle' dir) (liftIO . cleanupCradle)
withCradleRootDir (cradleRootDir -> projdir) = withCradleRootDir (cradleRootDir -> projdir) =
gbracket_ (liftIO $ setCurrentDirectory projdir >> getCurrentDirectory) gbracket_ (liftIO $ setCurrentDirectory projdir >> getCurrentDirectory)
(liftIO . setCurrentDirectory) (liftIO . setCurrentDirectory)

View File

@ -44,12 +44,12 @@ extract action = do
Right a -> return a Right a -> return a
Left e -> error $ show e Left e -> error $ show e
withSpecCradle :: IOish m => FilePath -> (Cradle -> m a) -> m a withSpecCradle :: (IOish m, GmOut m) => FilePath -> (Cradle -> m a) -> m a
withSpecCradle cradledir f = withSpecCradle cradledir f =
gbracket (liftIO $ findSpecCradle cradledir) (liftIO . cleanupCradle) f gbracket (findSpecCradle cradledir) (liftIO . cleanupCradle) f
withGhcModEnvSpec :: (IOish m, GmOut m) => FilePath -> Options -> (GhcModEnv -> m a) -> m a withGhcModEnvSpec :: (IOish m, GmOut m) => FilePath -> Options -> (GhcModEnv -> m a) -> m a
withGhcModEnvSpec dir opt f = withSpecCradle dir $ withGhcModEnv' opt f withGhcModEnvSpec = withGhcModEnv' withSpecCradle
runGhcModTSpec :: Options -> GhcModT IO a -> IO (Either GhcModError a, GhcModLog) runGhcModTSpec :: Options -> GhcModT IO a -> IO (Either GhcModError a, GhcModLog)
runGhcModTSpec opt action = do runGhcModTSpec opt action = do

View File

@ -9,7 +9,7 @@ main = doctest
, "-package", "transformers-" ++ VERSION_transformers , "-package", "transformers-" ++ VERSION_transformers
, "-package", "mtl-" ++ VERSION_mtl , "-package", "mtl-" ++ VERSION_mtl
, "-package", "directory-" ++ VERSION_directory , "-package", "directory-" ++ VERSION_directory
, "-XScopedTypeVariables", "-XRecordWildCards", "-XNamedFieldPuns", "-XConstraintKinds", "-XFlexibleContexts", "-XDataKinds", "-XKindSignatures", "-XTypeOperators" , "-XScopedTypeVariables", "-XRecordWildCards", "-XNamedFieldPuns", "-XConstraintKinds", "-XFlexibleContexts", "-XDataKinds", "-XKindSignatures", "-XTypeOperators", "-XViewPatterns"
, "-idist/build/autogen/" , "-idist/build/autogen/"
, "-optP-include" , "-optP-include"
, "-optPdist/build/autogen/cabal_macros.h" , "-optPdist/build/autogen/cabal_macros.h"