ghc-mod/test/CabalApiSpec.hs

66 lines
5.3 KiB
Haskell
Raw Normal View History

{-# LANGUAGE ScopedTypeVariables #-}
2013-02-12 07:24:33 +00:00
module CabalApiSpec where
2013-03-01 03:21:42 +00:00
import Control.Applicative
import Control.Exception
2013-09-20 02:22:56 +00:00
import Data.Maybe
2013-05-20 02:29:44 +00:00
import Language.Haskell.GhcMod.CabalApi
2013-09-20 02:22:56 +00:00
import Language.Haskell.GhcMod.Cradle
import Language.Haskell.GhcMod.Types
2013-02-12 07:24:33 +00:00
import Test.Hspec
import System.Directory
import System.FilePath
2013-02-12 07:24:33 +00:00
2013-09-20 02:22:56 +00:00
import Dir
2014-08-12 16:11:32 +00:00
import TestUtils
2013-09-20 02:22:56 +00:00
import Config (cProjectVersionInt) -- ghc version
ghcVersion :: Int
ghcVersion = read cProjectVersionInt
2013-02-12 07:24:33 +00:00
spec :: Spec
spec = do
describe "parseCabalFile" $ do
it "throws an exception if the cabal file is broken" $ do
2014-08-12 16:11:32 +00:00
shouldReturnError $
runD' $ parseCabalFile "test/data/broken-cabal/broken.cabal"
2013-09-20 02:22:56 +00:00
describe "getCompilerOptions" $ do
it "gets necessary CompilerOptions" $ do
cwd <- getCurrentDirectory
2013-09-20 02:22:56 +00:00
withDirectory "test/data/subdir1/subdir2" $ \dir -> do
cradle <- findCradle
2014-08-12 16:11:32 +00:00
pkgDesc <- runD $ parseCabalFile $ fromJust $ cradleCabalFile cradle
res <- runD $ getCompilerOptions [] cradle pkgDesc
let res' = res {
2013-09-21 09:37:33 +00:00
ghcOptions = ghcOptions res
, includeDirs = map (toRelativeDir dir) (includeDirs res)
}
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"]
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"]
2014-04-17 21:49:23 +00:00
includeDirs res' `shouldBe` ["test/data","test/data/dist/build","test/data/dist/build/autogen","test/data/subdir1/subdir2","test/data/test"]
2014-05-01 00:30:36 +00:00
(pkgName `map` depPackages res') `shouldContain` ["Cabal"]
2013-09-20 02:22:56 +00:00
2013-09-16 01:16:33 +00:00
describe "cabalDependPackages" $ do
2013-02-12 07:24:33 +00:00
it "extracts dependent packages" $ do
2014-08-12 16:11:32 +00:00
pkgs <- cabalDependPackages . cabalAllBuildInfo <$> runD (parseCabalFile "test/data/cabalapi.cabal")
2013-03-13 03:48:26 +00:00
pkgs `shouldBe` ["Cabal","base","template-haskell"]
2013-02-12 07:24:33 +00:00
2013-09-16 01:16:33 +00:00
describe "cabalSourceDirs" $ do
it "extracts all hs-source-dirs" $ do
2014-08-12 16:11:32 +00:00
dirs <- cabalSourceDirs . cabalAllBuildInfo <$> runD (parseCabalFile "test/data/check-test-subdir/check-test-subdir.cabal")
dirs `shouldBe` ["src", "test"]
2013-09-20 02:22:56 +00:00
it "extracts all hs-source-dirs including \".\"" $ do
2014-08-12 16:11:32 +00:00
dirs <- cabalSourceDirs . cabalAllBuildInfo <$> runD (parseCabalFile "test/data/cabalapi.cabal")
2013-09-20 02:22:56 +00:00
dirs `shouldBe` [".", "test"]
2013-09-20 01:48:51 +00:00
describe "cabalAllBuildInfo" $ do
2013-02-12 07:24:33 +00:00
it "extracts build info" $ do
2014-08-12 16:11:32 +00:00
info <- cabalAllBuildInfo <$> runD (parseCabalFile "test/data/cabalapi.cabal")
show info `shouldBe` "[BuildInfo {buildable = True, buildTools = [], cppOptions = [], ccOptions = [], ldOptions = [], pkgconfigDepends = [], frameworks = [], cSources = [], hsSourceDirs = [\".\"], otherModules = [ModuleName [\"Browse\"],ModuleName [\"CabalApi\"],ModuleName [\"Cabal\"],ModuleName [\"CabalDev\"],ModuleName [\"Check\"],ModuleName [\"ErrMsg\"],ModuleName [\"Flag\"],ModuleName [\"GHCApi\"],ModuleName [\"GHCChoice\"],ModuleName [\"Gap\"],ModuleName [\"Info\"],ModuleName [\"Lang\"],ModuleName [\"Lint\"],ModuleName [\"List\"],ModuleName [\"Paths_ghc_mod\"],ModuleName [\"Types\"]], defaultLanguage = Nothing, otherLanguages = [], defaultExtensions = [], otherExtensions = [], oldExtensions = [], extraLibs = [], extraLibDirs = [], includeDirs = [], includes = [], installIncludes = [], options = [(GHC,[\"-Wall\"])], ghcProfOptions = [], ghcSharedOptions = [], customFieldsBI = [], targetBuildDepends = [Dependency (PackageName \"Cabal\") (UnionVersionRanges (ThisVersion (Version {versionBranch = [1,10], versionTags = []})) (LaterVersion (Version {versionBranch = [1,10], versionTags = []}))),Dependency (PackageName \"base\") (IntersectVersionRanges (UnionVersionRanges (ThisVersion (Version {versionBranch = [4,0], versionTags = []})) (LaterVersion (Version {versionBranch = [4,0], versionTags = []}))) (EarlierVersion (Version {versionBranch = [5], versionTags = []}))),Dependency (PackageName \"template-haskell\") AnyVersion]},BuildInfo {buildable = True, buildTools = [], cppOptions = [], ccOptions = [], ldOptions = [], pkgconfigDepends = [], frameworks = [], cSources = [], hsSourceDirs = [\"test\",\".\"], otherModules = [ModuleName [\"Expectation\"],ModuleName [\"BrowseSpec\"],ModuleName [\"CabalApiSpec\"],ModuleName [\"FlagSpec\"],ModuleName [\"LangSpec\"],ModuleName [\"LintSpec\"],ModuleName [\"ListSpec\"]], defaultLanguage = Nothing, otherLanguages = [], defaultExtensions = [], otherExtensions = [], oldExtensions = [], extraLibs = [], extraLibDirs = [], includeDirs = [], includes = [], installIncludes = [], options = [], ghcProfOptions = [], ghcSharedOptions = [], customFieldsBI = [], targetBuildDepends = [Dependency (PackageName \"Cabal\") (UnionVersionRanges (ThisVersion (Version {versionBranch = [1,10], versionTags = []})) (LaterVersion (Version {versionBranch = [1,10], versionTags = []}))),Dependency (PackageName \"base\") (IntersectVersionRanges (UnionVersionRanges (ThisVersion (Version {versionBranch = [4,0], versionTags = []})) (LaterVersion (Version {versionBranch = [4,0], versionTags = []}))) (EarlierVersion (Version {versionBranch = [5], versionTags = []})))]}]"