Skip to content

Commit 08ba3b4

Browse files
committed
Fix redundant import tests
These tests were underspecified and broke with the recent improvements to ghcide diagnostics in haskell/ghcide#959 and included in this merge. Fixed by waiting specifically for the typecheck diagnostics and by being less prescriptive in the number and order of code actions
1 parent 8a7c6f6 commit 08ba3b4

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

haskell-language-server.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ test-suite func-test
395395
build-depends:
396396
, bytestring
397397
, data-default
398+
, hspec-expectations
398399
, lens
399400
, tasty
400401
, tasty-ant-xml >=1.1.6

test/functional/FunctionalCodeAction.hs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import Language.Haskell.LSP.Types
1919
import qualified Language.Haskell.LSP.Types.Lens as L
2020
import qualified Language.Haskell.LSP.Types.Capabilities as C
2121
import Test.Hls.Util
22+
import Test.Hspec.Expectations
23+
2224
import Test.Tasty
2325
import Test.Tasty.ExpectedFailure (ignoreTestBecause, expectFailBecause)
2426
import Test.Tasty.HUnit
@@ -293,17 +295,19 @@ redundantImportTests = testGroup "redundant import code actions" [
293295
runSession hlsCommand fullCaps "test/testdata/redundantImportTest/" $ do
294296
doc <- openDoc "src/CodeActionRedundant.hs" "haskell"
295297

296-
diags <- waitForDiagnosticsFrom doc
298+
diags <- waitForDiagnosticsFromSource doc "typecheck"
297299
liftIO $ expectDiagnostic diags ["The import of", "Data.List", "is redundant"]
298300

299301
mActions <- getAllCodeActions doc
300302

301-
let allActions@[removeAction, removeAllAction, makeAllExplicitAction] = map fromAction mActions
303+
let allActions = map fromAction mActions
304+
actionTitles = map (view L.title) allActions
305+
306+
liftIO $ actionTitles `shouldContain` ["Remove import", "Remove all redundant imports"]
307+
308+
let Just removeAction = find (\x -> x ^. L.title == "Remove import") allActions
302309

303310
liftIO $ do
304-
removeAction ^. L.title @?= "Remove import"
305-
removeAllAction ^. L.title @?= "Remove all redundant imports"
306-
makeAllExplicitAction ^. L.title @?= "Make all imports explicit"
307311
forM_ allActions $ \a -> a ^. L.kind @?= Just CodeActionQuickFix
308312
forM_ allActions $ \a -> a ^. L.command @?= Nothing
309313
forM_ allActions $ \a -> isJust (a ^. L.edit) @? "Has edit"
@@ -318,7 +322,7 @@ redundantImportTests = testGroup "redundant import code actions" [
318322

319323
, testCase "doesn't touch other imports" $ runSession hlsCommand noLiteralCaps "test/testdata/redundantImportTest/" $ do
320324
doc <- openDoc "src/MultipleImports.hs" "haskell"
321-
_ <- waitForDiagnosticsFrom doc
325+
_ <- waitForDiagnosticsFromSource doc "typecheck"
322326
CACommand cmd : _ <- getAllCodeActions doc
323327
executeCommand cmd
324328
contents <- documentContents doc

0 commit comments

Comments
 (0)