ghc-mod/test/TargetSpec.hs

48 lines
1.5 KiB
Haskell
Raw Normal View History

2015-03-05 15:50:06 +00:00
{-# LANGUAGE OverloadedStrings #-}
module TargetSpec where
import GhcMod.Target
import GhcMod.LightGhc
import GhcMod.Gap
2015-03-05 15:50:06 +00:00
import Test.Hspec
import TestUtils
import GHC
import Data.List
import Data.Maybe
import System.Directory
import System.FilePath
2015-03-05 15:50:06 +00:00
spec :: Spec
spec = do
describe "runLightGhc" $ do
it "works at all" $ do
withLightHscEnv [] $ \env ->
runLightGhc env (return ()) `shouldReturn` ()
it "has modules in scope" $ do
(withLightHscEnv [] $ \env ->
2015-03-05 15:50:06 +00:00
runLightGhc env $ do
dflags <- getSessionDynFlags
let i = intersect (listVisibleModuleNames dflags)
["Control.Applicative", "Control.Arrow"
,"Control.Exception", "GHC.Exts", "GHC.Float"]
liftIO $ i `shouldSatisfy` not . null) :: IO ()
2015-03-05 15:50:06 +00:00
it "can get module info" $ do
(withLightHscEnv [] $ \env ->
2015-03-05 15:50:06 +00:00
runLightGhc env $ do
mdl <- findModule "Data.List" Nothing
mmi <- getModuleInfo mdl
liftIO $ isJust mmi `shouldBe` True) :: IO ()
describe "resolveModule" $ do
it "Works when a module given as path uses CPP" $ do
dir <- getCurrentDirectory
let srcDirs = [dir </> "test/data/target/src"]
2015-08-14 07:50:20 +00:00
x <- withLightHscEnv [] $ \env -> runD $ do
2015-08-06 03:18:57 +00:00
resolveModule env srcDirs (Left $ dir </> "test/data/target/Cpp.hs")
liftIO $ x `shouldBe` Just (ModulePath "Cpp" $ dir </> "test/data/target/Cpp.hs")