ghc-mod/test/Main.hs

97 lines
3.3 KiB
Haskell
Raw Normal View History

{-# LANGUAGE CPP, ScopedTypeVariables #-}
import Dir
import Control.Exception as E
2014-08-20 03:14:27 +00:00
import Control.Monad (void)
import GhcMod (debugInfo)
2014-08-20 03:14:27 +00:00
import System.Process
2016-08-03 11:14:31 +00:00
import System.Environment
2014-08-20 03:14:27 +00:00
import Test.Hspec
import TestUtils
import qualified BrowseSpec
import qualified CabalHelperSpec
import qualified CaseSplitSpec
import qualified CheckSpec
import qualified CradleSpec
import qualified CustomPackageDbSpec
import qualified FileMappingSpec
import qualified FindSpec
import qualified FlagSpec
import qualified GhcPkgSpec
import qualified HomeModuleGraphSpec
import qualified InfoSpec
import qualified LangSpec
import qualified LintSpec
import qualified ListSpec
import qualified MonadSpec
import qualified PathsAndFilesSpec
import qualified ShellParseSpec
import qualified TargetSpec
spec :: Spec
spec = do
describe "Browse" BrowseSpec.spec
describe "CabalHelper" CabalHelperSpec.spec
describe "CaseSplit" CaseSplitSpec.spec
describe "Check" CheckSpec.spec
describe "Cradle" CradleSpec.spec
describe "CustomPackageDb" CustomPackageDbSpec.spec
describe "FileMapping" FileMappingSpec.spec
describe "Find" FindSpec.spec
describe "Flag" FlagSpec.spec
describe "GhcPkg" GhcPkgSpec.spec
describe "HomeModuleGraph" HomeModuleGraphSpec.spec
describe "Info" InfoSpec.spec
describe "Lang" LangSpec.spec
describe "Lint" LintSpec.spec
describe "List" ListSpec.spec
describe "Monad" MonadSpec.spec
describe "PathsAndFiles" PathsAndFilesSpec.spec
describe "ShellParse" ShellParseSpec.spec
describe "Target" TargetSpec.spec
2014-08-20 03:14:27 +00:00
main :: IO ()
main = do
2016-08-03 11:25:05 +00:00
#if __GLASGOW_HASKELL__ >= 708
2016-08-03 11:14:31 +00:00
unsetEnv "GHC_PACKAGE_PATH"
2016-08-03 11:25:05 +00:00
#endif
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
2017-03-01 07:20:19 +00:00
system ("rm cabal.sandbox.config; cabal sandbox init")
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
2016-08-28 20:59:55 +00:00
let cleanCmd = "git clean -dXf test/data/"
2015-03-28 01:33:42 +00:00
putStrLn $ "$ " ++ cleanCmd
2015-03-04 20:48:21 +00:00
void $ system cleanCmd
2014-08-20 03:14:27 +00:00
void $ system "cabal --version"
void $ system "ghc --version"
2016-08-28 20:33:40 +00:00
genSandboxCfg `mapM_` sandboxes
genGhcPkgCache `mapM_` pkgDirs
2015-08-19 04:48:27 +00:00
let stackDir = "test/data/stack-project"
void $ withDirectory_ stackDir $ do
let ghcver = let gvn = show (__GLASGOW_HASKELL__ :: Int)
(major, minor') = splitAt (length gvn - 2) gvn
minor = case dropWhile (=='0') minor' of
"" -> "0"
x -> x
in major ++ "." ++ minor
void $ system $ "sed '$ a resolver: ghc-" ++ ghcver ++ "' stack.yaml.in > stack.yaml"
2015-08-19 04:48:27 +00:00
void $ system "stack setup"
void $ system "stack build"
(putStrLn =<< runD debugInfo)
`E.catch` (\(_ :: E.SomeException) -> return () )
hspec spec