2015-03-05 15:50:06 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module TargetSpec where
|
|
|
|
|
|
|
|
import Language.Haskell.GhcMod.Target
|
2015-08-18 05:41:08 +00:00
|
|
|
import Language.Haskell.GhcMod.LightGhc
|
2015-03-05 15:50:06 +00:00
|
|
|
import Language.Haskell.GhcMod.Gap
|
|
|
|
import Test.Hspec
|
|
|
|
|
|
|
|
import TestUtils
|
|
|
|
|
|
|
|
import GHC
|
|
|
|
import Data.List
|
|
|
|
import Data.Maybe
|
2015-06-19 15:15:14 +00:00
|
|
|
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 ->
|
|
|
|
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
|
|
|
|
|
|
|
|
it "can get module info" $ do
|
|
|
|
withLightHscEnv [] $ \env ->
|
|
|
|
runLightGhc env $ do
|
|
|
|
mdl <- findModule "Data.List" Nothing
|
|
|
|
mmi <- getModuleInfo mdl
|
|
|
|
liftIO $ isJust mmi `shouldBe` True
|
2015-06-19 15:15:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
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")
|