2014-05-18 23:29:49 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
2014-11-01 21:02:47 +00:00
|
|
|
module PathsAndFilesSpec where
|
2014-04-15 03:13:10 +00:00
|
|
|
|
2014-11-01 21:02:47 +00:00
|
|
|
import Language.Haskell.GhcMod.PathsAndFiles
|
2014-08-20 03:35:36 +00:00
|
|
|
#if __GLASGOW_HASKELL__ <= 706
|
|
|
|
import Language.Haskell.GhcMod.Types
|
2014-11-01 21:02:47 +00:00
|
|
|
import Language.Haskell.GhcMod.GhcPkg
|
2014-08-20 03:35:36 +00:00
|
|
|
#endif
|
2014-05-04 22:28:03 +00:00
|
|
|
|
2014-04-15 03:13:10 +00:00
|
|
|
import System.Directory
|
2014-11-02 23:04:15 +00:00
|
|
|
import System.Environment
|
2014-04-15 03:13:10 +00:00
|
|
|
import System.FilePath ((</>))
|
|
|
|
import Test.Hspec
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = do
|
2014-05-18 23:20:58 +00:00
|
|
|
describe "getSandboxDb" $ do
|
2014-05-18 23:29:49 +00:00
|
|
|
-- ghc < 7.8
|
2014-08-20 03:35:36 +00:00
|
|
|
#if __GLASGOW_HASKELL__ <= 706
|
2014-05-18 23:29:49 +00:00
|
|
|
it "does include a sandbox with ghc < 7.8" $ do
|
|
|
|
cwd <- getCurrentDirectory
|
|
|
|
getPackageDbStack "test/data/" `shouldReturn` [GlobalDb, PackageDb $ cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d"]
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
pkgDb <- getSandboxDb "test/data/"
|
2014-11-01 21:02:47 +00:00
|
|
|
pkgDb `shouldBe` Just (cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d")
|
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
|
|
|
|
getSandboxDb "test/data/broken-sandbox" `shouldReturn` Nothing
|
2014-11-02 23:04:15 +00:00
|
|
|
|
|
|
|
describe "getCabalFiles" $ do
|
|
|
|
it "doesn't think $HOME/.cabal is a cabal file" $ do
|
|
|
|
(getCabalFiles =<< getEnv "HOME") `shouldReturn` []
|
2014-11-02 23:45:27 +00:00
|
|
|
|
|
|
|
describe "findCabalFile" $ do
|
|
|
|
it "works" $ do
|
|
|
|
findCabalFile "test/data" `shouldReturn` Just "test/data/cabalapi.cabal"
|
|
|
|
|
|
|
|
it "finds cabal files in parent directories" $ do
|
|
|
|
findCabalFile "test/data/subdir1/subdir2" `shouldReturn` Just "test/data/cabalapi.cabal"
|