Skip to content

Commit cc67943

Browse files
authored
Merge pull request #293 from alanz/merge-lsp-test
Merge lsp-test into lsp repo
2 parents 28830a5 + 5753049 commit cc67943

File tree

36 files changed

+3378
-11
lines changed

36 files changed

+3378
-11
lines changed

.github/workflows/haskell.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
ghc: ['8.10.2', '8.8.3', '8.6.5', '8.4.4']
12+
ghc: ['8.10.4', '8.8.3', '8.6.5', '8.4.4']
1313
os: [ubuntu-latest, macOS-latest, windows-latest]
1414
exclude:
1515
- os: windows-latest
1616
ghc: '8.8.3' # fails due to segfault
1717

1818
steps:
1919
- uses: actions/checkout@v2
20-
- uses: actions/setup-haskell@v1
20+
- uses: haskell/actions/setup@v1
2121
with:
2222
ghc-version: ${{ matrix.ghc }}
2323
cabal-version: '3.2'
@@ -38,5 +38,7 @@ jobs:
3838
run: cabal build
3939
- name: Test
4040
run: cabal test
41-
- name: Func tests
42-
run: cabal run func-test
41+
- name: Func test
42+
run: cabal test func-test
43+
- name: Test lsp-test
44+
run: cabal test lsp-test

cabal.project

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
packages:
22
./
33
./lsp-types/
4-
./func-test
4+
./lsp-test/
5+
./lsp-test/example
6+
./func-test/
57
./bench/
68

79
package lsp
810
flags: +demo
911

10-
source-repository-package
11-
type: git
12-
location: https://github.com/bubba/lsp-test.git
13-
tag: 55ae6885312a90117aab35acdfc470790f30cfca
14-
1512
tests: True
1613
test-show-details: direct
14+
haddock-quickjump: True

hie.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
# https://github.com/digital-asset/ghcide/issues/113
88
cradle:
99
cabal:
10+
- path: "./lsp-test/test"
11+
component: "lsp-test:test:tests"
12+
- path: "./lsp-test"
13+
component: "lsp-test"
1014
- path: "./lsp-types"
1115
component: "lsp-types"
1216
- path: "./src"

lsp-test/.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.stack-work
2+
stack.yaml.lock
3+
dist
4+
.cabal-sandbox
5+
cabal.sandbox.config
6+
dist-newstyle
7+
cabal.project.local*
8+
.ghc.environment.*
9+
**/.DS_Store
10+
*.swp
11+
12+
example/dist
13+
example/dist-newstyle
14+
example/cabal.project.local
15+
example/.ghc.environment.*
16+
17+
# used for rerunning failed hspec tests
18+
.hspec-failures
19+
20+
# downloaded by .download-hie.sh on travis
21+
hie
22+
.hie

