2014-09-12 04:13:04 +00:00
{- # LANGUAGE CPP # -}
2013-02-13 06:28:29 +00:00
module CheckSpec where
2017-01-12 15:36:47 +00:00
import 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 ` " "
2015-08-05 02:05:43 +00:00
2015-08-10 06:15:34 +00:00
# if __GLASGOW_HASKELL__ >= 708
-- See https://github.com/kazu-yamamoto/ghc-mod/issues/507
2015-08-05 02:05:43 +00:00
it " emits warnings generated in GHC's desugar stage " $ do
withDirectory_ " test/data/check-missing-warnings " $ do
res <- runD $ checkSyntax [ " DesugarWarnings.hs " ]
2016-05-22 00:55:06 +00:00
res ` shouldSatisfy ` ( " DesugarWarnings.hs:4:9:Warning: Pattern match(es) are non-exhaustive \ NUL In a case alternative: Patterns not matched: " ` isPrefixOf ` )
2015-08-10 06:15:34 +00:00
# endif
2015-08-10 03:14:31 +00:00
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 "
2015-08-18 05:41:08 +00:00
it " Uses the right qualification style " $ do
withDirectory_ " test/data/nice-qualification " $ do
res <- runD $ checkSyntax [ " NiceQualification.hs " ]
2016-05-22 00:55:06 +00:00
# if __GLASGOW_HASKELL__ >= 800
res ` shouldBe ` " NiceQualification.hs:4:8: \ 8226 Couldn't match expected type \ 8216 IO () \ 8217 with actual type \ 8216 [Char] \ 8217 \ NUL \ 8226 In the expression: \ " wrong type \ " \ NUL In an equation for \ 8216 main \ 8217 : main = \ " wrong type \ " \ n "
# elif __GLASGOW_HASKELL__ >= 708
2015-08-18 05:41:08 +00:00
res ` shouldBe ` " NiceQualification.hs:4:8:Couldn't match expected type \ 8216 IO () \ 8217 with actual type \ 8216 [Char] \ 8217 \ NUL In the expression: \ " wrong type \ " \ NUL In an equation for \ 8216 main \ 8217 : main = \ " wrong type \ " \ n "
2015-08-19 06:11:29 +00:00
# else
res ` shouldBe ` " NiceQualification.hs:4:8:Couldn't match expected type `IO ()' with actual type `[Char]' \ NUL In the expression: \ " wrong type \ " \ NUL In an equation for `main': main = \ " wrong type \ " \ n "
# endif