Fix tests for Cabal <= 1.16
This commit is contained in:
parent
d1da6ab289
commit
8741323f5b
@ -1,4 +1,4 @@
|
|||||||
{-# LANGUAGE BangPatterns, ScopedTypeVariables, TupleSections #-}
|
{-# LANGUAGE CPP, BangPatterns, ScopedTypeVariables, TupleSections #-}
|
||||||
module Language.Haskell.GhcMod.GhcPkg (
|
module Language.Haskell.GhcMod.GhcPkg (
|
||||||
ghcPkgDbOpt
|
ghcPkgDbOpt
|
||||||
, ghcPkgDbStackOpts
|
, ghcPkgDbStackOpts
|
||||||
@ -12,7 +12,9 @@ module Language.Haskell.GhcMod.GhcPkg (
|
|||||||
|
|
||||||
import Config (cProjectVersionInt)
|
import Config (cProjectVersionInt)
|
||||||
import Control.Applicative ((<$>))
|
import Control.Applicative ((<$>))
|
||||||
|
#if MIN_VERSION_Cabal(1,18,0)
|
||||||
import Control.Exception (SomeException(..))
|
import Control.Exception (SomeException(..))
|
||||||
|
#endif
|
||||||
import qualified Control.Exception as E
|
import qualified Control.Exception as E
|
||||||
import Data.Char (isSpace)
|
import Data.Char (isSpace)
|
||||||
import Data.List (isPrefixOf, intercalate)
|
import Data.List (isPrefixOf, intercalate)
|
||||||
@ -51,8 +53,12 @@ getPackageDbStack :: FilePath -- ^ Project Directory (where the
|
|||||||
-- exists)
|
-- exists)
|
||||||
-> IO [GhcPkgDb]
|
-> IO [GhcPkgDb]
|
||||||
getPackageDbStack cdir =
|
getPackageDbStack cdir =
|
||||||
|
#if MIN_VERSION_Cabal(1,18,0)
|
||||||
(getSandboxDb cdir >>= \db -> return [GlobalDb, PackageDb db])
|
(getSandboxDb cdir >>= \db -> return [GlobalDb, PackageDb db])
|
||||||
`E.catch` \(_ :: SomeException) -> return [GlobalDb, UserDb]
|
`E.catch` \(_ :: SomeException) -> return [GlobalDb, UserDb]
|
||||||
|
#else
|
||||||
|
return [GlobalDb, UserDb]
|
||||||
|
#endif
|
||||||
|
|
||||||
fromInstalledPackageId' :: InstalledPackageId -> Maybe Package
|
fromInstalledPackageId' :: InstalledPackageId -> Maybe Package
|
||||||
fromInstalledPackageId' pid = let
|
fromInstalledPackageId' pid = let
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{-# LANGUAGE ScopedTypeVariables #-}
|
{-# LANGUAGE CPP, ScopedTypeVariables #-}
|
||||||
|
|
||||||
module CabalApiSpec where
|
module CabalApiSpec where
|
||||||
|
|
||||||
@ -36,9 +36,15 @@ spec = do
|
|||||||
ghcOptions = ghcOptions res
|
ghcOptions = ghcOptions res
|
||||||
, includeDirs = map (toRelativeDir dir) (includeDirs res)
|
, includeDirs = map (toRelativeDir dir) (includeDirs res)
|
||||||
}
|
}
|
||||||
|
#if MIN_VERSION_Cabal(1,18,0)
|
||||||
if ghcVersion < 706
|
if ghcVersion < 706
|
||||||
then ghcOptions res' `shouldContain` ["-global-package-conf", "-no-user-package-conf","-package-conf",cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d","-XHaskell98"]
|
then ghcOptions res' `shouldContain` ["-global-package-conf", "-no-user-package-conf","-package-conf",cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d","-XHaskell98"]
|
||||||
else ghcOptions res' `shouldContain` ["-global-package-db", "-no-user-package-db","-package-db",cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d","-XHaskell98"]
|
else ghcOptions res' `shouldContain` ["-global-package-db", "-no-user-package-db","-package-db",cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d","-XHaskell98"]
|
||||||
|
#else
|
||||||
|
if ghcVersion < 706
|
||||||
|
then ghcOptions res' `shouldContain` ["-global-package-conf", "-user-package-conf","-XHaskell98"]
|
||||||
|
else ghcOptions res' `shouldContain` ["-global-package-db", "-user-package-db","-XHaskell98"]
|
||||||
|
#endif
|
||||||
includeDirs res' `shouldBe` ["test/data","test/data/dist/build","test/data/dist/build/autogen","test/data/subdir1/subdir2","test/data/test"]
|
includeDirs res' `shouldBe` ["test/data","test/data/dist/build","test/data/dist/build/autogen","test/data/subdir1/subdir2","test/data/test"]
|
||||||
(pkgName `map` depPackages res') `shouldContain` ["Cabal"]
|
(pkgName `map` depPackages res') `shouldContain` ["Cabal"]
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
{-# LANGUAGE CPP #-}
|
||||||
module CradleSpec where
|
module CradleSpec where
|
||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
@ -31,7 +32,11 @@ spec = do
|
|||||||
cradleCurrentDir = "test" </> "data" </> "subdir1" </> "subdir2"
|
cradleCurrentDir = "test" </> "data" </> "subdir1" </> "subdir2"
|
||||||
, cradleRootDir = "test" </> "data"
|
, cradleRootDir = "test" </> "data"
|
||||||
, cradleCabalFile = Just ("test" </> "data" </> "cabalapi.cabal")
|
, cradleCabalFile = Just ("test" </> "data" </> "cabalapi.cabal")
|
||||||
|
#if MIN_VERSION_Cabal(1,18,0)
|
||||||
, cradlePkgDbStack = [GlobalDb, PackageDb (cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d")]
|
, cradlePkgDbStack = [GlobalDb, PackageDb (cwd </> "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d")]
|
||||||
|
#else
|
||||||
|
, cradlePkgDbStack = [GlobalDb, UserDb]
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
it "works even if a sandbox config file is broken" $ do
|
it "works even if a sandbox config file is broken" $ do
|
||||||
withDirectory "test/data/broken-sandbox" $ \dir -> do
|
withDirectory "test/data/broken-sandbox" $ \dir -> do
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
{-# LANGUAGE CPP #-}
|
||||||
module GhcPkgSpec where
|
module GhcPkgSpec where
|
||||||
|
|
||||||
import Language.Haskell.GhcMod.GhcPkg
|
import Language.Haskell.GhcMod.GhcPkg
|
||||||
|
import Language.Haskell.GhcMod.Types
|
||||||
|
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import System.FilePath ((</>))
|
import System.FilePath ((</>))
|
||||||
@ -8,7 +10,12 @@ import Test.Hspec
|
|||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = do
|
spec = do
|
||||||
describe "getSandboxDb" $ do
|
describe "getPackageDbStack" $ do
|
||||||
|
#if !MIN_VERSION_Cabal(1,18,0)
|
||||||
|
it "does not include a sandbox with Cabal < 1.18" $ do
|
||||||
|
cwd <- getCurrentDirectory
|
||||||
|
getPackageDbStack cwd `shouldReturn` [GlobalDb, UserDb]
|
||||||
|
#endif
|
||||||
it "parses a config file and extracts sandbox package db" $ do
|
it "parses a config file and extracts sandbox package db" $ do
|
||||||
cwd <- getCurrentDirectory
|
cwd <- getCurrentDirectory
|
||||||
pkgDb <- getSandboxDb "test/data/"
|
pkgDb <- getSandboxDb "test/data/"
|
||||||
|
Loading…
Reference in New Issue
Block a user