lsp-test/ChangeLog.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Revision history for lsp-test
2+
3+
## 0.13.0.0 -- 2021-02-14
4+
5+
* Add support for lsp-types-1.1 (@wz1000)
6+
* Automatically respond to `workspace/applyEdit` and
7+
`window/workDoneProgress/create` messages (@wz1000)
8+
9+
## 0.12.0.0 -- 2021-01-25
10+
* Add `getIncompleteProgressSessions` to track ongoing progress sessions
11+
(@wz1000)
12+
13+
## 0.11.0.0 -- 2020-05-14
14+
15+
* Replace `openDoc'` with `createDoc` which now sends
16+
`workspace/didChangeWatchedFiles` notifications if the server has registered
17+
for it
18+
* Add `getRegisteredCapabilities`
19+
20+
## 0.10.3.0 -- 2020-05-04
21+
22+
* Build with new haskell-lsp-0.22
23+
24+
## 0.10.2.0 -- 2020-03-21
25+
26+
* Bump constraints for new haskell-lsp
27+
28+
## 0.10.1.0 -- 2020-02-04
29+
30+
* Bump constraints for new haskell-lsp
31+
32+
## 0.10.0.0 -- 2019-12-29
33+
34+
* Account for messages received between the initialize request and response.
35+
(Though it will throw an exception if the message received is an illegal one)
36+
37+
## 0.9.0.0 -- 2019-12-1
38+
39+
* Add `ignoreLogNotifications` config option
40+
* Add ability to override `logStdErr` and `logMessages` config options with
41+
the `LSP_TEST_LOG_STDERR` and `LOG_TEST_LOG_MESSAGES` environment variables
42+
* Update for haskell-lsp-0.19.0.0 (@mpickering)
43+
44+
## 0.8.2.0 -- 2019-11-17
45+
46+
* Expose `satisfyMaybe` (@cocreature)
47+
48+
## 0.8.1.0 -- 2019-11-17
49+
50+
* Update to haskell-lsp-0.18.0.0 (@mpickering, @alanz)
51+
* Tests now require hie-bios based hie
52+
53+
## 0.8.0.0 -- 2019-10-18
54+
55+
* Make `Session` a newtype
56+
* Update for haskell-lsp-0.17.0.0 (@cocreature)
57+
58+
## 0.7.0.0 -- 2019-09-08
59+
60+
* Update for haskell-lsp-0.16.0.0
61+
62+
## 0.6.1.0 -- 2019-08-24
63+
64+
* Add `satisfyMaybe` (@cocreature)
65+
66+
## 0.6.0.0 -- 2019-07-04
67+
68+
* Update to haskell-lsp-0.15.0.0 (@lorenzo)
69+
70+
## 0.5.4.0 -- 2019-06-13
71+
72+
* Fix `getDefinitions` for SingleLoc (@cocreature)
73+
* Add `getCodeLenses` (@cocreature)
74+
75+
## 0.5.3.0 -- 2019-06-13
76+
77+
* Update to haskell-lsp-0.14.0.0 (@cocreature)
78+
* Support `TextDocumentDidChange` (@cocreature)
79+
* Add non-file based `openDoc` (@cocreature)
80+
81+
## 0.5.2.0 -- 2019-04-28
82+
83+
* Add `satisfy` parser combinator
84+
85+
## 0.5.1.0 -- 2019-04-22
86+
87+
* Fix unhandled `window/progress` server notifications
88+
89+
## 0.5.1.0 -- 2019-04-07
90+
91+
* Add getTypeDefinitions (@fendor)
92+
93+
## 0.5.0.2 -- 2018-12-05
94+
95+
* Fix loose threads when exceptions are thrown
96+
97+
## 0.5.0.0 -- 2018-11-13
98+
99+
* Add lspConfig option in config
100+
* GHC 8.6.2 support
101+
102+
## 0.4.0.0 -- 2018-09-08
103+
104+
* Update to haskell-lsp-0.8.0.0
105+
106+
## 0.3.0.0 -- 2018-09-0t
107+
108+
* Update to haskell-lsp-0.7.0.0
109+
110+
## 0.2.1.0 -- 2018-08-14
111+
112+
* Add getCodeActions
113+
* Add getCurrentDiagnostics
114+
115+
## 0.2.0.0 -- 2018-08-06
116+
117+
* Update to haskell-lsp 0.6.0.0

lsp-test/LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Copyright Luke Lau 2018-2020.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above
11+
copyright notice, this list of conditions and the following
12+
disclaimer in the documentation and/or other materials provided
13+
with the distribution.
14+
15+
* Neither the name of Luke Lau nor the names of other
16+
contributors may be used to endorse or promote products derived
17+
from this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

