Skip to content

Commit f36f320

Browse files
committed
Move qualified import tests to hls-refactor-plugin
1 parent 19d2b23 commit f36f320

File tree

13 files changed

+66
-99
lines changed

13 files changed

+66
-99
lines changed

haskell-language-server.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ test-suite func-test
532532
Config
533533
Format
534534
FunctionalBadProject
535-
FunctionalCodeAction
536535
HieBios
537536
Progress
538537
Test.Hls.Command

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Test.Hls.Util
2525
, knownBrokenOnWindows
2626
, knownBrokenForGhcVersions
2727
, knownBrokenInEnv
28+
, knownBrokenInSpecificEnv
2829
, onlyWorkForGhcVersions
2930
-- * Extract code actions
3031
, fromAction
@@ -123,12 +124,18 @@ hostOS
123124
| isMac = MacOS
124125
| otherwise = Linux
125126

126-
-- | Mark as broken if /any/ of environmental spec mathces the current environment.
127+
-- | Mark as broken if /any/ of the environmental specs matches the current environment.
127128
knownBrokenInEnv :: [EnvSpec] -> String -> TestTree -> TestTree
128129
knownBrokenInEnv envSpecs reason
129130
| any matchesCurrentEnv envSpecs = expectFailBecause reason
130131
| otherwise = id
131132

133+
-- | Mark as broken if /all/ environmental specs match the current environment.
134+
knownBrokenInSpecificEnv :: [EnvSpec] -> String -> TestTree -> TestTree
135+
knownBrokenInSpecificEnv envSpecs reason
136+
| all matchesCurrentEnv envSpecs = expectFailBecause reason
137+
| otherwise = id
138+
132139
knownBrokenOnWindows :: String -> TestTree -> TestTree
133140
knownBrokenOnWindows = knownBrokenInEnv [HostOS Windows]
134141

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,21 +528,43 @@ insertImportTests = testGroup "insert import"
528528
"ModuleDeclAndImports.hs"
529529
"ModuleDeclAndImports.expected.hs"
530530
"import Data.Monoid"
531+
, importQualifiedTests
532+
]
533+
534+
importQualifiedTests :: TestTree
535+
importQualifiedTests = testGroup "import qualified prefix suggestions"
536+
[ checkImport'
537+
"qualified import works with 3.8 code action kinds"
538+
"ImportQualified.hs"
539+
"ImportQualified.expected.hs"
540+
"import qualified Control.Monad as Control"
541+
["import Control.Monad (when)"]
542+
, checkImport'
543+
"qualified import in postfix position works with 3.8 code action kinds"
544+
"ImportPostQualified.hs"
545+
"ImportPostQualified.expected.hs"
546+
"import Control.Monad qualified as Control"
547+
["import qualified Control.Monad as Control", "import Control.Monad (when)"]
531548
]
532549

533550
checkImport :: String -> FilePath -> FilePath -> T.Text -> TestTree
534551
checkImport testComment originalPath expectedPath action =
552+
checkImport' testComment originalPath expectedPath action []
553+
554+
checkImport' :: String -> FilePath -> FilePath -> T.Text -> [T.Text] -> TestTree
555+
checkImport' testComment originalPath expectedPath action excludedActions =
535556
testSessionWithExtraFiles "import-placement" testComment $ \dir ->
536557
check (dir </> originalPath) (dir </> expectedPath) action
537558
where
538559
check :: FilePath -> FilePath -> T.Text -> Session ()
539560
check originalPath expectedPath action = do
540561
oSrc <- liftIO $ readFileUtf8 originalPath
541-
eSrc <- liftIO $ readFileUtf8 expectedPath
562+
eSrc <- liftIO $ readFileUtf8 expectedPath
542563
originalDoc <- createDoc originalPath "haskell" oSrc
543564
_ <- waitForDiagnostics
544565
shouldBeDoc <- createDoc expectedPath "haskell" eSrc
545566
actionsOrCommands <- getAllCodeActions originalDoc
567+
for_ excludedActions (\a -> liftIO $ assertNoActionWithTitle a actionsOrCommands)
546568
chosenAction <- liftIO $ pickActionWithTitle action actionsOrCommands
547569
executeCodeAction chosenAction
548570
originalDocAfterAction <- documentContents originalDoc
@@ -3734,6 +3756,21 @@ pickActionWithTitle title actions = do
37343756
, title == actionTitle
37353757
]
37363758

