2014-09-12 06:13:04 +02:00
|
|
|
{-# LANGUAGE CPP #-}
|
2013-02-13 15:28:29 +09:00
|
|
|
module CheckSpec where
|
|
|
|
|
|
2013-05-20 11:29:44 +09:00
|
|
|
import Language.Haskell.GhcMod
|
2015-03-05 16:50:06 +01:00
|
|
|
|
|
|
|
|
import Data.List
|
|
|
|
|
import System.Process
|
2013-05-20 11:29:44 +09:00
|
|
|
import Test.Hspec
|
2013-02-13 15:28:29 +09:00
|
|
|
|
2014-05-10 15:10:34 +02:00
|
|
|
import TestUtils
|
2013-09-03 11:49:35 +09:00
|
|
|
import Dir
|
|
|
|
|
|
2013-02-13 15:28:29 +09:00
|
|
|
spec :: Spec
|
|
|
|
|
spec = do
|
|
|
|
|
describe "checkSyntax" $ do
|
2014-07-11 03:10:37 +02:00
|
|
|
it "works even if an executable depends on the library defined in the same cabal file" $ do
|
2013-03-05 10:22:33 +09:00
|
|
|
withDirectory_ "test/data/ghc-mod-check" $ do
|
2015-02-07 16:41:15 +01:00
|
|
|
res <- runD $ checkSyntax ["main.hs"]
|
2014-03-26 14:49:37 +09:00
|
|
|
res `shouldBe` "main.hs:5:1:Warning: Top-level binding with no type signature: main :: IO ()\n"
|
2013-03-15 17:30:21 +09:00
|
|
|
|
2015-03-04 21:48:21 +01:00
|
|
|
|
2014-07-11 03:10:37 +02:00
|
|
|
it "works even if a module imports another module from a different directory" $ do
|
2013-03-15 17:30:21 +09:00
|
|
|
withDirectory_ "test/data/check-test-subdir" $ do
|
2015-03-05 16:50:06 +01:00
|
|
|
_ <- system "cabal configure --enable-tests"
|
2015-02-07 16:41:15 +01:00
|
|
|
res <- runD $ checkSyntax ["test/Bar/Baz.hs"]
|
2014-03-26 14:49:37 +09:00
|
|
|
res `shouldSatisfy` (("test" </> "Foo.hs:3:1:Warning: Top-level binding with no type signature: foo :: [Char]\n") `isSuffixOf`)
|
2013-03-16 11:50:45 +09:00
|
|
|
|
2014-07-11 03:10:37 +02:00
|
|
|
it "detects cyclic imports" $ do
|
2015-03-04 21:48:21 +01:00
|
|
|
withDirectory_ "test/data/import-cycle" $ do
|
2015-02-07 16:41:15 +01:00
|
|
|
res <- runD $ checkSyntax ["Mutual1.hs"]
|
2013-03-16 11:50:45 +09:00
|
|
|
res `shouldSatisfy` ("Module imports form a cycle" `isInfixOf`)
|
2013-04-01 15:55:29 +09:00
|
|
|
|
2014-07-11 03:10:37 +02:00
|
|
|
it "works with modules using QuasiQuotes" $ do
|
2015-03-04 21:48:21 +01:00
|
|
|
withDirectory_ "test/data/quasi-quotes" $ do
|
|
|
|
|
res <- runD $ checkSyntax ["QuasiQuotes.hs"]
|
|
|
|
|
res `shouldSatisfy` ("QuasiQuotes.hs:6:1:Warning:" `isInfixOf`)
|
2014-05-11 00:25:44 +09:00
|
|
|
|
2014-09-12 06:13:04 +02:00
|
|
|
#if __GLASGOW_HASKELL__ >= 708
|
2014-09-12 03:48:22 +02:00
|
|
|
it "works with modules using PatternSynonyms" $ do
|
|
|
|
|
withDirectory_ "test/data/pattern-synonyms" $ do
|
2015-02-07 16:41:15 +01:00
|
|
|
res <- runD $ checkSyntax ["B.hs"]
|
2014-09-12 03:48:22 +02:00
|
|
|
res `shouldSatisfy` ("B.hs:6:9:Warning:" `isPrefixOf`)
|
2014-09-12 06:13:04 +02:00
|
|
|
#endif
|
2014-09-12 03:48:22 +02:00
|
|
|
|
2014-08-12 16:37:05 +09:00
|
|
|
it "works with foreign exports" $ do
|
2015-03-04 21:48:21 +01:00
|
|
|
withDirectory_ "test/data/foreign-export" $ do
|
2015-02-07 16:41:15 +01:00
|
|
|
res <- runD $ checkSyntax ["ForeignExport.hs"]
|
2014-08-12 16:37:05 +09:00
|
|
|
res `shouldBe` ""
|
|
|
|
|
|
2014-07-11 03:10:37 +02:00
|
|
|
context "when no errors are found" $ do
|
|
|
|
|
it "doesn't output an empty line" $ do
|
2015-03-04 21:48:21 +01:00
|
|
|
withDirectory_ "test/data/ghc-mod-check/lib/Data" $ do
|
2015-02-07 16:41:15 +01:00
|
|
|
res <- runD $ checkSyntax ["Foo.hs"]
|
2014-05-11 00:25:44 +09:00
|
|
|
res `shouldBe` ""
|