Fix tests, move option records to Types module

This commit is contained in:
Nikolay Yakimov 2015-12-06 00:56:19 +03:00
parent ad16b739eb
commit b2fb54a356
8 changed files with 30 additions and 23 deletions

View File

@ -14,6 +14,7 @@ import qualified GHC as G
import Language.Haskell.GhcMod.Convert import Language.Haskell.GhcMod.Convert
import Language.Haskell.GhcMod.Doc (showPage, styleUnqualified) import Language.Haskell.GhcMod.Doc (showPage, styleUnqualified)
import Language.Haskell.GhcMod.Gap as Gap import Language.Haskell.GhcMod.Gap as Gap
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Monad import Language.Haskell.GhcMod.Monad
import Language.Haskell.GhcMod.Logging import Language.Haskell.GhcMod.Logging
import Name (getOccString) import Name (getOccString)
@ -25,12 +26,6 @@ import Prelude
---------------------------------------------------------------- ----------------------------------------------------------------
data BrowseOpts = BrowseOpts {
optBrowseOperators :: Bool
, optBrowseDetailed :: Bool
, optBrowseQualified :: Bool
}
-- | Getting functions, classes, etc from a module. -- | Getting functions, classes, etc from a module.
-- If 'detailed' is 'True', their types are also obtained. -- If 'detailed' is 'True', their types are also obtained.
-- If 'operators' is 'True', operators are also returned. -- If 'operators' is 'True', operators are also returned.

View File

@ -4,6 +4,7 @@ import Exception (ghandle)
import Control.Exception (SomeException(..)) import Control.Exception (SomeException(..))
import Language.Haskell.GhcMod.Logger (checkErrorPrefix) import Language.Haskell.GhcMod.Logger (checkErrorPrefix)
import Language.Haskell.GhcMod.Convert import Language.Haskell.GhcMod.Convert
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Monad import Language.Haskell.GhcMod.Monad
import Language.Haskell.HLint (hlint) import Language.Haskell.HLint (hlint)
@ -11,8 +12,6 @@ import Language.Haskell.GhcMod.Utils (withMappedFile)
import Data.List (stripPrefix) import Data.List (stripPrefix)
data LintOpts = LintOpts { optLintHlintOpts :: [String] }
-- | Checking syntax of a target file using hlint. -- | Checking syntax of a target file using hlint.
-- Warnings and errors are returned. -- Warnings and errors are returned.
lint :: IOish m lint :: IOish m

View File

@ -373,6 +373,20 @@ instance Binary ChEntrypoint where
put = ggput . from put = ggput . from
get = to `fmap` ggget get = to `fmap` ggget
data LintOpts = LintOpts { optLintHlintOpts :: [String] }
defaultLintOpts :: LintOpts
defaultLintOpts = LintOpts []
data BrowseOpts = BrowseOpts {
optBrowseOperators :: Bool
, optBrowseDetailed :: Bool
, optBrowseQualified :: Bool
}
defaultBrowseOpts :: BrowseOpts
defaultBrowseOpts = BrowseOpts False False False
mkLabel ''GhcModCaches mkLabel ''GhcModCaches
mkLabel ''GhcModState mkLabel ''GhcModState
mkLabel ''Options mkLabel ''Options

View File

@ -2,8 +2,7 @@ module GHCMod.Options.Commands where
import Options.Applicative import Options.Applicative
import Options.Applicative.Types import Options.Applicative.Types
import Language.Haskell.GhcMod.Lint (LintOpts(..)) import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Browse (BrowseOpts(..))
import Text.Read (readMaybe) import Text.Read (readMaybe)
import GHCMod.Options.DocUtils import GHCMod.Options.DocUtils

View File

@ -12,23 +12,23 @@ spec :: Spec
spec = do spec = do
describe "browse Data.Map" $ do describe "browse Data.Map" $ do
it "contains at least `differenceWithKey'" $ do it "contains at least `differenceWithKey'" $ do
syms <- runD $ lines <$> browse "Data.Map" syms <- runD $ lines <$> browse defaultBrowseOpts "Data.Map"
syms `shouldContain` ["differenceWithKey"] syms `shouldContain` ["differenceWithKey"]
describe "browse -d Data.Either" $ do describe "browse -d Data.Either" $ do
it "contains functions (e.g. `either') including their type signature" $ do it "contains functions (e.g. `either') including their type signature" $ do
syms <- run defaultOptions { optDetailed = True } syms <- runD
$ lines <$> browse "Data.Either" $ lines <$> browse defaultBrowseOpts{ optBrowseDetailed = True } "Data.Either"
syms `shouldContain` ["either :: (a -> c) -> (b -> c) -> Either a b -> c"] syms `shouldContain` ["either :: (a -> c) -> (b -> c) -> Either a b -> c"]
it "contains type constructors (e.g. `Left') including their type signature" $ do it "contains type constructors (e.g. `Left') including their type signature" $ do
syms <- run defaultOptions { optDetailed = True} syms <- runD
$ lines <$> browse "Data.Either" $ lines <$> browse defaultBrowseOpts{ optBrowseDetailed = True } "Data.Either"
syms `shouldContain` ["Left :: a -> Either a b"] syms `shouldContain` ["Left :: a -> Either a b"]
describe "`browse' in a project directory" $ do describe "`browse' in a project directory" $ do
it "can list symbols defined in a a local module" $ do it "can list symbols defined in a a local module" $ do
withDirectory_ "test/data/ghc-mod-check/" $ do withDirectory_ "test/data/ghc-mod-check/" $ do
syms <- runD $ lines <$> browse "Data.Foo" syms <- runD $ lines <$> browse defaultBrowseOpts "Data.Foo"
syms `shouldContain` ["foo"] syms `shouldContain` ["foo"]
syms `shouldContain` ["fibonacci"] syms `shouldContain` ["fibonacci"]

