Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

Commit

Permalink
Add tests for modules, check, type and info with an Explicit project
Browse files Browse the repository at this point in the history
  • Loading branch information
alang9 committed Sep 18, 2015
1 parent b2422a7 commit a092a19
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Language/Haskell/GhcMod/Cradle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ findCradle' dir = run $

findSpecCradle :: (IOish m, GmOut m) => FilePath -> m Cradle
findSpecCradle dir = do
let cfs = [stackCradleSpec, cabalCradle, sandboxCradle]
let cfs = [stackCradleSpec, cabalCradle, sandboxCradle, explicitCradle]
cs <- catMaybes <$> mapM (runMaybeT . ($ dir)) cfs
gcs <- filterM isNotGmCradle cs
fillTempDir =<< case gcs of
Expand Down
10 changes: 10 additions & 0 deletions test/CheckSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,13 @@ spec = do
#else
res `shouldBe` "NiceQualification.hs:4:8:Couldn't match expected type `IO ()' with actual type `[Char]'\NULIn the expression: \"wrong type\"\NULIn an equation for `main': main = \"wrong type\"\n"
#endif

it "works with explicit options" $ do
withDirectory_ "test/data/options-cradle" $ do
res <- runD $ checkSyntax ["src/Main.hs"]
res `shouldBe` ""

it "emits error with explicit options" $ do
withDirectory_ "test/data/options-cradle" $ do
res <- runD $ checkSyntax ["src/Main2.hs"]
res `shouldBe` "src/Main2.hs:10:11:Couldn't match expected type \8216Int\8217 with actual type \8216a0 -> a0\8217\NULProbable cause: \8216id\8217 is applied to too few arguments\NULIn the second argument of \8216(+)\8217, namely \8216id\8217\NULIn the expression: 0 + id\n"
9 changes: 9 additions & 0 deletions test/InfoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ spec = do
res <- runD' tdir $ types "ImportsTH.hs" 3 8
res `shouldBe` unlines ["3 8 3 16 \"String -> IO ()\"", "3 8 3 20 \"IO ()\"", "3 1 3 20 \"IO ()\""]

it "works with a module in Explicit project type" $ do
let tdir = "test/data/options-cradle"
res <- runD' tdir $ types "src/Main.hs" 7 10
res `shouldBe` unlines ["7 8 7 14 \"() -> IO ()\"\n7 8 7 17 \"IO ()\"\n7 1 7 17 \"IO ()\""]

describe "info" $ do
it "works for non exported functions" $ do
let tdir = "test/data/non-exported"
Expand All @@ -41,3 +46,7 @@ spec = do
res <- runD' tdir $ info "ImportsTH.hs" $ Expression "bar"
res `shouldSatisfy` ("bar :: [Char]" `isPrefixOf`)

it "works with a module in Explicit project type" $ do
let tdir = "test/data/options-cradle"
res <- runD' tdir $ info "src/Main.hs" $ Expression "foo"
res `shouldSatisfy` ("foo :: Int" `isPrefixOf`)
7 changes: 7 additions & 0 deletions test/ListSpec.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ListSpec where

import Control.Applicative
import Dir
import Language.Haskell.GhcMod
import Test.Hspec
import TestUtils
Expand All @@ -12,3 +13,9 @@ spec = do
it "contains at least `Data.Map'" $ do
mdls <- runD $ lines <$> modules
mdls `shouldContain` ["Data.Map"]

describe "modules" $ do
it "contains at least `Main'" $ do
withDirectory_ "test/data/options-cradle" $ do
mdls <- runD $ lines <$> modules
mdls `shouldContain` ["Data.Map"]

0 comments on commit a092a19

Please sign in to comment.