ghc-mod/test/CabalHelperSpec.hs

71 lines
2.5 KiB
Haskell
Raw Normal View History

2015-03-05 15:50:06 +00:00
module CabalHelperSpec where
import Control.Arrow
import Control.Applicative
2015-03-28 01:33:42 +00:00
-- import Language.Haskell.GhcMod.CabalHelper
-- import Language.Haskell.GhcMod.PathsAndFiles
2015-03-05 15:50:06 +00:00
import Language.Haskell.GhcMod.Error
import Test.Hspec
2015-03-28 01:33:42 +00:00
-- import System.Directory
-- import System.FilePath
-- import System.Process (readProcess)
2015-03-05 15:50:06 +00:00
2015-03-28 01:33:42 +00:00
-- import Dir
-- import TestUtils
2015-03-05 15:50:06 +00:00
import Data.List
import Config (cProjectVersionInt)
ghcVersion :: Int
ghcVersion = read cProjectVersionInt
gmeProcessException :: GhcModError -> Bool
gmeProcessException GMEProcess {} = True
gmeProcessException _ = False
pkgOptions :: [String] -> [String]
pkgOptions [] = []
pkgOptions (_:[]) = []
pkgOptions (x:y:xs) | x == "-package-id" = [name y] ++ pkgOptions xs
| otherwise = pkgOptions (y:xs)
where
stripDash s = maybe s id $ (flip drop s . (+1) <$> findIndex (=='-') s)
name s = reverse $ stripDash $ stripDash $ reverse s
idirOpts :: [(c, [String])] -> [(c, [String])]
idirOpts = map (second $ map (drop 2) . filter ("-i"`isPrefixOf`))
spec :: Spec
2015-03-28 01:33:42 +00:00
spec = do return ()
-- describe "getGhcOptions" $ do
-- it "throws an exception if the cabal file is broken" $ do
-- let tdir = "test/data/broken-caba"
-- runD' tdir getGhcOptions `shouldThrow` anyIOException
2015-03-05 15:50:06 +00:00
2015-03-28 01:33:42 +00:00
-- it "handles sandboxes correctly" $ do
-- let tdir = "test/data/cabal-project"
-- cwd <- getCurrentDirectory
2015-03-05 15:50:06 +00:00
2015-03-28 01:33:42 +00:00
-- opts <- runD' tdir getGhcOptions
2015-03-05 15:50:06 +00:00
2015-03-28 01:33:42 +00:00
-- if ghcVersion < 706
-- then forM_ opts (\(_, o) -> o `shouldContain` ["-no-user-package-conf","-package-conf", cwd </> "test/data/cabal-project/.cabal-sandbox/"++ghcSandboxPkgDbDir])
-- else forM_ opts (\(_, o) -> o `shouldContain` ["-no-user-package-db","-package-db",cwd </> "test/data/cabal-project/.cabal-sandbox/"++ghcSandboxPkgDbDir])
2015-03-05 15:50:06 +00:00
2015-03-28 01:33:42 +00:00
-- it "extracts build dependencies" $ do
-- let tdir = "test/data/cabal-project"
-- opts <- runD' tdir getGhcOptions
-- let ghcOpts = snd $ head opts
-- pkgs = pkgOptions ghcOpts
-- pkgs `shouldBe` ["Cabal","base","template-haskell"]
2015-03-05 15:50:06 +00:00
2015-03-28 01:33:42 +00:00
-- it "uses non default flags" $ do
-- let tdir = "test/data/cabal-flags"
-- _ <- withDirectory_ tdir $
-- readProcess "cabal" ["configure", "-ftest-flag"] ""
2015-03-05 15:50:06 +00:00
2015-03-28 01:33:42 +00:00
-- opts <- runD' tdir getGhcOptions
-- let ghcOpts = snd $ head opts
-- pkgs = pkgOptions ghcOpts
-- pkgs `shouldBe` ["Cabal","base"]