ghc-mod/test/CheckSpec.hs

70 lines
3.0 KiB
Haskell
Raw Normal View History

{-# LANGUAGE CPP #-}
module CheckSpec where
2013-05-20 02:29:44 +00:00
import Language.Haskell.GhcMod
2015-03-05 15:50:06 +00:00
import Data.List
import System.Process
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
2015-02-07 15:41:15 +00:00
res <- runD $ 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"
2015-03-04 20:48:21 +00:00
it "works even if a module imports another module from a different directory" $ do
withDirectory_ "test/data/check-test-subdir" $ do
2015-03-05 15:50:06 +00:00
_ <- system "cabal configure --enable-tests"
2015-02-07 15:41:15 +00:00
res <- runD $ 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
2015-03-04 20:48:21 +00:00
withDirectory_ "test/data/import-cycle" $ do
2015-02-07 15:41:15 +00:00
res <- runD $ checkSyntax ["Mutual1.hs"]
res `shouldSatisfy` ("Module imports form a cycle" `isInfixOf`)
it "works with modules using QuasiQuotes" $ do
2015-03-04 20:48:21 +00:00
withDirectory_ "test/data/quasi-quotes" $ do
res <- runD $ checkSyntax ["QuasiQuotes.hs"]
res `shouldSatisfy` ("QuasiQuotes.hs:6:1:Warning:" `isInfixOf`)
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
2015-02-07 15:41:15 +00:00
res <- runD $ checkSyntax ["B.hs"]
2014-09-12 01:48:22 +00:00
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
2015-03-04 20:48:21 +00:00
withDirectory_ "test/data/foreign-export" $ do
2015-02-07 15:41:15 +00:00
res <- runD $ checkSyntax ["ForeignExport.hs"]
2014-08-12 07:37:05 +00:00
res `shouldBe` ""
context "when no errors are found" $ do
it "doesn't output an empty line" $ do
2015-03-04 20:48:21 +00:00
withDirectory_ "test/data/ghc-mod-check/lib/Data" $ do
2015-02-07 15:41:15 +00:00
res <- runD $ checkSyntax ["Foo.hs"]
2014-05-10 15:25:44 +00:00
res `shouldBe` ""
#if __GLASGOW_HASKELL__ >= 708
-- See https://github.com/kazu-yamamoto/ghc-mod/issues/507
it "emits warnings generated in GHC's desugar stage" $ do
withDirectory_ "test/data/check-missing-warnings" $ do
res <- runD $ checkSyntax ["DesugarWarnings.hs"]
2015-08-05 04:15:44 +00:00
res `shouldBe` "DesugarWarnings.hs:4:9:Warning: Pattern match(es) are non-exhaustive\NULIn a case alternative: Patterns not matched: _ : _\n"
#endif
it "works with cabal builtin preprocessors" $ do
withDirectory_ "test/data/cabal-preprocessors" $ do
_ <- system "cabal clean"
_ <- system "cabal build"
res <- runD $ checkSyntax ["Main.hs"]
res `shouldBe` "Preprocessed.hsc:3:1:Warning: Top-level binding with no type signature: warning :: ()\n"