Use existence of cabal/stack as cradle indicator
Also add some more "info" logging for which cradle was picked.
This commit is contained in:
@@ -37,14 +37,14 @@ spec = do
|
||||
it "returns the current directory" $ do
|
||||
withDirectory_ "/" $ do
|
||||
curDir <- stripLastDot <$> canonicalizePath "/"
|
||||
res <- clean_ $ runGmOutDef findCradleNoLog
|
||||
res <- clean_ $ runGmOutDef $ findCradleNoLog $ optPrograms defaultOptions
|
||||
cradleCurrentDir res `shouldBe` curDir
|
||||
cradleRootDir res `shouldBe` curDir
|
||||
cradleCabalFile res `shouldBe` Nothing
|
||||
|
||||
it "finds a cabal file and a sandbox" $ do
|
||||
withDirectory "test/data/cabal-project/subdir1/subdir2" $ \dir -> do
|
||||
res <- relativeCradle dir <$> clean_ (runGmOutDef findCradleNoLog)
|
||||
res <- relativeCradle dir <$> clean_ (runGmOutDef $ findCradleNoLog $ optPrograms defaultOptions)
|
||||
|
||||
cradleCurrentDir res `shouldBe`
|
||||
"test/data/cabal-project/subdir1/subdir2"
|
||||
@@ -56,7 +56,7 @@ spec = do
|
||||
|
||||
it "works even if a sandbox config file is broken" $ do
|
||||
withDirectory "test/data/broken-sandbox" $ \dir -> do
|
||||
res <- relativeCradle dir <$> clean_ (runGmOutDef findCradleNoLog)
|
||||
res <- relativeCradle dir <$> clean_ (runGmOutDef $ findCradleNoLog $ optPrograms defaultOptions)
|
||||
cradleCurrentDir res `shouldBe`
|
||||
"test" </> "data" </> "broken-sandbox"
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ spec = do
|
||||
describe "getSandboxDb" $ do
|
||||
it "can parse a config file and extract the sandbox package-db" $ do
|
||||
cwd <- getCurrentDirectory
|
||||
Just crdl <- runMaybeT $ plainCradle "test/data/cabal-project"
|
||||
Just crdl <- runLogDef $ runMaybeT $ plainCradle "test/data/cabal-project"
|
||||
Just db <- getSandboxDb crdl
|
||||
db `shouldSatisfy` isPkgDbAt (cwd </> "test/data/cabal-project/.cabal-sandbox")
|
||||
|
||||
it "returns Nothing if the sandbox config file is broken" $ do
|
||||
Just crdl <- runMaybeT $ plainCradle "test/data/broken-sandbox"
|
||||
Just crdl <- runLogDef $ runMaybeT $ plainCradle "test/data/broken-sandbox"
|
||||
getSandboxDb crdl `shouldReturn` Nothing
|
||||
|
||||
describe "findCabalFile" $ do
|
||||
|
||||
@@ -6,6 +6,7 @@ module TestUtils (
|
||||
, runE
|
||||
, runNullLog
|
||||
, runGmOutDef
|
||||
, runLogDef
|
||||
, shouldReturnError
|
||||
, isPkgDbAt
|
||||
, isPkgConfDAt
|
||||
@@ -43,10 +44,6 @@ extract action = do
|
||||
Right a -> return a
|
||||
Left e -> error $ show e
|
||||
|
||||
withSpecCradle :: (IOish m, GmOut m) => FilePath -> ((Cradle, GhcModLog) -> m a) -> m a
|
||||
withSpecCradle cradledir f = do
|
||||
gbracket (runJournalT $ findSpecCradle cradledir) (liftIO . cleanupCradle . fst) f
|
||||
|
||||
runGhcModTSpec :: Options -> GhcModT IO a -> IO (Either GhcModError a, GhcModLog)
|
||||
runGhcModTSpec opt action = do
|
||||
dir <- getCurrentDirectory
|
||||
@@ -59,6 +56,13 @@ runGhcModTSpec' dir opt action = liftIO (canonicalizePath dir) >>= \dir' -> do
|
||||
withGhcModEnv' withSpecCradle dir' opt $ \(env,_) -> do
|
||||
first (fst <$>) <$> runGhcModT' env defaultGhcModState
|
||||
(gmSetLogLevel (ooptLogLevel $ optOutput opt) >> action)
|
||||
where
|
||||
withSpecCradle :: (IOish m, GmOut m) => FilePath -> ((Cradle, GhcModLog) -> m a) -> m a
|
||||
withSpecCradle cradledir f =
|
||||
gbracket
|
||||
(runJournalT $ findSpecCradle (optPrograms opt) cradledir)
|
||||
(liftIO . cleanupCradle . fst) f
|
||||
|
||||
|
||||
-- | Run GhcMod
|
||||
run :: Options -> GhcModT IO a -> IO a
|
||||
@@ -88,6 +92,9 @@ runNullLog action = do
|
||||
runGmOutDef :: IOish m => GmOutT m a -> m a
|
||||
runGmOutDef = runGmOutT defaultOptions
|
||||
|
||||
runLogDef :: IOish m => GmOutT (JournalT GhcModLog m) a -> m a
|
||||
runLogDef = fmap fst . runJournalT . runGmOutDef
|
||||
|
||||
shouldReturnError :: Show a
|
||||
=> IO (Either GhcModError a, GhcModLog)
|
||||
-> Expectation
|
||||
|
||||
Reference in New Issue
Block a user