Skip to content

Commit

Permalink
Fix redundant import tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pepeiborra committed Dec 29, 2020
1 parent ecfa1c8 commit 052c310
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ test-suite func-test
build-depends:
, bytestring
, data-default
, hspec-expectations
, lens
, tasty
, tasty-ant-xml >=1.1.6
Expand Down
16 changes: 10 additions & 6 deletions test/functional/FunctionalCodeAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import Language.Haskell.LSP.Types
import qualified Language.Haskell.LSP.Types.Lens as L
import qualified Language.Haskell.LSP.Types.Capabilities as C
import Test.Hls.Util
import Test.Hspec.Expectations

import Test.Tasty
import Test.Tasty.ExpectedFailure (ignoreTestBecause, expectFailBecause)
import Test.Tasty.HUnit
Expand Down Expand Up @@ -293,17 +295,19 @@ redundantImportTests = testGroup "redundant import code actions" [
runSession hlsCommand fullCaps "test/testdata/redundantImportTest/" $ do
doc <- openDoc "src/CodeActionRedundant.hs" "haskell"

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

mActions <- getAllCodeActions doc

let allActions@[removeAction, removeAllAction, makeAllExplicitAction] = map fromAction mActions
let allActions = map fromAction mActions
actionTitles = map (view L.title) allActions

liftIO $ actionTitles `shouldContain` ["Remove import", "Remove all redundant imports"]

let Just removeAction = find (\x -> x ^. L.title == "Remove import") allActions

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

, testCase "doesn't touch other imports" $ runSession hlsCommand noLiteralCaps "test/testdata/redundantImportTest/" $ do
doc <- openDoc "src/MultipleImports.hs" "haskell"
_ <- waitForDiagnosticsFrom doc
_ <- waitForDiagnosticsFromSource doc "typecheck"
CACommand cmd : _ <- getAllCodeActions doc
executeCommand cmd
contents <- documentContents doc
Expand Down

0 comments on commit 052c310

Please sign in to comment.