View File

@ -122,13 +122,13 @@ spec = do
withDirectory_ "test/data/file-mapping" $ do withDirectory_ "test/data/file-mapping" $ do
res <- runD $ do res <- runD $ do
loadMappedFile "File.hs" "File_Redir_Lint.hs" loadMappedFile "File.hs" "File_Redir_Lint.hs"
lint "File.hs" lint defaultLintOpts "File.hs"
res `shouldBe` "File.hs:4:1: Error: Eta reduce\NULFound:\NUL func a b = (*) a b\NULWhy not:\NUL func = (*)\n" res `shouldBe` "File.hs:4:1: Error: Eta reduce\NULFound:\NUL func a b = (*) a b\NULWhy not:\NUL func = (*)\n"
it "lints in-memory file if one is specified and outputs original filename" $ do it "lints in-memory file if one is specified and outputs original filename" $ do
withDirectory_ "test/data/file-mapping" $ do withDirectory_ "test/data/file-mapping" $ do
res <- runD $ do res <- runD $ do
loadMappedFileSource "File.hs" "func a b = (++) a b\n" loadMappedFileSource "File.hs" "func a b = (++) a b\n"
lint "File.hs" lint defaultLintOpts "File.hs"
res `shouldBe` "File.hs:1:1: Error: Eta reduce\NULFound:\NUL func a b = (++) a b\NULWhy not:\NUL func = (++)\n" res `shouldBe` "File.hs:1:1: Error: Eta reduce\NULFound:\NUL func a b = (++) a b\NULWhy not:\NUL func = (++)\n"
it "shows types of the expression for redirected files" $ do it "shows types of the expression for redirected files" $ do
let tdir = "test/data/file-mapping" let tdir = "test/data/file-mapping"
@ -183,14 +183,14 @@ spec = do
withDirectory_ "test/data/file-mapping/preprocessor" $ do withDirectory_ "test/data/file-mapping/preprocessor" $ do
res <- runD $ do res <- runD $ do
loadMappedFile "File.hs" "File_Redir_Lint.hs" loadMappedFile "File.hs" "File_Redir_Lint.hs"
lint "File.hs" lint defaultLintOpts "File.hs"
res `shouldBe` "File.hs:6:1: Error: Eta reduce\NULFound:\NUL func a b = (*) a b\NULWhy not:\NUL func = (*)\n" res `shouldBe` "File.hs:6:1: Error: Eta reduce\NULFound:\NUL func a b = (*) a b\NULWhy not:\NUL func = (*)\n"
it "lints in-memory file if one is specified and outputs original filename" $ do it "lints in-memory file if one is specified and outputs original filename" $ do
withDirectory_ "test/data/file-mapping/preprocessor" $ do withDirectory_ "test/data/file-mapping/preprocessor" $ do
src <- readFile "File_Redir_Lint.hs" src <- readFile "File_Redir_Lint.hs"
res <- runD $ do res <- runD $ do
loadMappedFileSource "File.hs" src loadMappedFileSource "File.hs" src
lint "File.hs" lint defaultLintOpts "File.hs"
res `shouldBe` "File.hs:6:1: Error: Eta reduce\NULFound:\NUL func a b = (*) a b\NULWhy not:\NUL func = (*)\n" res `shouldBe` "File.hs:6:1: Error: Eta reduce\NULFound:\NUL func a b = (*) a b\NULWhy not:\NUL func = (*)\n"
describe "literate haskell tests" $ do describe "literate haskell tests" $ do
it "checks redirected file if one is specified and outputs original filename" $ do it "checks redirected file if one is specified and outputs original filename" $ do

View File

@ -8,10 +8,10 @@ spec :: Spec
spec = do spec = do
describe "lint" $ do describe "lint" $ do
it "can detect a redundant import" $ do it "can detect a redundant import" $ do
res <- runD $ lint "test/data/hlint/hlint.hs" res <- runD $ lint defaultLintOpts "test/data/hlint/hlint.hs"
res `shouldBe` "test/data/hlint/hlint.hs:4:8: Error: Redundant do\NULFound:\NUL do putStrLn \"Hello, world!\"\NULWhy not:\NUL putStrLn \"Hello, world!\"\n" res `shouldBe` "test/data/hlint/hlint.hs:4:8: Error: Redundant do\NULFound:\NUL do putStrLn \"Hello, world!\"\NULWhy not:\NUL putStrLn \"Hello, world!\"\n"
context "when no suggestions are given" $ do context "when no suggestions are given" $ do
it "doesn't output an empty line" $ do it "doesn't output an empty line" $ do
res <- runD $ lint "test/data/ghc-mod-check/lib/Data/Foo.hs" res <- runD $ lint defaultLintOpts "test/data/ghc-mod-check/lib/Data/Foo.hs"
res `shouldBe` "" res `shouldBe` ""

View File

@ -10,5 +10,5 @@ spec :: Spec
spec = do spec = do
describe "modules" $ do describe "modules" $ do
it "contains at least `Data.Map'" $ do it "contains at least `Data.Map'" $ do
mdls <- runD $ lines <$> modules mdls <- runD $ lines <$> modules False
mdls `shouldContain` ["Data.Map"] mdls `shouldContain` ["Data.Map"]