2014-11-01 21:02:47 +00:00
|
|
|
module PathsAndFilesSpec where
|
2014-04-15 03:13:10 +00:00
|
|
|
|
2015-08-19 06:46:56 +00:00
|
|
|
|
2017-05-28 02:22:56 +00:00
|
|
|
import GhcMod.PathsAndFiles
|
|
|
|
import GhcMod.Cradle
|
|
|
|
import qualified GhcMod.Utils as U
|
2014-05-04 22:28:03 +00:00
|
|
|
|
2015-08-19 06:46:56 +00:00
|
|
|
import Control.Monad.Trans.Maybe
|
2014-04-15 03:13:10 +00:00
|
|
|
import System.Directory
|
2015-02-07 15:41:15 +00:00
|
|
|
import System.FilePath
|
2014-04-15 03:13:10 +00:00
|
|
|
import Test.Hspec
|
2015-02-07 15:41:15 +00:00
|
|
|
import TestUtils
|
2014-04-15 03:13:10 +00:00
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = do
|
2014-05-18 23:20:58 +00:00
|
|
|
describe "getSandboxDb" $ do
|
2014-07-11 01:10:37 +00:00
|
|
|
it "can parse a config file and extract the sandbox package-db" $ do
|
2014-04-15 03:13:10 +00:00
|
|
|
cwd <- getCurrentDirectory
|
2016-05-14 18:18:06 +00:00
|
|
|
Just crdl <- runLogDef $ runMaybeT $ plainCradle "test/data/cabal-project"
|
2015-08-19 06:46:56 +00:00
|
|
|
Just db <- getSandboxDb crdl
|
2015-03-04 20:48:21 +00:00
|
|
|
db `shouldSatisfy` isPkgDbAt (cwd </> "test/data/cabal-project/.cabal-sandbox")
|
2014-04-15 03:13:10 +00:00
|
|
|
|
2014-11-01 21:02:47 +00:00
|
|
|
it "returns Nothing if the sandbox config file is broken" $ do
|
2016-05-14 18:18:06 +00:00
|
|
|
Just crdl <- runLogDef $ runMaybeT $ plainCradle "test/data/broken-sandbox"
|
2015-08-19 06:46:56 +00:00
|
|
|
getSandboxDb crdl `shouldReturn` Nothing
|
2014-11-02 23:04:15 +00:00
|
|
|
|
2014-11-02 23:45:27 +00:00
|
|
|
describe "findCabalFile" $ do
|
|
|
|
it "works" $ do
|
2015-09-08 04:20:12 +00:00
|
|
|
p <- U.makeAbsolute' "test/data/cabal-project/cabalapi.cabal"
|
|
|
|
findCabalFile "test/data/cabal-project" `shouldReturn` Just p
|
2014-11-02 23:45:27 +00:00
|
|
|
|
|
|
|
it "finds cabal files in parent directories" $ do
|
2015-09-08 04:20:12 +00:00
|
|
|
p <- U.makeAbsolute' "test/data/cabal-project/cabalapi.cabal"
|
|
|
|
findCabalFile "test/data/cabal-project/subdir1/subdir2" `shouldReturn` Just p
|
2015-02-07 15:41:15 +00:00
|
|
|
|
2015-08-17 09:20:43 +00:00
|
|
|
describe "findStackConfigFile" $ do
|
|
|
|
it "works" $ do
|
2015-09-08 04:42:32 +00:00
|
|
|
p <- U.makeAbsolute' "test/data/stack-project/stack.yaml"
|
|
|
|
findStackConfigFile "test/data/stack-project" `shouldReturn` Just p
|
2015-08-17 09:20:43 +00:00
|
|
|
|
2015-02-07 15:41:15 +00:00
|
|
|
describe "findCabalSandboxDir" $ do
|
|
|
|
it "works" $ do
|
2015-09-08 04:42:32 +00:00
|
|
|
p <- U.makeAbsolute' "test/data/cabal-project"
|
2015-09-08 04:20:12 +00:00
|
|
|
findCabalSandboxDir "test/data/cabal-project" `shouldReturn` Just p
|
2015-02-07 15:41:15 +00:00
|
|
|
|
|
|
|
it "finds sandboxes in parent directories" $ do
|
2015-09-08 04:42:32 +00:00
|
|
|
p <- U.makeAbsolute' "test/data/cabal-project"
|
2015-09-08 04:20:12 +00:00
|
|
|
findCabalSandboxDir "test/data/cabal-project/subdir1/subdir2" `shouldReturn` Just p
|