2013-02-13 06:28:29 +00:00
|
|
|
module CheckSpec where
|
|
|
|
|
2013-04-01 06:55:29 +00:00
|
|
|
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-02-13 06:28:29 +00:00
|
|
|
|
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
|
|
|
|
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
|
2013-08-21 08:21:49 +00:00
|
|
|
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"
|
2013-03-15 08:30:21 +00:00
|
|
|
|
|
|
|
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
|
2013-08-21 08:21:49 +00:00
|
|
|
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`)
|
2013-03-16 02:50:45 +00:00
|
|
|
|
|
|
|
it "can detect mutually imported modules" $ do
|
|
|
|
withDirectory_ "test/data" $ do
|
2013-09-21 09:37:33 +00:00
|
|
|
cradle <- findCradleWithoutSandbox
|
2013-08-21 08:21:49 +00:00
|
|
|
res <- checkSyntax defaultOptions cradle ["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
|
|
|
|
|
|
|
it "can check a module using QuasiQuotes" $ do
|
|
|
|
withDirectory_ "test/data" $ do
|
2013-09-21 09:37:33 +00:00
|
|
|
cradle <- findCradleWithoutSandbox
|
2013-08-21 08:21:49 +00:00
|
|
|
res <- checkSyntax defaultOptions cradle ["Baz.hs"]
|
2013-04-01 06:55:29 +00:00
|
|
|
res `shouldSatisfy` ("Baz.hs:5:1:Warning:" `isPrefixOf`)
|