ghc-mod/test/CheckSpec.hs

44 lines
1.9 KiB
Haskell
Raw Normal View History

module CheckSpec where
import Data.List (isSuffixOf, isInfixOf, isPrefixOf)
2013-05-20 02:29:44 +00:00
import Language.Haskell.GhcMod
2013-09-21 09:37:33 +00:00
import Language.Haskell.GhcMod.Cradle
2013-03-31 14:12:34 +00:00
import System.FilePath
2013-05-20 02:29:44 +00:00
import Test.Hspec
2013-09-03 02:49:35 +00:00
import Dir
spec :: Spec
spec = do
describe "checkSyntax" $ do
it "can check even if an executable depends on its library" $ do
2013-03-05 01:22:33 +00:00
withDirectory_ "test/data/ghc-mod-check" $ do
2013-09-21 09:37:33 +00:00
cradle <- findCradleWithoutSandbox
res <- checkSyntax defaultOptions cradle ["main.hs"]
2014-03-26 05:49:37 +00:00
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
2013-09-21 09:37:33 +00:00
cradle <- findCradleWithoutSandbox
res <- checkSyntax defaultOptions cradle ["test/Bar/Baz.hs"]
2014-03-26 05:49:37 +00:00
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
2013-09-21 09:37:33 +00:00
cradle <- findCradleWithoutSandbox
res <- checkSyntax defaultOptions cradle ["Mutual1.hs"]
res `shouldSatisfy` ("Module imports form a cycle" `isInfixOf`)
it "can check a module using QuasiQuotes" $ do
withDirectory_ "test/data" $ do
2013-09-21 09:37:33 +00:00
cradle <- findCradleWithoutSandbox
res <- checkSyntax defaultOptions cradle ["Baz.hs"]
res `shouldSatisfy` ("Baz.hs:5:1:Warning:" `isPrefixOf`)
2014-05-10 15:25:44 +00:00
context "without errors" $ do
it "doesn't output empty line" $ do
withDirectory_ "test/data/ghc-mod-check/Data" $ do
cradle <- findCradleWithoutSandbox
res <- checkSyntax defaultOptions cradle ["Foo.hs"]
res `shouldBe` ""