Skip to content

Commit 2e829f5

Browse files
committed
Add tests for Plugin global enable via config
And a CONTRIBUTING.md, for help on running tests
1 parent 1cbe1fd commit 2e829f5

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

CONTRIBUTING.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Contributors Guide
2+
3+
## Testing
4+
5+
The tests make use of the [Tasty](https://github.com/feuerbach/tasty) test framework.
6+
7+
There are two test suites, functional tests, and wrapper tests.
8+
9+
### Testing with Cabal
10+
11+
Running all the tests
12+
13+
```bash
14+
$ cabal test
15+
```
16+
17+
Running just the functional tests
18+
19+
```bash
20+
$ cabal test func-test
21+
```
22+
23+
Running just the wrapper tests
24+
25+
```bash
26+
$ cabal test wrapper-test
27+
```
28+
29+
Running a subset of tests
30+
31+
Tasty supports providing
32+
[Patterns](https://github.com/feuerbach/tasty#patterns) as command
33+
line arguments, to select the specific tests to run.
34+
35+
```bash
36+
$ cabal test func-test --test-option "-p hlint"
37+
```
38+
39+
The above recompiles everything every time you use a different test option though.
40+
41+
An alternative is
42+
43+
```bash
44+
$ cabal run haskell-language-server:func-test -- -p "hlint enables"
45+
```

haskell-language-server.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ test-suite func-test
381381
other-modules:
382382
Command
383383
Completion
384+
Config
384385
Deferred
385386
Definition
386387
Diagnostic

test/functional/Config.hs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
3+
module Config (tests) where
4+
5+
import Control.Lens hiding (List)
6+
import Control.Monad.IO.Class
7+
import Data.Aeson
8+
import Data.Default
9+
import qualified Data.Map as Map
10+
import qualified Data.Text as T
11+
import Ide.Plugin.Config
12+
import Language.Haskell.LSP.Test as Test
13+
import Language.Haskell.LSP.Types
14+
import qualified Language.Haskell.LSP.Types.Lens as L
15+
import System.FilePath ((</>))
16+
import Test.Hls.Util
17+
import Test.Tasty
18+
import Test.Tasty.HUnit
19+
20+
{-# ANN module ("HLint: ignore Reduce duplication"::String) #-}
21+
22+
tests :: TestTree
23+
tests = testGroup "plugin config" [
24+
-- Note: because the flag is treated generically in the plugin handler, we
25+
-- do not have to test each individual plugin
26+
hlintTests
27+
]
28+
29+
hlintTests :: TestTree
30+
hlintTests = testGroup "hlint plugin enables" [
31+
32+
testCase "changing hlintOn configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do
33+
let config = def { hlintOn = True }
34+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
35+
36+
doc <- openDoc "ApplyRefact2.hs" "haskell"
37+
testHlintDiagnostics doc
38+
39+
let config' = def { hlintOn = False }
40+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config'))
41+
42+
diags' <- waitForDiagnosticsFrom doc
43+
44+
liftIO $ noHlintDiagnostics diags'
45+
46+
, testCase "changing hlint plugin configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do
47+
let config = def { hlintOn = True }
48+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
49+
50+
doc <- openDoc "ApplyRefact2.hs" "haskell"
51+
testHlintDiagnostics doc
52+
53+
let config' = pluginGlobalOn config "hlint" False
54+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config'))
55+
56+
diags' <- waitForDiagnosticsFrom doc
57+
58+
liftIO $ noHlintDiagnostics diags'
59+
60+
]
61+
where
62+
runHlintSession :: FilePath -> Session a -> IO a
63+
runHlintSession subdir =
64+
failIfSessionTimeout . runSession hlsCommand fullCaps ("test/testdata/hlint" </> subdir)
65+
66+
noHlintDiagnostics :: [Diagnostic] -> Assertion
67+
noHlintDiagnostics diags =
68+
Just "hlint" `notElem` map (^. L.source) diags @? "There are no hlint diagnostics"
69+
70+
testHlintDiagnostics doc = do
71+
diags <- waitForDiagnosticsFromSource doc "hlint"
72+
liftIO $ length diags > 0 @? "There are hlint diagnostics"
73+
74+
pluginGlobalOn :: Config -> T.Text -> Bool -> Config
75+
pluginGlobalOn config pid state = config'
76+
where
77+
pluginConfig = def { plcGlobalOn = state }
78+
config' = def { plugins = Map.insert pid pluginConfig (plugins config) }

test/functional/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Test.Tasty.Ingredients.Rerun
88
import Test.Tasty.Runners.AntXML
99

1010
import Command
11+
import Config
1112
import Completion
1213
import Deferred
1314
import Definition
@@ -37,6 +38,7 @@ main =
3738
"haskell-language-server"
3839
[ Command.tests
3940
, Completion.tests
41+
, Config.tests
4042
, Deferred.tests
4143
, Definition.tests
4244
, Diagnostic.tests

0 commit comments

Comments
 (0)