Skip to content

Commit 82517c8

Browse files
committed
disable checkProject in hls-eval-plugin test suite
1 parent 822ff33 commit 82517c8

File tree

19 files changed

+41
-32
lines changed

19 files changed

+41
-32
lines changed

haskell-language-server.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ test-suite func-test
405405
, hspec-expectations
406406
, lens
407407
, ghcide
408-
, hls-test-utils ^>= 1.1.0.0
408+
, hls-test-utils ^>= 1.2.0.0
409409
, lsp-types
410410
, aeson
411411
, hls-plugin-api

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.4
22
name: hls-test-utils
3-
version: 1.1.0.0
3+
version: 1.2.0.0
44
synopsis: Utilities used in the tests of Haskell Language Server
55
description:
66
Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ import Development.IDE.Plugin.Test (TestRequest (WaitForIdeRule, W
5252
import Development.IDE.Types.Options
5353
import GHC.IO.Handle
5454
import Ide.Plugin.Config (Config, formattingProvider)
55-
import Ide.PluginUtils (idePluginsToPluginDesc, pluginDescToIdePlugins)
55+
import Ide.PluginUtils (idePluginsToPluginDesc,
56+
pluginDescToIdePlugins)
5657
import Ide.Types
5758
import Language.LSP.Test
5859
import Language.LSP.Types hiding
@@ -84,17 +85,17 @@ goldenGitDiff :: TestName -> FilePath -> IO ByteString -> TestTree
8485
goldenGitDiff name = goldenVsStringDiff name gitDiff
8586

8687
goldenWithHaskellDoc
87-
:: PluginDescriptor IdeState
88+
:: (Session ByteString -> IO ByteString)
8889
-> TestName
8990
-> FilePath
9091
-> FilePath
9192
-> FilePath
92-
-> FilePath
93+
-> String
9394
-> (TextDocumentIdentifier -> Session ())
9495
-> TestTree
95-
goldenWithHaskellDoc plugin title testDataDir path desc ext act =
96+
goldenWithHaskellDoc runSessionTest title testDataDir path desc ext act =
9697
goldenGitDiff title (testDataDir </> path <.> desc <.> ext)
97-
$ runSessionWithServer plugin testDataDir
98+
$ runSessionTest
9899
$ TL.encodeUtf8 . TL.fromStrict
99100
<$> do
100101
doc <- openDoc (path <.> ext) "haskell"
@@ -224,7 +225,7 @@ waitForAction key TextDocumentIdentifier{_uri} = do
224225
return $ do
225226
e <- _result
226227
case A.fromJSON e of
227-
A.Error err -> Left $ ResponseError InternalError (T.pack err) Nothing
228+
A.Error err -> Left $ ResponseError InternalError (T.pack err) Nothing
228229
A.Success a -> pure a
229230

230231
waitForTypecheck :: TextDocumentIdentifier -> Session (Either ResponseError Bool)

plugins/hls-brittany-plugin/hls-brittany-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ test-suite tests
4848
, base
4949
, filepath
5050
, hls-brittany-plugin
51-
, hls-test-utils >=1.0 && <1.2
51+
, hls-test-utils >=1.0 && <1.3

plugins/hls-call-hierarchy-plugin/hls-call-hierarchy-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test-suite tests
5555
, extra
5656
, filepath
5757
, hls-call-hierarchy-plugin
58-
, hls-test-utils >=1.0 && <1.2
58+
, hls-test-utils >=1.0 && <1.3
5959
, lens
6060
, lsp
6161
, lsp-test

plugins/hls-class-plugin/hls-class-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ test-suite tests
5353
, base
5454
, filepath
5555
, hls-class-plugin
56-
, hls-test-utils >=1.0 && <1.2
56+
, hls-test-utils >=1.0 && <1.3
5757
, lens
5858
, lsp-types

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ test-suite tests
106106
, extra
107107
, filepath
108108
, hls-eval-plugin
109-
, hls-test-utils ^>=1.1
109+
, hls-plugin-api
110+
, hls-test-utils ^>=1.2
110111
, lens
111112
, lsp-types
112113
, text

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import Data.Aeson (fromJSON)
1212
import Data.Aeson.Types (Result (Success))
1313
import Data.List (isInfixOf)
1414
import Data.List.Extra (nubOrdOn)
15+
import qualified Data.Text as T
16+
import Ide.Plugin.Config (checkProject)
1517
import qualified Ide.Plugin.Eval as Eval
1618
import Ide.Plugin.Eval.Types (EvalParams (..), Section (..),
1719
testOutput)
1820
import Language.LSP.Types.Lens (arguments, command, range, title)
1921
import System.FilePath ((</>))
2022
import Test.Hls
21-
import qualified Data.Text as T
2223

2324
main :: IO ()
2425
main = defaultTestRunner tests
@@ -30,27 +31,27 @@ tests :: TestTree
3031
tests =
3132
testGroup "eval"
3233
[ testCase "Produces Evaluate code lenses" $
33-
runSessionWithServer evalPlugin testDataDir $ do
34+
runS evalPlugin testDataDir $ do
3435
doc <- openDoc "T1.hs" "haskell"
3536
lenses <- getCodeLenses doc
3637
liftIO $ map (preview $ command . _Just . title) lenses @?= [Just "Evaluate..."]
3738
, testCase "Produces Refresh code lenses" $
38-
runSessionWithServer evalPlugin testDataDir $ do
39+
runS evalPlugin testDataDir $ do
3940
doc <- openDoc "T2.hs" "haskell"
4041
lenses <- getCodeLenses doc
4142
liftIO $ map (preview $ command . _Just . title) lenses @?= [Just "Refresh..."]
4243
, testCase "Code lenses have ranges" $
43-
runSessionWithServer evalPlugin testDataDir $ do
44+
runS evalPlugin testDataDir $ do
4445
doc <- openDoc "T1.hs" "haskell"
4546
lenses <- getCodeLenses doc
4647
liftIO $ map (view range) lenses @?= [Range (Position 4 0) (Position 5 0)]
4748
, testCase "Multi-line expressions have a multi-line range" $ do
48-
runSessionWithServer evalPlugin testDataDir $ do
49+
runS evalPlugin testDataDir $ do
4950
doc <- openDoc "T3.hs" "haskell"
5051
lenses <- getCodeLenses doc
5152
liftIO $ map (view range) lenses @?= [Range (Position 3 0) (Position 5 0)]
5253
, testCase "Executed expressions range covers only the expression" $ do
53-
runSessionWithServer evalPlugin testDataDir $ do
54+
runS evalPlugin testDataDir $ do
5455
doc <- openDoc "T2.hs" "haskell"
5556
lenses <- getCodeLenses doc
5657
liftIO $ map (view range) lenses @?= [Range (Position 4 0) (Position 5 0)]
@@ -181,7 +182,7 @@ tests =
181182

182183
goldenWithEval :: TestName -> FilePath -> FilePath -> TestTree
183184
goldenWithEval title path ext =
184-
goldenWithHaskellDoc evalPlugin title testDataDir path "expected" ext executeLensesBackwards
185+
goldenWithHaskellDoc (runS evalPlugin testDataDir) title testDataDir path "expected" ext executeLensesBackwards
185186

186187
-- | Execute lenses backwards, to avoid affecting their position in the source file
187188
executeLensesBackwards :: TextDocumentIdentifier -> Session ()
@@ -208,7 +209,7 @@ executeCmd cmd = do
208209
pure ()
209210

210211
evalLenses :: FilePath -> IO [CodeLens]
211-
evalLenses path = runSessionWithServer evalPlugin testDataDir $ do
212+
evalLenses path = runS evalPlugin testDataDir $ do
212213
doc <- openDoc path "haskell"
213214
executeLensesBackwards doc
214215
getCodeLenses doc
@@ -225,11 +226,17 @@ testDataDir :: FilePath
225226
testDataDir = "test" </> "testdata"
226227

227228
evalInFile :: FilePath -> T.Text -> T.Text -> IO ()
228-
evalInFile fp e expected = runSessionWithServer evalPlugin testDataDir $ do
229+
evalInFile fp e expected = runS evalPlugin testDataDir $ do
229230
doc <- openDoc fp "haskell"
230231
origin <- documentContents doc
231232
let withEval = origin <> e
232233
changeDoc doc [TextDocumentContentChangeEvent Nothing Nothing withEval]
233234
executeLensesBackwards doc
234235
result <- fmap T.strip . T.stripPrefix withEval <$> documentContents doc
235236
liftIO $ result @?= Just (T.strip expected)
237+
238+
-- Run with checkProject false to avoid loading all the test data modules,
239+
-- which leads to flaky test failures due to how the Eval plugin mutates
240+
-- the shared GHC session (this is because of how the InteractiveContext works)
241+
runS :: PluginDescriptor IdeState -> FilePath -> Session a -> IO a
242+
runS plugin = runSessionWithServer' [plugin] def{checkProject = False} def fullCaps

plugins/hls-floskell-plugin/hls-floskell-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ test-suite tests
4040
, base
4141
, filepath
4242
, hls-floskell-plugin
43-
, hls-test-utils >=1.0 && <1.2
43+
, hls-test-utils >=1.0 && <1.3

plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ test-suite tests
4444
, base
4545
, filepath
4646
, hls-fourmolu-plugin
47-
, hls-test-utils >=1.0 && <1.2
47+
, hls-test-utils >=1.0 && <1.3
4848
, lsp-test

plugins/hls-haddock-comments-plugin/hls-haddock-comments-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ test-suite tests
5050
, base
5151
, filepath
5252
, hls-haddock-comments-plugin
53-
, hls-test-utils >=1.0 && <1.2
53+
, hls-test-utils >=1.0 && <1.3
5454
, text

plugins/hls-hlint-plugin/hls-hlint-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ test-suite tests
122122
, filepath
123123
, hls-hlint-plugin
124124
, hls-plugin-api
125-
, hls-test-utils >=1.0 && <1.2
125+
, hls-test-utils >=1.0 && <1.3
126126
, lens
127127
, lsp-types
128128
, text

plugins/hls-module-name-plugin/hls-module-name-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ test-suite tests
4444
, base
4545
, filepath
4646
, hls-module-name-plugin
47-
, hls-test-utils >=1.0 && <1.2
47+
, hls-test-utils >=1.0 && <1.3

plugins/hls-ormolu-plugin/hls-ormolu-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ test-suite tests
4343
, base
4444
, filepath
4545
, hls-ormolu-plugin
46-
, hls-test-utils >=1.0 && <1.2
46+
, hls-test-utils >=1.0 && <1.3
4747
, lsp-types

plugins/hls-pragmas-plugin/hls-pragmas-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test-suite tests
4444
, base
4545
, filepath
4646
, hls-pragmas-plugin
47-
, hls-test-utils >=1.0 && <1.2
47+
, hls-test-utils >=1.0 && <1.3
4848
, lens
4949
, lsp-types
5050
, text

plugins/hls-rename-plugin/hls-rename-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ test-suite tests
4747
, base
4848
, filepath
4949
, hls-rename-plugin
50-
, hls-test-utils >=1.0 && <1.2
50+
, hls-test-utils >=1.0 && <1.3

plugins/hls-splice-plugin/hls-splice-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ test-suite tests
6464
, base
6565
, filepath
6666
, hls-splice-plugin
67-
, hls-test-utils >=1.0 && <1.2
67+
, hls-test-utils >=1.0 && <1.3
6868
, text

plugins/hls-stylish-haskell-plugin/hls-stylish-haskell-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ test-suite tests
4242
, base
4343
, filepath
4444
, hls-stylish-haskell-plugin
45-
, hls-test-utils >=1.0 && <1.2
45+
, hls-test-utils >=1.0 && <1.3

plugins/hls-tactics-plugin/hls-tactics-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ test-suite tests
160160
, ghcide
161161
, hls-plugin-api
162162
, hls-tactics-plugin
163-
, hls-test-utils >=1.0 && <1.2
163+
, hls-test-utils >=1.0 && <1.3
164164
, hspec
165165
, hspec-expectations
166166
, lens

0 commit comments

Comments
 (0)