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

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasgwaaler committed Nov 25, 2015
1 parent eb32bf6 commit e9cea16
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 2 deletions.
1 change: 1 addition & 0 deletions haskell-ide-engine.cabal
Expand Up @@ -97,6 +97,7 @@ test-suite haskell-ide-test
HaRePluginSpec
JsonStdioSpec
JsonSpec
PluginUtilsSpec
build-depends: base
, aeson
, containers
Expand Down
3 changes: 2 additions & 1 deletion hie-plugin-api/Haskell/Ide/Engine/PluginUtils.hs
Expand Up @@ -11,6 +11,7 @@ module Haskell.Ide.Engine.PluginUtils
, incorrectParameter
, validatePlugins
, PluginDescriptionError(..)
, ParamNameCollision
) where

import Data.Aeson
Expand Down Expand Up @@ -93,7 +94,7 @@ data PluginDescriptionError =
PluginDescriptionError {
paramNameCollisions :: [ParamNameCollision]
, paramNameCollisionErrorMsg :: String
} deriving Eq
} deriving (Eq, Show)

validatePlugins :: Plugins -> Maybe PluginDescriptionError
validatePlugins plugins =
Expand Down
2 changes: 1 addition & 1 deletion test/DispatcherSpec.hs
Expand Up @@ -40,7 +40,7 @@ dispatcherSpec :: Spec
dispatcherSpec = do
describe "checking plugins on startup" $ do

it "exits on parameter name collisions" $ do
it "exits with an error if any command has a parameter name collision" $ do
runIdeM (IdeState testPluginWithParamNameCollison) undefined `shouldThrow` anyErrorCall

-- ---------------------------------
Expand Down
148 changes: 148 additions & 0 deletions test/PluginUtilsSpec.hs
Expand Up @@ -23,6 +23,154 @@ pluginUtilsSpec = do
it "accepts plugins without parameter name collisions" $ do
validatePlugins pluginsWithoutCollisions `shouldBe` Nothing

it "reports collisions for plugins with parameter name collisions" $ do
fmap paramNameCollisions (validatePlugins pluginsWithCollisions) `shouldBe` Just
[
("plugin1",
[
("cmd1", ["file"])
, ("cmd2", ["end_pos"])
, ("cmd3", ["a", "a", "b"])
]
)
, ("plugin2",
[
("cmd1", ["file"])
]
)
]


it "pretty prints the error message" $ do
fmap paramNameCollisionErrorMsg (validatePlugins pluginsWithCollisions) `shouldBe` Just (
"In plugin \"plugin1\" the command \"cmd1\" has multiple parameters named \"file\"" ++
"\nIn plugin \"plugin1\" the command \"cmd2\" has multiple parameters named \"end_pos\"" ++
"\nIn plugin \"plugin1\" the command \"cmd3\" has multiple parameters named \"a\", \"b\"" ++
"\nIn plugin \"plugin2\" the command \"cmd1\" has multiple parameters named \"file\""
)


pluginsWithCollisions :: Plugins
pluginsWithCollisions = Map.fromList [("plugin1", PluginDescriptor
{
pdCommands =
[
Command
{ cmdDesc = CommandDesc
{ cmdName = "cmd1"
, cmdUiDescription = ""
, cmdFileExtensions = []
, cmdContexts = [CtxRegion, CtxPoint] -- ["file", "start_pos", "file", "start_pos", "end_pos"]
, cmdAdditionalParams =
[
RP
{ pName = "file"
, pHelp = "shoud collide"
, pType = PtText
}
, RP
{ pName = "uniqueParamName1"
, pHelp = "shoud not collide"
, pType = PtText
}
]
}
, cmdFunc = CmdSync $ \_ _ -> return (IdeResponseOk ("" :: T.Text))
}
, Command
{ cmdDesc = CommandDesc
{ cmdName = "cmd2"
, cmdUiDescription = ""
, cmdFileExtensions = []
, cmdContexts = [CtxRegion]
, cmdAdditionalParams =
[
RP
{ pName = "end_pos"
, pHelp = "shoud collide"
, pType = PtText
}
, OP
{ pName = "uniqueParamName1"
, pHelp = "shoud not collide"
, pType = PtText
}
]
}
, cmdFunc = CmdSync $ \_ _ -> return (IdeResponseOk ("" :: T.Text))
}
, Command
{ cmdDesc = CommandDesc
{ cmdName = "cmd3"
, cmdUiDescription = ""
, cmdFileExtensions = []
, cmdContexts = [] -- ["file", "start_pos", "file", "start_pos", "end_pos"]
, cmdAdditionalParams =
[
RP
{ pName = "a"
, pHelp = "shoud collide"
, pType = PtText
}
, OP
{ pName = "a"
, pHelp = "shoud collide"
, pType = PtText
}
, OP
{ pName = "a"
, pHelp = "shoud collide"
, pType = PtText
}
, RP
{ pName = "b"
, pHelp = "shoud collide"
, pType = PtText
}
, RP
{ pName = "b"
, pHelp = "shoud collide"
, pType = PtText
}
]
}
, cmdFunc = CmdSync $ \_ _ -> return (IdeResponseOk ("" :: T.Text))
}
]
, pdExposedServices = []
, pdUsedServices = []
})
, ("plugin2", PluginDescriptor
{
pdCommands =
[
Command
{ cmdDesc = CommandDesc
{ cmdName = "cmd1"
, cmdUiDescription = ""
, cmdFileExtensions = []
, cmdContexts = [CtxRegion, CtxPoint] -- ["file", "start_pos", "file", "start_pos", "end_pos"]
, cmdAdditionalParams =
[
RP
{ pName = "file"
, pHelp = "shoud collide"
, pType = PtText
}
, RP
{ pName = "uniqueParamName1"
, pHelp = "shoud not collide"
, pType = PtText
}
]
}
, cmdFunc = CmdSync $ \_ _ -> return (IdeResponseOk ("" :: T.Text))
}
]
, pdExposedServices = []
, pdUsedServices = []
})
]


pluginsWithoutCollisions :: Plugins
Expand Down

0 comments on commit e9cea16

Please sign in to comment.