2014-09-12 04:13:04 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
2013-02-13 06:28:29 +00:00
|
|
|
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
|
2013-02-13 06:28:29 +00:00
|
|
|
|
2014-05-10 13:10:34 +00:00
|
|
|
import TestUtils
|
2013-09-03 02:49:35 +00:00
|
|
|
import Dir
|
|
|
|
|
2013-02-13 06:28:29 +00:00
|
|
|
spec :: Spec
|
|
|
|
spec = do
|
|
|
|
describe "checkSyntax" $ do
|
2014-07-11 01:10:37 +00:00
|
|
|
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"
|
2013-03-15 08:30:21 +00:00
|
|
|
|
2015-03-04 20:48:21 +00:00
|
|
|
|
2014-07-11 01:10:37 +00:00
|
|
|
it "works even if a module imports another module from a different directory" $ do
|
2013-03-15 08:30:21 +00:00
|
|
|
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`)
|
2013-03-16 02:50:45 +00:00
|
|
|
|
2014-07-11 01:10:37 +00:00
|
|
|
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"]
|
2013-03-16 02:50:45 +00:00
|
|
|
res `shouldSatisfy` ("Module imports form a cycle" `isInfixOf`)
|
2013-04-01 06:55:29 +00:00
|
|
|
|
2014-07-11 01:10:37 +00:00
|
|
|
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
|
|
|
|
2014-09-12 04:13:04 +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`)
|
2014-09-12 04:13:04 +00:00
|
|
|
#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` ""
|
|
|
|
|
2014-07-11 01:10:37 +00:00
|
|
|
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` ""
|