ghc-mod/test/Main.hs

52 lines
1.7 KiB
Haskell
Raw Normal View History

{-# LANGUAGE CPP, ScopedTypeVariables #-}
import Spec
import Dir
import Control.Exception as E
2014-08-20 03:14:27 +00:00
import Control.Monad (void)
2015-03-04 20:48:21 +00:00
import Data.List
2014-08-20 03:14:27 +00:00
import Language.Haskell.GhcMod (debugInfo)
import System.Process
import Test.Hspec
import TestUtils
2014-08-20 03:14:27 +00:00
main :: IO ()
main = do
2015-03-04 20:48:21 +00:00
let sandboxes = [ "test/data/cabal-project"
, "test/data/check-packageid"
, "test/data/duplicate-pkgver/"
, "test/data/broken-cabal/"
]
2014-08-20 03:14:27 +00:00
genSandboxCfg dir = withDirectory dir $ \cwdir -> do
system ("sed 's|@CWD@|" ++ cwdir ++ "|g' cabal.sandbox.config.in > cabal.sandbox.config")
pkgDirs =
2015-03-04 20:48:21 +00:00
[ "test/data/cabal-project/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d"
, "test/data/check-packageid/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d"
, "test/data/duplicate-pkgver/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d"]
genGhcPkgCache dir = system $ "ghc-pkg recache --force -f" ++ dir
2015-03-04 20:48:21 +00:00
genSandboxCfg `mapM_` sandboxes
genGhcPkgCache `mapM_` pkgDirs
2015-03-04 20:48:21 +00:00
let caches = [ "setup-config"
, "setup-config.ghc-mod.cabal-ghc-options"
, "setup-config.ghc-mod.cabal-helper.ghc-options"
, "setup-config.ghc-mod.cabal-helper"
, "ghc-mod.cache"
]
cachesFindExp :: String
cachesFindExp = unwords $ intersperse "-o " $ map ("-name "++) caches
cleanCmd = "find test \\( "++ cachesFindExp ++" \\) -exec rm {} \\;"
print cleanCmd
void $ system cleanCmd
2014-08-20 03:14:27 +00:00
void $ system "cabal --version"
putStrLn $ "ghc-mod was built with Cabal version " ++ VERSION_Cabal
2014-08-20 03:14:27 +00:00
void $ system "ghc --version"
(putStrLn =<< runD debugInfo)
`E.catch` (\(_ :: E.SomeException) -> return () )
hspec spec