lsp-test/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# lsp-test [![Actions Status](https://github.com/bubba/lsp-test/workflows/Haskell%20CI/badge.svg)](https://github.com/bubba/lsp-test/actions) [![Hackage](https://img.shields.io/hackage/v/lsp-test.svg)](https://hackage.haskell.org/package/lsp-test)
2+
lsp-test is a functional testing framework for Language Server Protocol servers.
3+
4+
```haskell
5+
import Language.LSP.Test
6+
main = runSession "hie" fullCaps "proj/dir" $ do
7+
doc <- openDoc "Foo.hs" "haskell"
8+
skipMany anyNotification
9+
symbols <- getDocumentSymbols doc
10+
```
11+
12+
## Examples
13+
14+
### Unit tests with HSpec
15+
```haskell
16+
describe "diagnostics" $
17+
it "report errors" $ runSession "hie" fullCaps "test/data" $ do
18+
openDoc "Error.hs" "haskell"
19+
[diag] <- waitForDiagnosticsSource "ghcmod"
20+
liftIO $ do
21+
diag ^. severity `shouldBe` Just DsError
22+
diag ^. source `shouldBe` Just "ghcmod"
23+
```
24+
25+
### Replaying captured session
26+
```haskell
27+
replaySession "hie" "test/data/renamePass"
28+
```
29+
30+
### Parsing with combinators
31+
```haskell
32+
skipManyTill loggingNotification publishDiagnosticsNotification
33+
count 4 (message :: Session ApplyWorkspaceEditRequest)
34+
anyRequest <|> anyResponse
35+
```
36+
37+
Try out the example tests in the `example` directory with `cabal test`.
38+
For more examples check the [Wiki](https://github.com/bubba/lsp-test/wiki/Introduction), or see this [introductory blog post](https://lukelau.me/haskell/posts/lsp-test/).
39+
40+
Whilst writing your tests you may want to debug them to see what's going wrong.
41+
You can set the `logMessages` and `logStdErr` options in `SessionConfig` to see what the server is up to.
42+
There are also corresponding environment variables so you can turn them on from the command line:
43+
```
44+
LSP_TEST_LOG_MESSAGES=1 LSP_TEST_LOG_STDERR=1 cabal test
45+
```
46+
47+
## Developing
48+
The tests for lsp-test use a dummy server found in `test/dummy-server/`.
49+
Run the tests with `cabal test` or `stack test`.
50+
Tip: If you want to filter the tests, use `cabal run test:tests -- -m "foo"`
51+
52+
## Troubleshooting
53+
Seeing funny stuff when running lsp-test via stack? If your server is built upon Haskell tooling, [keep in mind that stack sets some environment variables related to GHC, and you may want to unset them.](https://github.com/alanz/haskell-ide-engine/blob/bfb16324d396da71000ef81d51acbebbdaa854ab/test/utils/TestUtils.hs#L290-L298)

lsp-test/example/Test.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Control.Applicative.Combinators
2+
import Control.Monad.IO.Class
3+
import Language.LSP.Test
4+
import Language.LSP.Types
5+
6+
main = runSession "haskell-language-server" fullCaps "../test/data/" $ do
7+
doc <- openDoc "Rename.hs" "haskell"
8+
9+
-- Use your favourite favourite combinators.
10+
skipManyTill loggingNotification (count 2 publishDiagnosticsNotification)
11+
12+
-- Send requests and notifications and receive responses
13+
rsp <- request STextDocumentDocumentSymbol $
14+
DocumentSymbolParams Nothing Nothing doc
15+
liftIO $ print rsp
16+
17+
-- Or use one of the helper functions
18+
getDocumentSymbols doc >>= liftIO . print
19+

lsp-test/example/cabal.project

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages: .
2+
../

lsp-test/example/example.cabal

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: example
2+
version: 0.0.0.0
3+
cabal-version: >= 1.22
4+
build-type: Simple
5+
6+
test-suite tests
7+
type: exitcode-stdio-1.0
8+
main-is: Test.hs
9+
build-depends: base
10+
, lsp-test
11+
, parser-combinators

lsp-test/hie.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cradle:
2+
multi:
3+
- path: "./test/data/"
4+
config: { cradle: { none: } }
5+
- path: "./example/"
6+
config: { cradle: { none: } }
7+
- path: "./"
8+
config:
9+
cradle:
10+
cabal:
11+
- path: "src"
12+
component: "lib:lsp-test"
13+
- path: "test/dummy-server"
14+
component: "exe:dummy-server"
15+
- path: "test"
16+
component: "test:tests"

0 commit comments

Comments
 (0)