ghc-mod/test/CheckSpec.hs

52 lines
2.1 KiB
Haskell
Raw Normal View History

{-# LANGUAGE CPP #-}
module CheckSpec where
import Data.List (isSuffixOf, isInfixOf, isPrefixOf)
2013-05-20 02:29:44 +00:00
import Language.Haskell.GhcMod
2013-03-31 14:12:34 +00:00
import System.FilePath
2013-05-20 02:29:44 +00:00
import Test.Hspec
2014-05-10 13:10:34 +00:00
import TestUtils
2013-09-03 02:49:35 +00:00
import Dir
spec :: Spec
spec = do
describe "checkSyntax" $ do
it "works even if an executable depends on the library defined in the same cabal file" $ do
2013-03-05 01:22:33 +00:00
withDirectory_ "test/data/ghc-mod-check" $ do
2014-05-10 13:10:34 +00:00
res <- runID $ checkSyntax ["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 "works even if a module imports another module from a different directory" $ do
withDirectory_ "test/data/check-test-subdir" $ do
2014-05-10 13:10:34 +00:00
res <- runID $ checkSyntax ["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 "detects cyclic imports" $ do
withDirectory_ "test/data" $ do
2014-05-10 13:10:34 +00:00
res <- runID $ checkSyntax ["Mutual1.hs"]
res `shouldSatisfy` ("Module imports form a cycle" `isInfixOf`)
it "works with modules using QuasiQuotes" $ do
withDirectory_ "test/data" $ do
2014-05-10 13:10:34 +00:00
res <- runID $ checkSyntax ["Baz.hs"]
res `shouldSatisfy` ("Baz.hs:5:1:Warning:" `isPrefixOf`)
2014-05-10 15:25:44 +00:00
#if __GLASGOW_HASKELL__ >= 708
2014-09-12 01:48:22 +00:00
it "works with modules using PatternSynonyms" $ do
withDirectory_ "test/data/pattern-synonyms" $ do
res <- runID $ checkSyntax ["B.hs"]
res `shouldSatisfy` ("B.hs:6:9:Warning:" `isPrefixOf`)
#endif
2014-09-12 01:48:22 +00:00
2014-08-12 07:37:05 +00:00
it "works with foreign exports" $ do
withDirectory_ "test/data" $ do
res <- runID $ checkSyntax ["ForeignExport.hs"]
res `shouldBe` ""
context "when no errors are found" $ do
it "doesn't output an empty line" $ do
2014-05-10 15:25:44 +00:00
withDirectory_ "test/data/ghc-mod-check/Data" $ do
2014-05-14 16:05:40 +00:00
res <- runID $ checkSyntax ["Foo.hs"]
2014-05-10 15:25:44 +00:00
res `shouldBe` ""