2015-03-05 15:50:06 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module TargetSpec where
|
|
|
|
|
2017-05-28 02:22:56 +00:00
|
|
|
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
|
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
|
2016-07-16 01:42:59 +00:00
|
|
|
(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"]
|
2016-07-16 01:42:59 +00:00
|
|
|
liftIO $ i `shouldSatisfy` not . null) :: IO ()
|
2015-03-05 15:50:06 +00:00
|
|
|
|
|
|
|
it "can get module info" $ do
|
2016-07-16 01:42:59 +00:00
|
|
|
(withLightHscEnv [] $ \env ->
|
2015-03-05 15:50:06 +00:00
|
|
|
runLightGhc env $ do
|
|
|
|
mdl <- findModule "Data.List" Nothing
|
|
|
|
mmi <- getModuleInfo mdl
|
2016-07-16 01:42:59 +00:00
|
|
|
liftIO $ isJust mmi `shouldBe` True) :: IO ()
|
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")
|