3759+
assertNoActionWithTitle :: T.Text -> [Command |? CodeAction] -> IO ()
3760+
assertNoActionWithTitle title actions = do
3761+
assertBool ("Unexpected code action " <> show title <> " in " <> show titles) (null matches)
3762+
pure ()
3763+
where
3764+
titles =
3765+
[ actionTitle
3766+
| InR CodeAction { _title = actionTitle } <- actions
3767+
]
3768+
matches =
3769+
[ action
3770+
| InR action@CodeAction { _title = actionTitle } <- actions
3771+
, title == actionTitle
3772+
]
3773+
37373774
findCodeActions :: TextDocumentIdentifier -> Range -> [T.Text] -> Session [CodeAction]
37383775
findCodeActions = findCodeActions' (==) "is not a superset of"
37393776

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE ImportQualifiedPost #-}
2+
{-# OPTIONS_GHC -Wprepositive-qualified-module #-}
3+
import Control.Monad qualified as Control
4+
main :: IO ()
5+
main = Control.when True $ putStrLn "hello"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import qualified Control.Monad as Control
2+
main :: IO ()
3+
main = Control.when True $ putStrLn "hello"

test/functional/FunctionalCodeAction.hs

Lines changed: 0 additions & 83 deletions
This file was deleted.

test/functional/Main.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module Main where
33
import Config
44
import Format
55
import FunctionalBadProject
6-
import FunctionalCodeAction
76
import HieBios
87
import Progress
98
import Test.Hls
@@ -13,7 +12,6 @@ main = defaultTestRunner $ testGroup "haskell-language-server"
1312
[ Config.tests
1413
, ignoreInEnv [HostOS Windows, GhcVer GHC90, GhcVer GHC92] "Tests gets stuck in ci" $ Format.tests
1514
, FunctionalBadProject.tests
16-
, FunctionalCodeAction.tests
1715
, HieBios.tests
1816
, ignoreInEnv [HostOS Windows, GhcVer GHC90] "Tests gets stuck in ci" $ Progress.tests
1917
]

test/functional/Progress.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import Data.Text (Text, pack)
1818
import Ide.Types
1919
import Language.LSP.Protocol.Capabilities
2020
import qualified Language.LSP.Protocol.Lens as L
21-
import System.FilePath ((</>))
2221
import Test.Hls
2322
import Test.Hls.Command
2423
import Test.Hls.Flags
@@ -29,10 +28,10 @@ tests =
2928
testGroup
3029
"window/workDoneProgress"
3130
[ testCase "sends indefinite progress notifications" $
32-
runSession hlsCommand progressCaps "test/testdata" $ do
33-
let path = "diagnostics" </> "Foo.hs"
31+
runSession hlsCommand progressCaps "test/testdata/diagnostics" $ do
32+
let path = "Foo.hs"
3433
_ <- openDoc path "haskell"
35-
expectProgressMessages [pack ("Setting up testdata (for " ++ path ++ ")"), "Processing", "Indexing"] []
34+
expectProgressMessages [pack ("Setting up diagnostics (for " ++ path ++ ")"), "Processing", "Indexing"] []
3635
, requiresEvalPlugin $ testCase "eval plugin sends progress reports" $
3736
runSession hlsCommand progressCaps "plugins/hls-eval-plugin/test/testdata" $ do
3837
doc <- openDoc "T1.hs" "haskell"

test/testdata/diagnostics/hie.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cradle:
2+
direct:
3+
arguments:
4+
- Foo
5+
- -Wmissing-signatures

test/testdata/format/hie.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cradle:
2+
direct:
3+
arguments:
4+
- Format

test/testdata/hie.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)