Ghc -> GhcMod: Browse, Check
This commit is contained in:
@@ -5,30 +5,30 @@ import Language.Haskell.GhcMod
|
||||
import Language.Haskell.GhcMod.Cradle
|
||||
import Test.Hspec
|
||||
|
||||
import TestUtils
|
||||
import Dir
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "browseModule" $ do
|
||||
describe "browse" $ do
|
||||
it "lists up symbols in the module" $ do
|
||||
cradle <- findCradle
|
||||
syms <- lines <$> browseModule defaultOptions cradle "Data.Map"
|
||||
syms <- runD $ lines <$> browse "Data.Map"
|
||||
syms `shouldContain` ["differenceWithKey"]
|
||||
|
||||
describe "browseModule -d" $ do
|
||||
describe "browse -d" $ do
|
||||
it "lists up symbols with type info in the module" $ do
|
||||
cradle <- findCradle
|
||||
syms <- lines <$> browseModule defaultOptions { detailed = True } cradle "Data.Either"
|
||||
syms <- run defaultOptions { detailed = True }
|
||||
$ lines <$> browse "Data.Either"
|
||||
syms `shouldContain` ["either :: (a -> c) -> (b -> c) -> Either a b -> c"]
|
||||
|
||||
it "lists up data constructors with type info in the module" $ do
|
||||
cradle <- findCradle
|
||||
syms <- lines <$> browseModule defaultOptions { detailed = True} cradle "Data.Either"
|
||||
syms <- run defaultOptions { detailed = True}
|
||||
$ lines <$> browse "Data.Either"
|
||||
syms `shouldContain` ["Left :: a -> Either a b"]
|
||||
|
||||
describe "browseModule local" $ do
|
||||
describe "browse local" $ do
|
||||
it "lists symbols in a local module" $ do
|
||||
withDirectory_ "test/data" $ do
|
||||
cradle <- findCradleWithoutSandbox
|
||||
syms <- lines <$> browseModule defaultOptions cradle "Baz"
|
||||
syms <- runID $ lines <$> browse "Baz"
|
||||
syms `shouldContain` ["baz"]
|
||||
|
||||
@@ -6,6 +6,7 @@ import Language.Haskell.GhcMod.Cradle
|
||||
import System.FilePath
|
||||
import Test.Hspec
|
||||
|
||||
import TestUtils
|
||||
import Dir
|
||||
|
||||
spec :: Spec
|
||||
@@ -13,26 +14,22 @@ spec = do
|
||||
describe "checkSyntax" $ do
|
||||
it "can check even if an executable depends on its library" $ do
|
||||
withDirectory_ "test/data/ghc-mod-check" $ do
|
||||
cradle <- findCradleWithoutSandbox
|
||||
res <- checkSyntax defaultOptions cradle ["main.hs"]
|
||||
res <- runID $ checkSyntax ["main.hs"]
|
||||
res `shouldBe` "main.hs:5:1:Warning: Top-level binding with no type signature: main :: IO ()\n"
|
||||
|
||||
it "can check even if a test module imports another test module located at different directory" $ do
|
||||
withDirectory_ "test/data/check-test-subdir" $ do
|
||||
cradle <- findCradleWithoutSandbox
|
||||
res <- checkSyntax defaultOptions cradle ["test/Bar/Baz.hs"]
|
||||
res <- runID $ checkSyntax ["test/Bar/Baz.hs"]
|
||||
res `shouldSatisfy` (("test" </> "Foo.hs:3:1:Warning: Top-level binding with no type signature: foo :: [Char]\n") `isSuffixOf`)
|
||||
|
||||
it "can detect mutually imported modules" $ do
|
||||
withDirectory_ "test/data" $ do
|
||||
cradle <- findCradleWithoutSandbox
|
||||
res <- checkSyntax defaultOptions cradle ["Mutual1.hs"]
|
||||
res <- runID $ checkSyntax ["Mutual1.hs"]
|
||||
res `shouldSatisfy` ("Module imports form a cycle" `isInfixOf`)
|
||||
|
||||
it "can check a module using QuasiQuotes" $ do
|
||||
withDirectory_ "test/data" $ do
|
||||
cradle <- findCradleWithoutSandbox
|
||||
res <- checkSyntax defaultOptions cradle ["Baz.hs"]
|
||||
res <- runID $ checkSyntax ["Baz.hs"]
|
||||
res `shouldSatisfy` ("Baz.hs:5:1:Warning:" `isPrefixOf`)
|
||||
|
||||
context "without errors" $ do
|
||||
|
||||
34
test/TestUtils.hs
Normal file
34
test/TestUtils.hs
Normal file
@@ -0,0 +1,34 @@
|
||||
module TestUtils (
|
||||
run
|
||||
, runD
|
||||
, runI
|
||||
, runID
|
||||
, runIsolatedGhcMod
|
||||
, isolateCradle
|
||||
, module Language.Haskell.GhcMod.Monad
|
||||
, module Language.Haskell.GhcMod.Types
|
||||
) where
|
||||
|
||||
import Language.Haskell.GhcMod.Monad
|
||||
import Language.Haskell.GhcMod.Types
|
||||
|
||||
isolateCradle :: GhcMod a -> GhcMod a
|
||||
isolateCradle action =
|
||||
local modifyEnv $ action
|
||||
where
|
||||
modifyEnv e = e { gmCradle = (gmCradle e) { cradlePkgDbStack = [GlobalDb] } }
|
||||
|
||||
runIsolatedGhcMod :: Options -> GhcMod a -> IO a
|
||||
runIsolatedGhcMod opt action = runGhcMod opt $ isolateCradle action
|
||||
|
||||
-- | Run GhcMod in isolated cradle with default options
|
||||
runID = runIsolatedGhcMod defaultOptions
|
||||
|
||||
-- | Run GhcMod in isolated cradle
|
||||
runI = runIsolatedGhcMod
|
||||
|
||||
-- | Run GhcMod
|
||||
run = runGhcMod
|
||||
|
||||
-- | Run GhcMod with default options
|
||||
runD = runGhcMod defaultOptions
|
||||
Reference in New Issue
Block a user