2013-02-13 06:28:29 +00:00
|
|
|
module CheckSpec where
|
|
|
|
|
2013-03-04 09:11:09 +00:00
|
|
|
import CabalApi
|
2013-02-13 06:28:29 +00:00
|
|
|
import Check
|
2013-03-02 07:14:55 +00:00
|
|
|
import Cradle
|
2013-03-16 02:50:45 +00:00
|
|
|
import Data.List (isSuffixOf, isInfixOf)
|
2013-02-13 06:28:29 +00:00
|
|
|
import Expectation
|
2013-03-02 07:14:55 +00:00
|
|
|
import Test.Hspec
|
2013-02-13 06:28:29 +00:00
|
|
|
import Types
|
2013-03-31 14:12:34 +00:00
|
|
|
import System.FilePath
|
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-03-04 09:11:09 +00:00
|
|
|
(strVer,_) <- getGHCVersion
|
|
|
|
cradle <- findCradle Nothing strVer
|
2013-03-02 07:14:55 +00:00
|
|
|
res <- checkSyntax defaultOptions cradle "main.hs"
|
2013-02-13 07:04:22 +00:00
|
|
|
res `shouldBe` "main.hs:5:1:Warning: Top-level binding with no type signature: main :: IO ()\NUL\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
|
|
|
|
cradle <- getGHCVersion >>= findCradle Nothing . fst
|
|
|
|
res <- checkSyntax defaultOptions cradle "test/Bar/Baz.hs"
|
2013-03-31 14:12:34 +00:00
|
|
|
res `shouldSatisfy` (("test" </> "Foo.hs:3:1:Warning: Top-level binding with no type signature: foo :: [Char]\NUL\n") `isSuffixOf`)
|
2013-03-16 02:50:45 +00:00
|
|
|
|
|
|
|
it "can detect mutually imported modules" $ do
|
|
|
|
withDirectory_ "test/data" $ do
|
|
|
|
(strVer,_) <- getGHCVersion
|
|
|
|
cradle <- findCradle Nothing strVer
|
|
|
|
res <- checkSyntax defaultOptions cradle "Mutual1.hs"
|
|
|
|
res `shouldSatisfy` ("Module imports form a cycle" `isInfixOf`)
|