Skip to content

Commit df67bee

Browse files
Migrate tests of plugins (#1612)
* Class plugin * Splice plugin, extract hlsCommand from hls-test-utils * Haddock comments plugin * Update github actions * Remove invalid import * Bump up specification version of package description to 2.4 * Fix hls.cabal * Remove the build of eval plugin's testdata from circle ci * Limit the parallelism of building test suites in circle ci Co-authored-by: Pepe Iborra <pepeiborra@gmail.com>
1 parent 0cf081d commit df67bee

File tree

103 files changed

+345
-171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+345
-171
lines changed

.circleci/config.yml

+1-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ defaults: &defaults
3838

3939
- run:
4040
name: Build Testsuite without running it
41-
command: stack --stack-yaml=${STACK_FILE} build --test --no-run-tests
41+
command: stack -j 1 --stack-yaml=${STACK_FILE} build --test --no-run-tests
4242
no_output_timeout: 30m
4343

4444
- store_artifacts:
@@ -52,14 +52,6 @@ defaults: &defaults
5252
- ~/build/.stack-work
5353
- ~/build/ghcide/.stack-work
5454

55-
- run:
56-
name: Setup stack eval hie.html
57-
command: cp plugins/hls-eval-plugin/test/testdata/hie-stack.yaml plugins/hls-eval-plugin/test/testdata/hie.yaml
58-
59-
- run:
60-
name: Setup stack eval stack.html
61-
command: grep '^resolver:\|^compiler:' stack-build.txt > plugins/hls-eval-plugin/test/testdata/stack.yaml
62-
6355
- run:
6456
name: Build including tests
6557
command: stack --stack-yaml=${STACK_FILE} test --no-run-tests

.github/workflows/test.yml

+19-16
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,30 @@ jobs:
131131
# instances to be spun up for the poor github actions runner to handle
132132
run: cabal test wrapper-test --test-options="-j1" || cabal test wrapper-test --test-options="-j1" || cabal test wrapper-test --test-options="-j1"
133133

134-
- name: Test hls-tactics-plugin test suite
134+
- name: Test hls-brittany-plugin
135135
if: ${{ matrix.test }}
136-
run: LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-tactics-plugin --test-options="-j1"
136+
run: cabal test hls-brittany-plugin || cabal test hls-brittany-plugin --test-options="-j1"
137137

138-
- name: Test brittany plugin
138+
- name: Test hls-class-plugin
139139
if: ${{ matrix.test }}
140-
env:
141-
HLS_TEST_EXE: hls
142-
HLS_WRAPPER_TEST_EXE: hls-wrapper
143-
run: cabal test hls-brittany-plugin || cabal test hls-brittany-plugin --test-options="-j1"
140+
run: cabal test hls-class-plugin || cabal test hls-class-plugin --test-options="-j1"
144141

145-
- name: Test stylish-haskell plugin
142+
- name: Test hls-eval-plugin
143+
if: ${{ matrix.test }}
144+
run: cabal test hls-eval-plugin --test-options="-j1 --rerun" || cabal test hls-eval-plugin --test-options="-j1 --rerun"
145+
146+
- name: Test hls-haddock-comments-plugin
147+
if: ${{ matrix.test }}
148+
run: cabal test hls-haddock-comments-plugin || cabal test hls-haddock-comments-plugin --test-options="-j1"
149+
150+
- name: Test hls-splice-plugin
151+
if: ${{ matrix.test }}
152+
run: cabal test hls-splice-plugin || cabal test hls-splice-plugin --test-options="-j1"
153+
154+
- name: Test hls-stylish-haskell-plugin
146155
if: ${{ matrix.test }}
147-
env:
148-
HLS_TEST_EXE: hls
149-
HLS_WRAPPER_TEST_EXE: hls-wrapper
150156
run: cabal test hls-stylish-haskell-plugin || cabal test hls-stylish-haskell-plugin --test-options="-j1"
151157

152-
- name: Test eval plugin
158+
- name: Test hls-tactics-plugin test suite
153159
if: ${{ matrix.test }}
154-
env:
155-
HLS_TEST_EXE: hls
156-
HLS_WRAPPER_TEST_EXE: hls-wrapper
157-
run: cabal test hls-eval-plugin || cabal test hls-eval-plugin --test-options="-j1"
160+
run: LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-tactics-plugin --test-options="-j1"

haskell-language-server.cabal

+2-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ extra-source-files:
2727
test/testdata/**/*.h
2828
test/testdata/**/*.hs
2929
test/testdata/**/*.expected
30-
test/testdata/**/*.error
3130

3231
flag pedantic
3332
description: Enable -Werror
@@ -394,11 +393,10 @@ test-suite func-test
394393
, containers
395394
, unordered-containers
396395

397-
hs-source-dirs: test/functional plugins/hls-splice-plugin/src
396+
hs-source-dirs: test/functional test/utils
398397

399398
main-is: Main.hs
400399
other-modules:
401-
Class
402400
Command
403401
Completion
404402
Config
@@ -417,9 +415,7 @@ test-suite func-test
417415
Rename
418416
Symbol
419417
TypeDefinition
420-
Splice
421-
HaddockComments
422-
Ide.Plugin.Splice.Types
418+
Test.Hls.Command
423419

424420
default-extensions: OverloadedStrings
425421
ghc-options:

hls-plugin-api/hls-plugin-api.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cabal-version: 2.2
1+
cabal-version: 2.4
22
name: hls-plugin-api
33
version: 1.1.0.0
44
synopsis: Haskell Language Server API for plugin communication

hls-test-utils/hls-test-utils.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cabal-version: 2.2
1+
cabal-version: 2.4
22
name: hls-test-utils
33
version: 1.0.0.0
44
synopsis: Utilities used in the tests of Haskell Language Server

hls-test-utils/src/Test/Hls/Util.hs

-25
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ module Test.Hls.Util
1515
, ghcVersion, GhcVersion(..)
1616
, hostOS, OS(..)
1717
, matchesCurrentEnv, EnvSpec(..)
18-
, hlsCommand
19-
, hlsCommandExamplePlugin
20-
, hlsCommandVomit
2118
, ignoreForGhcVersions
2219
, ignoreInEnv
2320
, inspectCodeAction
@@ -26,7 +23,6 @@ module Test.Hls.Util
2623
, knownBrokenOnWindows
2724
, knownBrokenForGhcVersions
2825
, knownBrokenInEnv
29-
, logFilePath
3026
, setupBuildToolFiles
3127
, SymbolLocation
3228
, waitForDiagnosticsFrom
@@ -57,7 +53,6 @@ import System.Environment
5753
import System.Time.Extra (Seconds, sleep)
5854
import System.FilePath
5955
import System.IO.Temp
60-
import System.IO.Unsafe
6156
import Test.Hspec.Runner
6257
import Test.Hspec.Core.Formatters hiding (Seconds)
6358
import Test.Tasty (TestTree)
@@ -164,26 +159,6 @@ ignoreForGhcVersions vers reason
164159
| ghcVersion `elem` vers = ignoreTestBecause reason
165160
| otherwise = id
166161

167-
logFilePath :: String
168-
logFilePath = "hls-" ++ show ghcVersion ++ ".log"
169-
170-
-- | The command to execute the version of hls for the current compiler.
171-
--
172-
-- Both @stack test@ and @cabal new-test@ setup the environment so @hls@ is
173-
-- on PATH. Cabal seems to respond to @build-tool-depends@ specifically while
174-
-- stack just puts all project executables on PATH.
175-
hlsCommand :: String
176-
{-# NOINLINE hlsCommand #-}
177-
hlsCommand = unsafePerformIO $ do
178-
testExe <- fromMaybe "haskell-language-server" <$> lookupEnv "HLS_TEST_EXE"
179-
pure $ testExe ++ " --lsp -d -j2 -l test-logs/" ++ logFilePath
180-
181-
hlsCommandVomit :: String
182-
hlsCommandVomit = hlsCommand ++ " --vomit"
183-
184-
hlsCommandExamplePlugin :: String
185-
hlsCommandExamplePlugin = hlsCommand ++ " --example"
186-
187162
-- ---------------------------------------------------------------------
188163

189164
hieYamlCradleDirectContents :: String
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
cabal-version: 2.2
1+
cabal-version: 2.4
22
name: hls-class-plugin
33
version: 1.0.0.0
4-
synopsis: Class/instance management plugin for Haskell Language Server
4+
synopsis:
5+
Class/instance management plugin for Haskell Language Server
6+
57
description:
6-
Class/instance management plugin for Haskell Language Server.
7-
For usage, please see README of HLS on GitHub at <https://github.com/haskell/haskell-language-server#readme>
8+
Class/instance management plugin for Haskell Language Server.
9+
For usage, please see README of HLS on GitHub at <https://github.com/haskell/haskell-language-server#readme>
10+
811
license: Apache-2.0
912
license-file: LICENSE
1013
author: Junyoung Clare Jang
@@ -13,24 +16,60 @@ homepage: https://github.com/haskell/haskell-language-server#readme
1316
bug-reports: https://github.com/haskell/haskell-language-server/issues
1417
category: Development
1518
build-type: Simple
19+
extra-source-files:
20+
LICENSE
21+
test/testdata/*.hs
1622

1723
library
18-
exposed-modules: Ide.Plugin.Class
19-
hs-source-dirs: src
20-
build-depends: aeson
21-
, base >=4.12 && <5
22-
, containers
23-
, lsp
24-
, hls-plugin-api >= 1.0 && < 1.2
25-
, ghc
26-
, ghc-exactprint
27-
, ghcide ^>= 1.1.0.0
28-
, lens
29-
, shake
30-
, text
31-
, transformers
32-
, unordered-containers
24+
exposed-modules: Ide.Plugin.Class
25+
hs-source-dirs: src
26+
build-depends:
27+
, aeson
28+
, base >=4.12 && <5
29+
, containers
30+
, ghc
31+
, ghc-exactprint
32+
, ghcide ^>=1.1.0.0
33+
, hls-plugin-api >=1.0 && <1.2
34+
, lens
35+
, lsp
36+
, shake
37+
, text
38+
, transformers
39+
, unordered-containers
40+
41+
default-language: Haskell2010
42+
default-extensions:
43+
DataKinds
44+
TypeOperators
3345

46+
ghc-options: -Wno-unticked-promoted-constructors
47+
48+
executable test-server
3449
default-language: Haskell2010
35-
default-extensions: DataKinds, TypeOperators
36-
ghc-options: -Wno-unticked-promoted-constructors
50+
build-depends:
51+
, base
52+
, data-default
53+
, ghcide
54+
, hls-class-plugin
55+
, hls-plugin-api
56+
57+
main-is: Server.hs
58+
hs-source-dirs: test
59+
ghc-options: -threaded
60+
61+
test-suite tests
62+
type: exitcode-stdio-1.0
63+
default-language: Haskell2010
64+
build-tool-depends: hls-class-plugin:test-server -any
65+
hs-source-dirs: test
66+
main-is: Main.hs
67+
build-depends:
68+
, base
69+
, bytestring
70+
, filepath
71+
, hls-test-utils
72+
, lens
73+
, lsp-test
74+
, lsp-types
75+
, text

test/functional/Class.hs renamed to plugins/hls-class-plugin/test/Main.hs

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
{-# LANGUAGE OverloadedStrings #-}
33
{-# LANGUAGE ScopedTypeVariables #-}
44
{-# LANGUAGE TypeOperators #-}
5-
module Class
6-
( tests
5+
module Main
6+
( main
77
)
88
where
99

@@ -14,19 +14,21 @@ import qualified Language.LSP.Types.Lens as J
1414
import System.FilePath
1515
import Test.Hls
1616

17+
main :: IO ()
18+
main = defaultTestRunner tests
19+
1720
tests :: TestTree
1821
tests = testGroup
1922
"class"
2023
[ testCase "Produces addMinimalMethodPlaceholders code actions for one instance" $ do
21-
runSession hlsCommand fullCaps classPath $ do
24+
runSession testCommand fullCaps classPath $ do
2225
doc <- openDoc "T1.hs" "haskell"
2326
_ <- waitForDiagnosticsFromSource doc "typecheck"
2427
caResults <- getAllCodeActions doc
2528
liftIO $ map (^? _CACodeAction . J.title) caResults
2629
@?=
2730
[ Just "Add placeholders for '=='"
2831
, Just "Add placeholders for '/='"
29-
, Just "Disable \"missing-methods\" warnings"
3032
]
3133
, glodenTest "Creates a placeholder for '=='" "T1" "eq"
3234
$ \(eqAction:_) -> do
@@ -54,12 +56,12 @@ _CACodeAction = prism' InR $ \case
5456
_ -> Nothing
5557

5658
classPath :: FilePath
57-
classPath = "test" </> "testdata" </> "class"
59+
classPath = "test" </> "testdata"
5860

5961
glodenTest :: String -> FilePath -> FilePath -> ([CodeAction] -> Session ()) -> TestTree
6062
glodenTest name fp deco execute
6163
= goldenGitDiff name (classPath </> fpWithDeco <.> "expected" <.> "hs")
62-
$ runSession hlsCommand fullCaps classPath
64+
$ runSession testCommand fullCaps classPath
6365
$ do
6466
doc <- openDoc (fp <.> "hs") "haskell"
6567
_ <- waitForDiagnosticsFromSource doc "typecheck"
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
{-# LANGUAGE OverloadedStrings #-}
3+
module Main(main) where
4+
5+
import Data.Default
6+
import Development.IDE.Main
7+
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
8+
import qualified Ide.Plugin.Class as Class
9+
import Ide.Plugin.Config
10+
import Ide.PluginUtils
11+
12+
main :: IO ()
13+
main = defaultMain def
14+
{ argsHlsPlugins = pluginDescToIdePlugins $
15+
[ Class.descriptor "class"
16+
] <>
17+
Ghcide.descriptors
18+
}

plugins/hls-eval-plugin/hls-eval-plugin.cabal

-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ test-suite tests
111111
build-tool-depends: hls-eval-plugin:test-server -any
112112
hs-source-dirs: test
113113
main-is: Main.hs
114-
ghc-options: -Wunused-packages
115114

116115
build-depends:
117116
, aeson

plugins/hls-eval-plugin/test/Main.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,4 @@ replaceUnicodeQuotes :: T.Text -> T.Text
213213
replaceUnicodeQuotes = T.replace "" "'" . T.replace "" "'"
214214

215215
evalPath :: FilePath
216-
evalPath = "test/testdata"
216+
evalPath = "test" </> "testdata"

plugins/hls-eval-plugin/test/testdata/hie-cabal.yaml

-4
This file was deleted.

plugins/hls-eval-plugin/test/testdata/hie-stack.yaml

-4
This file was deleted.

plugins/hls-eval-plugin/test/testdata/stack.yaml

-4
This file was deleted.

0 commit comments

Comments
 (0)