diff --git a/CODEOWNERS b/CODEOWNERS index 9450a53ec1..fdb10aa538 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -3,7 +3,8 @@ /ghcide/session-loader @pepeiborra @fendor /hls-graph @pepeiborra /hls-plugin-api @berberman -/hls-test-utils +/hls-test-utils @fendor +/test @fendor /hie-compat # Plugins diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index 02c72f7265..76f3da9bbe 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -529,21 +529,11 @@ test-suite func-test main-is: Main.hs other-modules: - Command - Completion Config - Deferred - Definition - Diagnostic Format FunctionalBadProject - FunctionalCodeAction HieBios - Highlight Progress - Reference - Symbol - TypeDefinition Test.Hls.Command Test.Hls.Flags diff --git a/hls-test-utils/src/Test/Hls/Util.hs b/hls-test-utils/src/Test/Hls/Util.hs index a3e2146743..4f0c400a18 100644 --- a/hls-test-utils/src/Test/Hls/Util.hs +++ b/hls-test-utils/src/Test/Hls/Util.hs @@ -25,6 +25,7 @@ module Test.Hls.Util , knownBrokenOnWindows , knownBrokenForGhcVersions , knownBrokenInEnv + , knownBrokenInSpecificEnv , onlyWorkForGhcVersions -- * Extract code actions , fromAction @@ -123,12 +124,18 @@ hostOS | isMac = MacOS | otherwise = Linux --- | Mark as broken if /any/ of environmental spec mathces the current environment. +-- | Mark as broken if /any/ of the environmental specs matches the current environment. knownBrokenInEnv :: [EnvSpec] -> String -> TestTree -> TestTree knownBrokenInEnv envSpecs reason | any matchesCurrentEnv envSpecs = expectFailBecause reason | otherwise = id +-- | Mark as broken if /all/ environmental specs match the current environment. +knownBrokenInSpecificEnv :: [EnvSpec] -> String -> TestTree -> TestTree +knownBrokenInSpecificEnv envSpecs reason + | all matchesCurrentEnv envSpecs = expectFailBecause reason + | otherwise = id + knownBrokenOnWindows :: String -> TestTree -> TestTree knownBrokenOnWindows = knownBrokenInEnv [HostOS Windows] diff --git a/plugins/hls-refactor-plugin/test/Main.hs b/plugins/hls-refactor-plugin/test/Main.hs index 31d3de21cc..e7975e21fa 100644 --- a/plugins/hls-refactor-plugin/test/Main.hs +++ b/plugins/hls-refactor-plugin/test/Main.hs @@ -528,21 +528,43 @@ insertImportTests = testGroup "insert import" "ModuleDeclAndImports.hs" "ModuleDeclAndImports.expected.hs" "import Data.Monoid" + , importQualifiedTests + ] + +importQualifiedTests :: TestTree +importQualifiedTests = testGroup "import qualified prefix suggestions" + [ checkImport' + "qualified import works with 3.8 code action kinds" + "ImportQualified.hs" + "ImportQualified.expected.hs" + "import qualified Control.Monad as Control" + ["import Control.Monad (when)"] + , checkImport' + "qualified import in postfix position works with 3.8 code action kinds" + "ImportPostQualified.hs" + "ImportPostQualified.expected.hs" + "import Control.Monad qualified as Control" + ["import qualified Control.Monad as Control", "import Control.Monad (when)"] ] checkImport :: String -> FilePath -> FilePath -> T.Text -> TestTree checkImport testComment originalPath expectedPath action = + checkImport' testComment originalPath expectedPath action [] + +checkImport' :: String -> FilePath -> FilePath -> T.Text -> [T.Text] -> TestTree +checkImport' testComment originalPath expectedPath action excludedActions = testSessionWithExtraFiles "import-placement" testComment $ \dir -> check (dir originalPath) (dir expectedPath) action where check :: FilePath -> FilePath -> T.Text -> Session () check originalPath expectedPath action = do oSrc <- liftIO $ readFileUtf8 originalPath - eSrc <- liftIO $ readFileUtf8 expectedPath + eSrc <- liftIO $ readFileUtf8 expectedPath originalDoc <- createDoc originalPath "haskell" oSrc _ <- waitForDiagnostics shouldBeDoc <- createDoc expectedPath "haskell" eSrc actionsOrCommands <- getAllCodeActions originalDoc + for_ excludedActions (\a -> liftIO $ assertNoActionWithTitle a actionsOrCommands) chosenAction <- liftIO $ pickActionWithTitle action actionsOrCommands executeCodeAction chosenAction originalDocAfterAction <- documentContents originalDoc @@ -3734,6 +3756,21 @@ pickActionWithTitle title actions = do , title == actionTitle ] +assertNoActionWithTitle :: T.Text -> [Command |? CodeAction] -> IO () +assertNoActionWithTitle title actions = do + assertBool ("Unexpected code action " <> show title <> " in " <> show titles) (null matches) + pure () + where + titles = + [ actionTitle + | InR CodeAction { _title = actionTitle } <- actions + ] + matches = + [ action + | InR action@CodeAction { _title = actionTitle } <- actions + , title == actionTitle + ] + findCodeActions :: TextDocumentIdentifier -> Range -> [T.Text] -> Session [CodeAction] findCodeActions = findCodeActions' (==) "is not a superset of" diff --git a/plugins/hls-refactor-plugin/test/data/import-placement/ImportPostQualified.expected.hs b/plugins/hls-refactor-plugin/test/data/import-placement/ImportPostQualified.expected.hs new file mode 100644 index 0000000000..0ea06c3dcf --- /dev/null +++ b/plugins/hls-refactor-plugin/test/data/import-placement/ImportPostQualified.expected.hs @@ -0,0 +1,5 @@ +{-# LANGUAGE ImportQualifiedPost #-} +{-# OPTIONS_GHC -Wprepositive-qualified-module #-} +import Control.Monad qualified as Control +main :: IO () +main = Control.when True $ putStrLn "hello" diff --git a/test/testdata/CodeActionImportPostQualified.hs b/plugins/hls-refactor-plugin/test/data/import-placement/ImportPostQualified.hs similarity index 100% rename from test/testdata/CodeActionImportPostQualified.hs rename to plugins/hls-refactor-plugin/test/data/import-placement/ImportPostQualified.hs diff --git a/plugins/hls-refactor-plugin/test/data/import-placement/ImportQualified.expected.hs b/plugins/hls-refactor-plugin/test/data/import-placement/ImportQualified.expected.hs new file mode 100644 index 0000000000..5b9ce112ff --- /dev/null +++ b/plugins/hls-refactor-plugin/test/data/import-placement/ImportQualified.expected.hs @@ -0,0 +1,3 @@ +import qualified Control.Monad as Control +main :: IO () +main = Control.when True $ putStrLn "hello" diff --git a/test/testdata/CodeActionImportQualified.hs b/plugins/hls-refactor-plugin/test/data/import-placement/ImportQualified.hs similarity index 100% rename from test/testdata/CodeActionImportQualified.hs rename to plugins/hls-refactor-plugin/test/data/import-placement/ImportQualified.hs diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000000..2cab8fbce7 --- /dev/null +++ b/test/README.md @@ -0,0 +1,27 @@ +# The `func-test` test suite. + +This is the integration test suite for cross-plugin and cross-package features. + +Add integration tests to `func-test` only if they satisfy one or more of the following conditions: + +* It tests the interaction between more than one plugin. + * For example, plugin A provides a Diagnostic that plugin B requires to provide a CodeAction. + * However, it is also valid, and often preferable, to depend on the required plugin directly in plugin B's test suite. +* It tests HLS specific LSP code. + * For example, we test that config changes are appropriately propagated. + * Note, this is slightly debatable, since the test could also be part of `ghcide`. + * Non HLS specific LSP code may exist in HLS temporarily, but any LSP extensions should be upstreamed to `lsp`. +* It tests features of the `haskell-language-server-wrapper` executable. + * For example, argument parsing. +* It tests features of the `haskell-language-server` executable. + * For example, argument parsing. +* It tests features provided by `hls-plugin-api` that require an integration test (i.e. a unit test doesn't suffice). + * Example: Testing the Logger setup. + +If you think that a test that currently lives in `func-test` does not meet the conditions above, open a ticket for discussion or try to move the test to a better location. + +Note: `func-test` is a historical test suite. It was originally written for Haskell IDE Engine, which was merged with the `ghcide` project. +The integration test-suite `func-test` (back then `unit-test` existed as well) was used to test all kinds of features provided by Haskell IDE Engine (HIE). +When `ghcide` and HIE merged together, the integration test suite was vastly copied. +HLS moved to a plugin-based architecture, which mainly entails that plugin tests are isolated in the respective plugin's test suite. +Over time, `func-test` started to bit rot and wasn't maintained properly any more, since all new tests were added to the plugin or `ghcide` test suites. diff --git a/test/functional/Command.hs b/test/functional/Command.hs deleted file mode 100644 index b24390d59f..0000000000 --- a/test/functional/Command.hs +++ /dev/null @@ -1,32 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} -module Command (tests) where - -import Control.Lens hiding (List) -import Data.Char -import qualified Data.Text as T -import qualified Language.LSP.Protocol.Lens as L -import Language.LSP.Protocol.Types as LSP -import Test.Hls -import Test.Hls.Command -import Test.Hls.Flags (requiresEvalPlugin) - -tests :: TestTree -tests = testGroup "commands" [ - testCase "are prefixed" $ - runSession hlsCommand fullCaps "test/testdata/" $ do - TResponseMessage _ _ (Right res) <- initializeResponse - let cmds = res ^. L.capabilities . L.executeCommandProvider . _Just . L.commands - f x = (T.length (T.takeWhile isNumber x) >= 1) && (T.count ":" x >= 2) - liftIO $ do - all f cmds @? "All prefixed" - not (null cmds) @? "Commands aren't empty" - , requiresEvalPlugin $ testCase "get de-prefixed" $ - runSession hlsCommand fullCaps "test/testdata/" $ do - TResponseMessage _ _ (Left err) <- request - SMethod_WorkspaceExecuteCommand - (ExecuteCommandParams Nothing "34133:eval:evalCommand" (Just [])) - let ResponseError _ msg _ = err - -- We expect an error message about the dud arguments, but we can - -- check that we found the right plugin. - liftIO $ "while parsing args for evalCommand in plugin eval" `T.isInfixOf` msg @? "Has error message" - ] diff --git a/test/functional/Completion.hs b/test/functional/Completion.hs deleted file mode 100644 index 111328207e..0000000000 --- a/test/functional/Completion.hs +++ /dev/null @@ -1,380 +0,0 @@ -{-# LANGUAGE OverloadedLabels #-} -{-# LANGUAGE OverloadedLists #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -module Completion(tests) where - -import Control.Lens hiding ((.=)) -import Data.Aeson (toJSON) -import Data.Foldable (find) -import Data.Functor (void) -import qualified Data.Map as Map -import Data.Row.Records (focus) -import qualified Data.Text as T -import Ide.Plugin.Config (maxCompletions, plcConfig, plugins) -import Language.LSP.Protocol.Lens hiding (applyEdit, length) -import Test.Hls -import Test.Hls.Command - -tests :: TestTree -tests = testGroup "completions" [ - testCase "works" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - let te = TextEdit (Range (Position 5 7) (Position 5 24)) "put" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 5 9) - item <- getCompletionByLabel "putStrLn" compls - liftIO $ do - item ^. label @?= "putStrLn" - item ^. kind @?= Just CompletionItemKind_Function - item ^. detail @?= Just ":: String -> IO ()\nfrom Prelude" - item ^. insertTextFormat @?= Just InsertTextFormat_Snippet - item ^. insertText @?= Just "putStrLn" - - , testCase "itemCompletion/resolve works" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - let te = TextEdit (Range (Position 5 7) (Position 5 24)) "put" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 5 9) - item <- getCompletionByLabel "putStrLn" compls - liftIO $ do - item ^. label @?= "putStrLn" - item ^. kind @?= Just CompletionItemKind_Function - item ^. detail @?= Just ":: String -> IO ()\nfrom Prelude" - item ^. insertTextFormat @?= Just InsertTextFormat_Snippet - item ^. insertText @?= Just "putStrLn" - - , testCase "completes imports" $ runSession (hlsCommand <> " --test") fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - waitForKickDone - - let te = TextEdit (Range (Position 1 17) (Position 1 26)) "Data.M" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 1 23) - item <- getCompletionByLabel "Maybe" compls - liftIO $ do - item ^. label @?= "Maybe" - item ^. detail @?= Just "Data.Maybe" - item ^. kind @?= Just CompletionItemKind_Module - - , testCase "completes qualified imports" $ runSession (hlsCommand <> " --test") fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - _ <- waitForKickDone - - let te = TextEdit (Range (Position 2 17) (Position 2 25)) "Data.L" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 2 24) - item <- getCompletionByLabel "List" compls - liftIO $ do - item ^. label @?= "List" - item ^. detail @?= Just "Data.List" - item ^. kind @?= Just CompletionItemKind_Module - - , testCase "completes with no prefix" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - compls <- getAndResolveCompletions doc (Position 5 7) - liftIO $ assertBool "Expected completions" $ not $ null compls - - , expectFailIfBeforeGhc92 "record dot syntax is introduced in GHC 9.2" - $ testGroup "recorddotsyntax" - [ testCase "shows field selectors" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "RecordDotSyntax.hs" "haskell" - - let te = TextEdit (Range (Position 25 0) (Position 25 5)) "z = x.a" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 25 6) - item <- getCompletionByLabel "a" compls - - liftIO $ do - item ^. label @?= "a" - , testCase "shows field selectors for nested field" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "RecordDotSyntax.hs" "haskell" - - let te = TextEdit (Range (Position 27 0) (Position 27 8)) "z2 = x.c.z" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 27 9) - item <- getCompletionByLabel "z" compls - - liftIO $ do - item ^. label @?= "z" - ] - - -- See https://github.com/haskell/haskell-ide-engine/issues/903 - , testCase "strips compiler generated stuff from completions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "DupRecFields.hs" "haskell" - - let te = TextEdit (Range (Position 5 0) (Position 5 2)) "acc" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 5 4) - item <- getCompletionByLabel "accessor" compls - liftIO $ do - item ^. label @?= "accessor" - item ^. kind @?= Just CompletionItemKind_Function - , testCase "have implicit foralls on basic polymorphic types" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - let te = TextEdit (Range (Position 5 7) (Position 5 9)) "id" - _ <- applyEdit doc te - compls <- getAndResolveCompletions doc (Position 5 9) - item <- getCompletionByLabel "id" compls - liftIO $ do - item ^. detail @?= Just ":: a -> a\nfrom Prelude" - - , testCase "have implicit foralls with multiple type variables" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - let te = TextEdit (Range (Position 5 7) (Position 5 24)) "flip" - _ <- applyEdit doc te - compls <- getAndResolveCompletions doc (Position 5 11) - item <- getCompletionByLabel "flip" compls - liftIO $ - item ^. detail @?= Just ":: (a -> b -> c) -> b -> a -> c\nfrom Prelude" - - , testCase "maxCompletions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - compls <- getAndResolveCompletions doc (Position 5 7) - liftIO $ length compls @?= maxCompletions def - - , testCase "import function completions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "FunctionCompletions.hs" "haskell" - - let te = TextEdit (Range (Position 0 30) (Position 0 41)) "A" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 0 31) - item <- getCompletionByLabel "Alternative" compls - liftIO $ do - item ^. label @?= "Alternative" - item ^. kind @?= Just CompletionItemKind_Function - item ^. detail @?= Just "Control.Applicative" - - , testCase "import second function completion" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "FunctionCompletions.hs" "haskell" - - let te = TextEdit (Range (Position 0 39) (Position 0 39)) ", l" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 0 42) - item <- getCompletionByLabel "liftA" compls - liftIO $ do - item ^. label @?= "liftA" - item ^. kind @?= Just CompletionItemKind_Function - item ^. detail @?= Just "Control.Applicative" - - , testCase "completes locally defined associated type family" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "AssociatedTypeFamily.hs" "haskell" - - compls <- getAndResolveCompletions doc (Position 5 20) - item <- getCompletionByLabel "Fam" compls - liftIO $ do - item ^. label @?= "Fam" - item ^. kind @?= Just CompletionItemKind_Struct - - , contextTests - , snippetTests - ] - -snippetTests :: TestTree -snippetTests = testGroup "snippets" [ - testCase "work for argumentless constructors" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - let te = TextEdit (Range (Position 5 7) (Position 5 24)) "Nothing" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 5 14) - item <- getCompletionByLabel "Nothing" compls - liftIO $ do - item ^. insertTextFormat @?= Just InsertTextFormat_Snippet - item ^. insertText @?= Just "Nothing" - - , testCase "work for polymorphic types" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - let te = TextEdit (Range (Position 5 7) (Position 5 24)) "fold" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 5 11) - item <- getCompletionByLabel "foldl" compls - liftIO $ do - item ^. label @?= "foldl" - item ^. kind @?= Just CompletionItemKind_Function - item ^. insertTextFormat @?= Just InsertTextFormat_Snippet - item ^. insertText @?= Just "foldl" - - , testCase "work for complex types" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - let te = TextEdit (Range (Position 5 7) (Position 5 24)) "mapM" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 5 11) - item <- getCompletionByLabel "mapM" compls - liftIO $ do - item ^. label @?= "mapM" - item ^. kind @?= Just CompletionItemKind_Function - item ^. insertTextFormat @?= Just InsertTextFormat_Snippet - item ^. insertText @?= Just "mapM" - - , testCase "work for infix functions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - let te = TextEdit (Range (Position 5 7) (Position 5 24)) "even `filte" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 5 18) - item <- getCompletionByLabel "filter" compls - liftIO $ do - item ^. label @?= "filter" - item ^. kind @?= Just CompletionItemKind_Function - item ^. insertTextFormat @?= Just InsertTextFormat_PlainText - item ^. insertText @?= Nothing - - , testCase "work for infix functions in backticks" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - let te = TextEdit (Range (Position 5 7) (Position 5 24)) "even `filte`" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 5 18) - item <- getCompletionByLabel "filter" compls - liftIO $ do - item ^. label @?= "filter" - item ^. kind @?= Just CompletionItemKind_Function - item ^. insertTextFormat @?= Just InsertTextFormat_PlainText - item ^. insertText @?= Nothing - - , testCase "work for qualified infix functions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - let te = TextEdit (Range (Position 5 7) (Position 5 24)) "\"\" `Data.List.interspe" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 5 29) - item <- getCompletionByLabel "intersperse" compls - liftIO $ do - item ^. label @?= "intersperse" - item ^. kind @?= Just CompletionItemKind_Function - item ^. insertTextFormat @?= Just InsertTextFormat_PlainText - item ^. insertText @?= Nothing - - , testCase "work for qualified infix functions in backticks" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - let te = TextEdit (Range (Position 5 7) (Position 5 24)) "\"\" `Data.List.interspe`" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 5 29) - item <- getCompletionByLabel "intersperse" compls - liftIO $ do - item ^. label @?= "intersperse" - item ^. kind @?= Just CompletionItemKind_Function - item ^. insertTextFormat @?= Just InsertTextFormat_PlainText - item ^. insertText @?= Nothing - - , testCase "respects lsp configuration" $ runSessionWithConfig (def {ignoreConfigurationRequests=False}) hlsCommand fullCaps "test/testdata/completion" $ do - void configurationRequest - doc <- openDoc "Completion.hs" "haskell" - - let config = def { plugins = Map.insert "ghcide-completions" (def { plcConfig = [("snippetsOn", (toJSON False))]}) (plugins def) } - - setHlsConfig config - - checkNoSnippets doc - - , testCase "respects client capabilities" $ runSession hlsCommand noSnippetsCaps "test/testdata/completion" $ do - doc <- openDoc "Completion.hs" "haskell" - - checkNoSnippets doc - , testCase "works for record fields sharing the single signature" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "FieldsSharingSignature.hs" "haskell" - - let te = TextEdit (Range (Position 1 0) (Position 1 2)) "MkF" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 1 6) - item <- case find (\c -> (c ^. label == "MkFoo") && maybe False ("MkFoo {" `T.isPrefixOf`) (c ^. insertText)) compls of - Just c -> pure c - Nothing -> liftIO . assertFailure $ "Completion with label 'MkFoo' and insertText starting with 'MkFoo {' not found among " <> show compls - liftIO $ do - item ^. insertTextFormat @?= Just InsertTextFormat_Snippet - item ^. insertText @?= Just "MkFoo {arg1=${1:_arg1}, arg2=${2:_arg2}, arg3=${3:_arg3}, arg4=${4:_arg4}, arg5=${5:_arg5}}" - ] - where - checkNoSnippets doc = do - let te = TextEdit (Range (Position 5 7) (Position 5 24)) "fold" - _ <- applyEdit doc te - - compls <- getAndResolveCompletions doc (Position 5 11) - item <- getCompletionByLabel "foldl" compls - liftIO $ do - item ^. label @?= "foldl" - item ^. kind @?= Just CompletionItemKind_Function - item ^. insertTextFormat @?= Just InsertTextFormat_PlainText - item ^. insertText @?= Nothing - - noSnippetsCaps = - ( textDocument - . _Just - . completion - . _Just - . completionItem - . _Just - . focus #snippetSupport - ?~ False - ) - fullCaps - -contextTests :: TestTree -contextTests = testGroup "contexts" [ - testCase "only provides type suggestions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Context.hs" "haskell" - - compls <- getAndResolveCompletions doc (Position 2 17) - liftIO $ do - compls `shouldContainCompl` "Integer" - compls `shouldNotContainCompl` "interact" - - , testCase "only provides value suggestions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Context.hs" "haskell" - - compls <- getAndResolveCompletions doc (Position 3 10) - liftIO $ do - compls `shouldContainCompl` "abs" - compls `shouldNotContainCompl` "Applicative" - - , testCase "completes qualified type suggestions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do - doc <- openDoc "Context.hs" "haskell" - - compls <- getAndResolveCompletions doc (Position 2 26) - liftIO $ do - compls `shouldNotContainCompl` "forkOn" - compls `shouldContainCompl` "MVar" - compls `shouldContainCompl` "Chan" - ] - -shouldContainCompl :: [CompletionItem] -> T.Text -> Assertion -compls `shouldContainCompl` lbl = - any ((== lbl) . (^. label)) compls - @? "Should contain completion: " ++ show lbl - -shouldNotContainCompl :: [CompletionItem] -> T.Text -> Assertion -compls `shouldNotContainCompl` lbl = - all ((/= lbl) . (^. label)) compls - @? "Should not contain completion: " ++ show lbl - -expectFailIfBeforeGhc92 :: String -> TestTree -> TestTree -expectFailIfBeforeGhc92 = knownBrokenForGhcVersions [GHC90] diff --git a/test/functional/Deferred.hs b/test/functional/Deferred.hs deleted file mode 100644 index eb8d1aa72d..0000000000 --- a/test/functional/Deferred.hs +++ /dev/null @@ -1,171 +0,0 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -module Deferred(tests) where - -import Control.Lens hiding (List) --- import Control.Monad --- import Data.Maybe -import Language.LSP.Protocol.Lens hiding (id, length, message) -import Language.LSP.Protocol.Types (Null (Null)) --- import qualified Language.LSP.Types.Lens as LSP -import Test.Hls -import Test.Hls.Command - - -tests :: TestTree -tests = testGroup "deferred responses" [ - - --TODO: DOes not compile - -- testCase "do not affect hover requests" $ runSession hlsCommand fullCaps "test/testdata" $ do - -- doc <- openDoc "FuncTest.hs" "haskell" - - -- id1 <- sendRequest TextDocumentHover (TextDocumentPositionParams doc (Position 4 2) Nothing) - - -- skipMany anyNotification - -- hoverRsp <- message :: Session HoverResponse - -- liftIO $ hoverRsp ^? result . _Just . _Just . contents @?= Nothing - -- liftIO $ hoverRsp ^. LSP.id @?= responseId id1 - - -- id2 <- sendRequest TextDocumentDocumentSymbol (DocumentSymbolParams doc Nothing) - -- symbolsRsp <- skipManyTill anyNotification message :: Session DocumentSymbolsResponse - -- liftIO $ symbolsRsp ^. LSP.id @?= responseId id2 - - -- id3 <- sendRequest TextDocumentHover (TextDocumentPositionParams doc (Position 4 2) Nothing) - -- hoverRsp2 <- skipManyTill anyNotification message :: Session HoverResponse - -- liftIO $ hoverRsp2 ^. LSP.id @?= responseId id3 - - -- let contents2 = hoverRsp2 ^? result . _Just . _Just . contents - -- liftIO $ contents2 `shouldNotSatisfy` null - - -- -- Now that we have cache the following request should be instant - -- let highlightParams = TextDocumentPositionParams doc (Position 7 0) Nothing - -- highlightRsp <- request TextDocumentDocumentHighlight highlightParams - -- let (Just (List locations)) = highlightRsp ^. result - -- liftIO $ locations @?= [ DocumentHighlight - -- { _range = Range - -- { _start = Position {_line = 7, _character = 0} - -- , _end = Position {_line = 7, _character = 2} - -- } - -- , _kind = Just HkWrite - -- } - -- , DocumentHighlight - -- { _range = Range - -- { _start = Position {_line = 7, _character = 0} - -- , _end = Position {_line = 7, _character = 2} - -- } - -- , _kind = Just HkWrite - -- } - -- , DocumentHighlight - -- { _range = Range - -- { _start = Position {_line = 5, _character = 6} - -- , _end = Position {_line = 5, _character = 8} - -- } - -- , _kind = Just HkRead - -- } - -- , DocumentHighlight - -- { _range = Range - -- { _start = Position {_line = 7, _character = 0} - -- , _end = Position {_line = 7, _character = 2} - -- } - -- , _kind = Just HkWrite - -- } - -- , DocumentHighlight - -- { _range = Range - -- { _start = Position {_line = 7, _character = 0} - -- , _end = Position {_line = 7, _character = 2} - -- } - -- , _kind = Just HkWrite - -- } - -- , DocumentHighlight - -- { _range = Range - -- { _start = Position {_line = 5, _character = 6} - -- , _end = Position {_line = 5, _character = 8} - -- } - -- , _kind = Just HkRead - -- } - -- ] - - testCase "instantly respond to failed modules with no cache" $ runSession hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "FuncTestFail.hs" "haskell" - defs <- getDefinitions doc (Position 1 11) - liftIO $ defs @?= InR (InR Null) - - -- TODO: the benefits of caching parsed modules is doubted. - -- TODO: add issue link - -- , testCase "respond to untypecheckable modules with parsed module cache" $ - -- runSession hlsCommand fullCaps "test/testdata" $ do - -- doc <- openDoc "FuncTestFail.hs" "haskell" - -- (Left (sym:_)) <- getDocumentSymbols doc - -- liftIO $ sym ^. name @?= "main" - - -- TODO does not compile - -- , testCase "returns hints as diagnostics" $ runSession hlsCommand fullCaps "test/testdata" $ do - -- _ <- openDoc "FuncTest.hs" "haskell" - - -- cwd <- liftIO getCurrentDirectory - -- let testUri = filePathToUri $ cwd "test/testdata/FuncTest.hs" - - -- diags <- publishDiagnosticsNotification - -- liftIO $ diags ^? params @?= (Just $ PublishDiagnosticsParams - -- { _uri = testUri - -- , _diagnostics = List - -- [ Diagnostic - -- (Range (Position 9 6) (Position 10 18)) - -- (Just DsInfo) - -- (Just (StringValue "Redundant do")) - -- (Just "hlint") - -- "Redundant do\nFound:\n do putStrLn \"hello\"\nWhy not:\n putStrLn \"hello\"\n" - -- Nothing - -- ] - -- } - -- ) - -- let args' = H.fromList [("pos", toJSON (Position 7 0)), ("file", toJSON testUri)] - -- args = List [Object args'] - -- - -- executeRsp <- request WorkspaceExecuteCommand (ExecuteCommandParams "hare:demote" (Just args) Nothing) - -- liftIO $ executeRsp ^. result @?= Just (Object H.empty) - - -- editReq <- message :: Session ApplyWorkspaceEditRequest - -- let expectedTextEdits = List [TextEdit (Range (Position 6 0) (Position 7 6)) " where\n bb = 5"] - -- expectedTextDocEdits = List [TextDocumentEdit (VersionedTextDocumentIdentifier testUri (Just 0)) expectedTextEdits] - -- liftIO $ editReq ^. params . edit @?= WorkspaceEdit - -- Nothing - -- (Just expectedTextDocEdits) - -- , multiServerTests - , multiMainTests - ] - ---TODO: Does not compile --- multiServerTests :: TestTree --- multiServerTests = testGroup "multi-server setup" [ --- testCase "doesn't have clashing commands on two servers" $ do --- let getCommands = runSession hlsCommand fullCaps "test/testdata" $ do --- rsp <- initializeResponse --- let uuids = rsp ^? result . _Just . capabilities . executeCommandProvider . _Just . commands --- return $ fromJust uuids --- List uuids1 <- getCommands --- List uuids2 <- getCommands --- liftIO $ forM_ (zip uuids1 uuids2) (uncurry shouldNotBe) --- ] - -multiMainTests :: TestTree -multiMainTests = testGroup "multiple main modules" [ - ignoreTestBecause "Broken: Unexpected ConduitParser.empty" $ - testCase "Can load one file at a time, when more than one Main module exists" - $ runSession hlsCommand fullCaps "test/testdata" $ do - _doc <- openDoc "ApplyRefact2.hs" "haskell" - _diagsRspHlint <- skipManyTill anyNotification (message SMethod_TextDocumentPublishDiagnostics) - diagsRspGhc <- skipManyTill anyNotification (message SMethod_TextDocumentPublishDiagnostics) - let diags = diagsRspGhc ^. params . diagnostics - - liftIO $ length diags @?= 2 - - _doc2 <- openDoc "HaReRename.hs" "haskell" - _diagsRspHlint2 <- skipManyTill anyNotification (message SMethod_TextDocumentPublishDiagnostics) - -- errMsg <- skipManyTill anyNotification notification :: Session ShowMessageNotification - diagsRsp2 <- skipManyTill anyNotification (message SMethod_TextDocumentPublishDiagnostics) - let diags2 = diagsRsp2 ^. params . diagnostics - - liftIO $ show diags2 @?= "[]" - ] diff --git a/test/functional/Definition.hs b/test/functional/Definition.hs deleted file mode 100644 index 3c32f2cf72..0000000000 --- a/test/functional/Definition.hs +++ /dev/null @@ -1,89 +0,0 @@ -module Definition (tests) where - -import Control.Lens -import Language.LSP.Protocol.Lens -import System.Directory -import Test.Hls -import Test.Hls.Command - -tests :: TestTree -tests = testGroup "definitions" [symbolTests, moduleTests] - -symbolTests :: TestTree -symbolTests = testGroup "gotoDefinition on symbols" - -- gotoDefinition where the definition is in the same file - [ testCase "gotoDefinition in this file" $ runSession hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "References.hs" "haskell" - defs <- getDefinitions doc (Position 7 8) - let expRange = Range (Position 4 0) (Position 4 3) - liftIO $ defs @?= InL (Definition (InR [Location (doc ^. uri) expRange])) - - -- gotoDefinition where the definition is in a different file - , testCase "gotoDefinition in other file" $ runSession hlsCommand fullCaps "test/testdata/definition" $ do - doc <- openDoc "Foo.hs" "haskell" - defs <- getDefinitions doc (Position 4 11) - let expRange = Range (Position 2 0) (Position 2 1) - liftIO $ do - fp <- canonicalizePath "test/testdata/definition/Bar.hs" - defs @?= InL (Definition (InR [Location (filePathToUri fp) expRange])) - - -- gotoDefinition where the definition is in a different file and the - -- definition in the other file is on a line number that is greater - -- than the number of lines in the file we are requesting from - , testCase "gotoDefinition in other file past lines in this file" $ runSession hlsCommand fullCaps "test/testdata/definition" $ do - doc <- openDoc "Foo.hs" "haskell" - defs <- getDefinitions doc (Position 5 13) - let expRange = Range (Position 8 0) (Position 8 1) - liftIO $ do - fp <- canonicalizePath "test/testdata/definition/Bar.hs" - defs @?= InL (Definition (InR [Location (filePathToUri fp) expRange])) - ] - - -- ----------------------------------- - -moduleTests :: TestTree -moduleTests = testGroup "gotoDefinition on modules" - [ ignoreTestBecause "Broken: file:///Users/jwindsor/src/haskell-language-server/test/testdata/Bar.hs" $ - testCase "goto's imported modules" $ runSession hlsCommand fullCaps "test/testdata/definition" $ do - doc <- openDoc "Foo.hs" "haskell" - defs <- getDefinitions doc (Position 2 8) - liftIO $ do - fp <- canonicalizePath "test/testdata/definition/Bar.hs" - defs @?= InL (Definition (InR [Location (filePathToUri fp) zeroRange])) - - , ignoreTestBecause "Broken: file:///Users/jwindsor/src/haskell-language-server/test/testdata/Bar.hs" $ - testCase "goto's exported modules" $ runSession hlsCommand fullCaps "test/testdata/definition" $ do - doc <- openDoc "Foo.hs" "haskell" - defs <- getDefinitions doc (Position 0 15) - liftIO $ do - fp <- canonicalizePath "test/testdata/definition/Bar.hs" - defs @?= InL (Definition (InR [Location (filePathToUri fp) zeroRange])) - - , ignoreTestBecause "Broken: file:///Users/jwindsor/src/haskell-language-server/test/testdata/Bar.hs" $ - testCase "goto's imported modules that are loaded" $ runSession hlsCommand fullCaps "test/testdata/definition" $ do - doc <- openDoc "Foo.hs" "haskell" - _ <- openDoc "Bar.hs" "haskell" - defs <- getDefinitions doc (Position 2 8) - liftIO $ do - fp <- canonicalizePath "test/testdata/definition/Bar.hs" - defs @?= InL (Definition (InR [Location (filePathToUri fp) zeroRange])) - - , ignoreTestBecause "Broken: file:///Users/jwindsor/src/haskell-language-server/test/testdata/Bar.hs" $ - testCase "goto's imported modules that are loaded, and then closed" $ - runSession hlsCommand fullCaps "test/testdata/definition" $ do - doc <- openDoc "Foo.hs" "haskell" - otherDoc <- openDoc "Bar.hs" "haskell" - closeDoc otherDoc - defs <- getDefinitions doc (Position 2 8) - _ <- waitForDiagnostics - liftIO $ putStrLn "D" - liftIO $ do - fp <- canonicalizePath "test/testdata/definition/Bar.hs" - defs @?= InL (Definition (InR [Location (filePathToUri fp) zeroRange])) - liftIO $ putStrLn "E" -- AZ - - noDiagnostics - ] - -zeroRange :: Range -zeroRange = Range (Position 0 0) (Position 0 0) diff --git a/test/functional/Diagnostic.hs b/test/functional/Diagnostic.hs deleted file mode 100644 index 6d4502d145..0000000000 --- a/test/functional/Diagnostic.hs +++ /dev/null @@ -1,24 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module Diagnostic (tests) where - -import Control.Lens hiding (List) -import qualified Language.LSP.Protocol.Lens as L -import Test.Hls -import Test.Hls.Command - --- --------------------------------------------------------------------- - -tests :: TestTree -tests = testGroup "diagnostics providers" [ warningTests ] - - -warningTests :: TestTree -warningTests = testGroup "Warnings are warnings" [ - testCase "Overrides -Werror" $ - runSession hlsCommand fullCaps "test/testdata/wErrorTest" $ do - doc <- openDoc "src/WError.hs" "haskell" - [diag] <- waitForDiagnosticsFrom doc - liftIO $ diag ^. L.severity @?= Just DiagnosticSeverity_Warning - ] - diff --git a/test/functional/Format.hs b/test/functional/Format.hs index 2f018c3d3c..6b174a68d1 100644 --- a/test/functional/Format.hs +++ b/test/functional/Format.hs @@ -4,10 +4,8 @@ module Format (tests) where import Control.Lens ((^.)) import Control.Monad.IO.Class -import qualified Data.ByteString.Lazy as BS import Data.Functor (void) import qualified Data.Text as T -import qualified Data.Text.Encoding as T import qualified Data.Text.IO as T import Ide.Types import qualified Language.LSP.Protocol.Lens as L @@ -19,34 +17,13 @@ import Test.Hls.Flags (requiresFloskellPlugin, requiresOrmoluPlugin) tests :: TestTree -tests = testGroup "format document" [ - requiresOrmoluPlugin $ goldenGitDiff "works" "test/testdata/format/Format.formatted_document.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do - doc <- openDoc "Format.hs" "haskell" - formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) - BS.fromStrict . T.encodeUtf8 <$> documentContents doc - , requiresOrmoluPlugin $ goldenGitDiff "works with custom tab size" "test/testdata/format/Format.formatted_document_with_tabsize.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do - doc <- openDoc "Format.hs" "haskell" - formatDoc doc (FormattingOptions 5 True Nothing Nothing Nothing) - BS.fromStrict . T.encodeUtf8 <$> documentContents doc - , rangeTests - , providerTests - ] - -rangeTests :: TestTree -rangeTests = requiresOrmoluPlugin $ testGroup "format range" [ - goldenGitDiff "works" "test/testdata/format/Format.formatted_range.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do - doc <- openDoc "Format.hs" "haskell" - formatRange doc (FormattingOptions 2 True Nothing Nothing Nothing) (Range (Position 5 0) (Position 7 10)) - BS.fromStrict . T.encodeUtf8 <$> documentContents doc - , goldenGitDiff "works with custom tab size" "test/testdata/format/Format.formatted_range_with_tabsize.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do - doc <- openDoc "Format.hs" "haskell" - formatRange doc (FormattingOptions 5 True Nothing Nothing Nothing) (Range (Position 8 0) (Position 11 19)) - BS.fromStrict . T.encodeUtf8 <$> documentContents doc +tests = testGroup "format document" + [ providerTests ] providerTests :: TestTree -providerTests = testGroup "formatting provider" [ - testCase "respects none" $ runSessionWithConfig (formatConfig "none") hlsCommand fullCaps "test/testdata/format" $ do +providerTests = testGroup "lsp formatting provider" + [ testCase "respects none" $ runSessionWithConfig (formatConfig "none") hlsCommand fullCaps "test/testdata/format" $ do void configurationRequest doc <- openDoc "Format.hs" "haskell" resp <- request SMethod_TextDocumentFormatting $ DocumentFormattingParams Nothing doc (FormattingOptions 2 True Nothing Nothing Nothing) diff --git a/test/functional/FunctionalBadProject.hs b/test/functional/FunctionalBadProject.hs index 16f1fd213d..e6242ba9c1 100644 --- a/test/functional/FunctionalBadProject.hs +++ b/test/functional/FunctionalBadProject.hs @@ -16,7 +16,7 @@ tests = testGroup "behaviour on malformed projects" doc <- openDoc "src/MyLib.hs" "haskell" [diag] <- waitForDiagnosticsFrom doc liftIO $ assertBool "missing module name" $ "MyLib" `T.isInfixOf` (diag ^. L.message) - liftIO $ assertBool "module missing context" $ "may not be listed" `T.isInfixOf` (diag ^. L.message) + liftIO $ assertBool "module missing context" $ "may not be listed" `T.isInfixOf` (diag ^. L.message) , testCase "Missing module diagnostic - no matching prefix" $ do runSession hlsCommand fullCaps "test/testdata/missingModuleTest/noPrefixMatch/" $ do doc <- openDoc "app/Other.hs" "haskell" diff --git a/test/functional/FunctionalCodeAction.hs b/test/functional/FunctionalCodeAction.hs deleted file mode 100644 index dfe9ba680b..0000000000 --- a/test/functional/FunctionalCodeAction.hs +++ /dev/null @@ -1,416 +0,0 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} - -module FunctionalCodeAction (tests) where - -import Control.Lens hiding (List) -import Control.Monad -import Data.Aeson.Lens (_Object) -import Data.List -import Data.Maybe -import qualified Data.Text as T -import Development.IDE.Core.Compile (sourceTypecheck) -import Development.IDE.Test (configureCheckProject) -import Ide.Plugin.Config -import qualified Language.LSP.Protocol.Lens as L -import Language.LSP.Test as Test -import Test.Hls -import Test.Hls.Command -import Test.Hspec.Expectations - -{-# ANN module ("HLint: ignore Reduce duplication"::String) #-} - -tests :: TestTree -tests = testGroup "code actions" [ -#if hls_refactor - importTests - , ignoreInEnv [HostOS Windows, GhcVer GHC94] "Diagnostic failure for Windows-ghc9.4.2" importQualifiedTests - , ignoreInEnv [HostOS Windows, GhcVer GHC94] "Diagnostic failure for Windows-ghc9.4.2" importQualifiedPostTests - , packageTests - , redundantImportTests - , renameTests - , signatureTests - , typedHoleTests - , unusedTermTests -#endif - ] - -renameTests :: TestTree -renameTests = testGroup "rename suggestions" [ - testCase "works" $ runSession hlsCommand noLiteralCaps "test/testdata" $ do - doc <- openDoc "CodeActionRename.hs" "haskell" - - _ <- waitForDiagnosticsFromSource doc (T.unpack sourceTypecheck) - - cars <- getAllCodeActions doc - replaceButStrLn <- liftIO $ inspectCommand cars ["Replace with", "putStrLn"] - executeCommand replaceButStrLn - _ <- anyRequest - - x:_ <- T.lines <$> documentContents doc - liftIO $ x @?= "main = putStrLn \"hello\"" - - , testCase "doesn't give both documentChanges and changes" - $ runSession hlsCommand noLiteralCaps "test/testdata" $ do - configureCheckProject False - doc <- openDoc "CodeActionRename.hs" "haskell" - - _ <- waitForDiagnosticsFromSource doc (T.unpack sourceTypecheck) - - cars <- getAllCodeActions doc - cmd <- liftIO $ inspectCommand cars ["Replace with", "putStrLn"] - let mbArgs = cmd ^. L.arguments - case mbArgs of - Just [args] -> liftIO $ do - let editParams = args ^. ix "fallbackWorkspaceEdit" . _Object - (editParams & has (ix "changes")) @? "Contains changes" - not (editParams & has (ix "documentChanges")) @? "Doesn't contain documentChanges" - _ -> error $ "Unexpected arguments: " ++ show mbArgs - - executeCommand cmd - _ <- anyRequest - - x1:x2:_ <- T.lines <$> documentContents doc - liftIO $ - x1 == "main = putStrLn \"hello\"" - || x2 == "foo = putStrLn \"world\"" - @? "One of the typos got fixed" - ] - -importTests :: TestTree -importTests = testGroup "import suggestions" [ - testCase "import works with 3.8 code action kinds" $ runSessionWithConfig (def {lspConfig = hlsConfigToClientConfig testConfig}) hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "CodeActionImport.hs" "haskell" - - (diag:_) <- waitForDiagnosticsFrom doc - liftIO $ diag ^. L.message @?= "Variable not in scope: when :: Bool -> IO () -> IO ()" - - actionsOrCommands <- getAllCodeActions doc - let actns = map fromAction actionsOrCommands - - importControlMonad <- liftIO $ inspectCodeAction actionsOrCommands ["import Control.Monad"] - liftIO $ do - expectCodeAction actionsOrCommands ["import Control.Monad (when)"] - length actns >= 10 @? "There are some actions" - - executeCodeAction importControlMonad - - contents <- documentContents doc - liftIO $ contents @?= "import Control.Monad\nmain :: IO ()\nmain = when True $ putStrLn \"hello\"" - ] - -importQualifiedTests :: TestTree -importQualifiedTests = testGroup "import qualified prefix suggestions" [ - testCase "qualified import works with 3.8 code action kinds" $ runSessionWithConfig (def {lspConfig = hlsConfigToClientConfig testConfig}) hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "CodeActionImportQualified.hs" "haskell" - (diag:_) <- waitForDiagnosticsFrom doc - liftIO $ diag ^. L.message @?= - if ghcVersion >= GHC96 - then "Variable not in scope: Control.when :: Bool -> IO () -> IO ()\nNB: no module named ‘Control’ is imported." - else "Not in scope: ‘Control.when’\nNo module named ‘Control’ is imported." - - actionsOrCommands <- getAllCodeActions doc - let actns = map fromAction actionsOrCommands - - let importQualifiedSuggestion = "import qualified Control.Monad as Control" - importControlMonadQualified <- liftIO $ inspectCodeAction actionsOrCommands [importQualifiedSuggestion] - liftIO $ do - dontExpectCodeAction actionsOrCommands ["import Control.Monad (when)"] - length actns >= 5 @? "There are some actions" - - executeCodeAction importControlMonadQualified - - contents <- documentContents doc - liftIO $ contents @?= "import qualified Control.Monad as Control\nmain :: IO ()\nmain = Control.when True $ putStrLn \"hello\"\n" - ] - -importQualifiedPostTests :: TestTree -importQualifiedPostTests = testGroup "import qualified postfix suggestions" [ - testCase "qualified import in postfix position works with 3.8 code action kinds" $ runSessionWithConfig (def {lspConfig = hlsConfigToClientConfig testConfig}) hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "CodeActionImportPostQualified.hs" "haskell" - (diag:_) <- waitForDiagnosticsFrom doc - liftIO $ diag ^. L.message @?= - if ghcVersion >= GHC96 - then "Variable not in scope: Control.when :: Bool -> IO () -> IO ()\nNB: no module named ‘Control’ is imported." - else "Not in scope: ‘Control.when’\nNo module named ‘Control’ is imported." - - actionsOrCommands <- getAllCodeActions doc - let actns = map fromAction actionsOrCommands - - let importQualifiedPostSuggestion = "import Control.Monad qualified as Control" - importControlMonadQualified <- liftIO $ inspectCodeAction actionsOrCommands [importQualifiedPostSuggestion] - liftIO $ do - dontExpectCodeAction actionsOrCommands ["import qualified Control.Monad as Control", "import Control.Monad (when)"] - length actns >= 5 @? "There are some actions" - - executeCodeAction importControlMonadQualified - - contents <- documentContents doc - liftIO $ T.lines contents !! 2 @?= "import Control.Monad qualified as Control" - ] - -packageTests :: TestTree -packageTests = testGroup "add package suggestions" [ - ignoreTestBecause "no support for adding dependent packages via code action" $ testCase "adds to .cabal files" $ do - runSession hlsCommand fullCaps "test/testdata/addPackageTest/cabal-exe" $ do - doc <- openDoc "AddPackage.hs" "haskell" - - -- ignore the first empty hlint diagnostic publish - [_,diag:_] <- count 2 $ waitForDiagnosticsFrom doc - - let prefixes = [ "Could not load module `Data.Text'" -- Windows && GHC >= 8.6 - , "Could not find module `Data.Text'" -- Windows - , "Could not load module ‘Data.Text’" -- GHC >= 8.6 - , "Could not find module ‘Data.Text’" - ] - in liftIO $ any (`T.isPrefixOf` (diag ^. L.message)) prefixes @? "Contains prefix" - - acts <- getAllCodeActions doc - case acts of - (InR action:_) -> do - liftIO $ do - action ^. L.title @?= "Add text as a dependency" - action ^. L.kind @?= Just CodeActionKind_QuickFix - "package:add" `T.isSuffixOf` (action ^. L.command . _Just . L.command) @? "Command contains package:add" - - executeCodeAction action - - _ -> error $ "Unexpected code actions: " ++ show acts - - contents <- skipManyTill anyMessage $ getDocumentEdit . TextDocumentIdentifier =<< getDocUri "add-package-test.cabal" - liftIO $ - any (\l -> "text -any" `T.isSuffixOf` l || "text : {} -any" `T.isSuffixOf` l) (T.lines contents) @? "Contains text package" - - , ignoreTestBecause "no support for adding dependent packages via code action" $ testCase "adds to hpack package.yaml files" $ - runSession hlsCommand fullCaps "test/testdata/addPackageTest/hpack-exe" $ do - doc <- openDoc "app/Asdf.hs" "haskell" - - -- ignore the first empty hlint diagnostic publish - [_,_:diag:_] <- count 2 $ waitForDiagnosticsFrom doc - - let prefixes = - [ "Could not load module `Codec.Compression.GZip'" -- Windows && GHC >= 8.6 - , "Could not find module `Codec.Compression.GZip'" -- Windows - , "Could not load module ‘Codec.Compression.GZip’" -- GHC >= 8.6 - , "Could not find module ‘Codec.Compression.GZip’" - ] - in liftIO $ any (`T.isPrefixOf` (diag ^. L.message)) prefixes @? "Diagnostic contains message" - - mActions <- getAllCodeActions doc - let allActions = map fromAction mActions - action <- case allActions of - (a:_) -> pure a - _ -> liftIO $ assertFailure "Expected non-empty list of actions" - - liftIO $ do - action ^. L.title @?= "Add zlib as a dependency" - forM_ allActions $ \a -> a ^. L.kind @?= Just CodeActionKind_QuickFix - forM_ allActions $ \a -> "package:add" `T.isSuffixOf` (a ^. L.command . _Just . L.command) @? "Command contains package:add" - - executeCodeAction action - - contents <- skipManyTill anyMessage $ getDocumentEdit . TextDocumentIdentifier =<< getDocUri "package.yaml" - liftIO $ do - "zlib" `T.isSuffixOf` (T.lines contents !! 3) @? "Contains zlib" - "zlib" `T.isSuffixOf` (T.lines contents !! 21) @? "Does not contain zlib in unrelated component" - ] - -redundantImportTests :: TestTree -redundantImportTests = testGroup "redundant import code actions" [ - testCase "remove solitary redundant imports" $ - runSession hlsCommand fullCaps "test/testdata/redundantImportTest/" $ do - doc <- openDoc "src/CodeActionRedundant.hs" "haskell" - - diags <- waitForDiagnosticsFromSource doc (T.unpack sourceTypecheck) - liftIO $ expectDiagnostic diags [ "The import of", "Data.List", "is redundant" ] - liftIO $ expectDiagnostic diags [ "Empty", "from module", "Data.Sequence" ] - - mActions <- getAllCodeActions doc - - let allActions = map fromAction mActions - actionTitles = map (view L.title) allActions - - liftIO $ actionTitles `shouldContain` - [ "Remove import" - , "Remove Empty from import" - , "Remove all redundant imports" - ] - - let mbRemoveAction = find (\x -> x ^. L.title == "Remove all redundant imports") allActions - - case mbRemoveAction of - Just removeAction -> do - liftIO $ do - forM_ allActions $ \a -> a ^. L.kind @?= Just CodeActionKind_QuickFix - forM_ allActions $ \a -> a ^. L.command @?= Nothing - forM_ allActions $ \a -> isJust (a ^. L.edit) @? "Has edit" - - executeCodeAction removeAction - - Nothing -> error $ "Unexpected code actions: " ++ show allActions - - -- No command/applyworkspaceedit should be here, since action - -- provides workspace edit property which skips round trip to - -- the server - contents <- documentContents doc - liftIO $ contents @?= T.unlines - [ "{-# OPTIONS_GHC -Wunused-imports #-}" - , "{-# LANGUAGE PatternSynonyms #-}" - , "module CodeActionRedundant where" - , "-- We need a non-reduntant import in the import list" - , "-- to properly test the removal of the singular redundant item" - , "import Data.Sequence (singleton)" - , "main :: IO ()" - , "main = putStrLn \"hello\"" - , " where unused = Data.Sequence.singleton 42" - ] - - , testCase "doesn't touch other imports" $ runSession hlsCommand noLiteralCaps "test/testdata/redundantImportTest/" $ do - doc <- openDoc "src/MultipleImports.hs" "haskell" - _ <- waitForDiagnosticsFromSource doc (T.unpack sourceTypecheck) - cas <- getAllCodeActions doc - cmd <- liftIO $ inspectCommand cas ["redundant import"] - executeCommand cmd - _ <- anyRequest - contents <- documentContents doc - liftIO $ T.lines contents @?= - [ "{-# OPTIONS_GHC -Wunused-imports #-}" - , "module MultipleImports where" - , "import Data.Maybe" - , "foo :: Int" - , "foo = fromJust (Just 3)" - ] - ] - - -typedHoleTests :: TestTree -typedHoleTests = testGroup "typed hole code actions" [ - testCase "works" $ - runSessionWithConfig (def {lspConfig = hlsConfigToClientConfig testConfig}) hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "TypedHoles.hs" "haskell" - _ <- waitForDiagnosticsFromSource doc (T.unpack sourceTypecheck) - cas <- getAllCodeActions doc - liftIO $ do - expectCodeAction cas ["replace _ with minBound"] - expectCodeAction cas ["replace _ with foo _"] - replaceWithMaxBound <- liftIO $ inspectCodeAction cas ["replace _ with maxBound"] - - executeCodeAction replaceWithMaxBound - - contents <- documentContents doc - - liftIO $ contents @?= T.concat - [ "module TypedHoles where\n" - , "foo :: [Int] -> Int\n" - , "foo x = maxBound" - ] - - , testCase "shows more suggestions" $ - runSessionWithConfig (def {lspConfig = hlsConfigToClientConfig testConfig}) hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "TypedHoles2.hs" "haskell" - _ <- waitForDiagnosticsFromSource doc (T.unpack sourceTypecheck) - cas <- getAllCodeActions doc - - liftIO $ do - expectCodeAction cas ["replace _ with foo2 _"] - expectCodeAction cas ["replace _ with A _"] - replaceWithStuff <- liftIO $ inspectCodeAction cas ["replace _ with stuff _"] - - executeCodeAction replaceWithStuff - - contents <- documentContents doc - - liftIO $ T.lines contents @?= - [ "module TypedHoles2 (foo2) where" - , "newtype A = A Int" - , "foo2 :: [A] -> A" - , "foo2 x = (stuff _)" - , " where" - , " stuff (A a) = A (a + 1)" - ] - ] - -signatureTests :: TestTree -signatureTests = testGroup "missing top level signature code actions" [ - testCase "Adds top level signature" $ - runSession hlsCommand fullCaps "test/testdata/" $ do - doc <- openDoc "TopLevelSignature.hs" "haskell" - - _ <- waitForDiagnosticsFromSource doc (T.unpack sourceTypecheck) - cas <- getAllCodeActions doc - - liftIO $ expectCodeAction cas ["add signature: main :: IO ()"] - - replaceWithStuff <- liftIO $ inspectCodeAction cas ["add signature"] - executeCodeAction replaceWithStuff - - contents <- documentContents doc - - let expected = [ "{-# OPTIONS_GHC -Wall #-}" - , "module TopLevelSignature where" - , "main :: IO ()" - , "main = do" - , " putStrLn \"Hello\"" - , " return ()" - ] - - liftIO $ T.lines contents @?= expected - ] - -unusedTermTests :: TestTree -unusedTermTests = testGroup "unused term code actions" [ - ignoreTestBecause "no support for prefixing unused names with _" $ testCase "Prefixes with '_'" $ - runSession hlsCommand fullCaps "test/testdata/" $ do - doc <- openDoc "UnusedTerm.hs" "haskell" - - _ <- waitForDiagnosticsFromSource doc (T.unpack sourceTypecheck) - cars <- getAllCodeActions doc - prefixImUnused <- liftIO $ inspectCodeAction cars ["Prefix imUnused with _"] - - executeCodeAction prefixImUnused - - edit <- skipManyTill anyMessage $ getDocumentEdit doc - - let expected = [ "{-# OPTIONS_GHC -Wall #-}" - , "module UnusedTerm () where" - , "_imUnused :: Int -> Int" - , "_imUnused 1 = 1" - , "_imUnused 2 = 2" - , "_imUnused _ = 3" - ] - - liftIO $ edit @?= T.unlines expected - - -- See https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#textDocument_codeAction - -- `CodeActionContext` - , testCase "respect 'only' parameter" $ runSession hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "CodeActionOnly.hs" "haskell" - _ <- waitForDiagnosticsFrom doc - diags <- getCurrentDiagnostics doc - let params = CodeActionParams Nothing Nothing doc (Range (Position 1 0) (Position 4 0)) caContext - caContext = CodeActionContext diags (Just [CodeActionKind_Refactor]) Nothing - caContextAllActions = CodeActionContext diags Nothing Nothing - -- Verify that we get code actions of at least two different kinds. - TResponseMessage _ _ (Right res) - <- request SMethod_TextDocumentCodeAction (params & L.context .~ caContextAllActions) - liftIO $ do - let cas = map fromAction $ absorbNull res - kinds = map (^. L.kind) cas - assertBool "Test precondition failed" $ Just CodeActionKind_QuickFix `elem` kinds - -- Verify that that when we set the only parameter, we only get actions - -- of the right kind. - TResponseMessage _ _ (Right res) <- request SMethod_TextDocumentCodeAction params - liftIO $ do - let cas = map fromAction $ absorbNull res - kinds = map (^. L.kind) cas - assertBool "Quick fixes should have been filtered out" - $ Just CodeActionKind_QuickFix `notElem` kinds - ] - -testConfig :: Config -testConfig = def { - formattingProvider = "none" - } - - diff --git a/test/functional/Highlight.hs b/test/functional/Highlight.hs deleted file mode 100644 index 28b2a2d393..0000000000 --- a/test/functional/Highlight.hs +++ /dev/null @@ -1,22 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} -module Highlight (tests) where - -import Test.Hls -import Test.Hls.Command - -tests :: TestTree -tests = testGroup "highlight" [ - testCase "works" $ runSession (hlsCommand ++ " --test") fullCaps "test/testdata" $ do - doc <- openDoc "Highlight.hs" "haskell" - _ <- waitForDiagnosticsFrom doc - highlights <- getHighlights doc (Position 2 2) - liftIO $ do - let hls = - [ DocumentHighlight (mkRange 2 0 2 3) (Just DocumentHighlightKind_Write) - , DocumentHighlight (mkRange 4 22 4 25) (Just DocumentHighlightKind_Read) - , DocumentHighlight (mkRange 3 6 3 9) (Just DocumentHighlightKind_Read) - , DocumentHighlight (mkRange 1 0 1 3) (Just DocumentHighlightKind_Read)] - mapM_ (\x -> x `elem` highlights @? "Contains highlight") hls - ] - where - mkRange sl sc el ec = Range (Position sl sc) (Position el ec) diff --git a/test/functional/Main.hs b/test/functional/Main.hs index 9cf61e05d7..a214f3cd65 100644 --- a/test/functional/Main.hs +++ b/test/functional/Main.hs @@ -1,39 +1,17 @@ module Main where -import Command -import Completion import Config -import Deferred -import Definition -import Diagnostic import Format import FunctionalBadProject -import FunctionalCodeAction import HieBios -import Highlight import Progress -import Reference -import Symbol import Test.Hls -import TypeDefinition main :: IO () -main = defaultTestRunner - $ testGroup - "haskell-language-server" - [ Command.tests - , Completion.tests - , Config.tests - , ignoreInEnv [HostOS Windows, GhcVer GHC90] "Tests gets stuck in ci" $ Deferred.tests - , Definition.tests - , Diagnostic.tests - , ignoreInEnv [HostOS Windows, GhcVer GHC90, GhcVer GHC92] "Tests gets stuck in ci" $ Format.tests - , FunctionalBadProject.tests - , FunctionalCodeAction.tests - , HieBios.tests - , Highlight.tests - , ignoreInEnv [HostOS Windows, GhcVer GHC90] "Tests gets stuck in ci" $ Progress.tests - , Reference.tests - , ignoreInEnv [HostOS Windows, GhcVer GHC90] "Tests gets stuck in ci" $ Symbol.tests - , TypeDefinition.tests - ] +main = defaultTestRunner $ testGroup "haskell-language-server" + [ Config.tests + , ignoreInEnv [HostOS Windows, GhcVer GHC90, GhcVer GHC92] "Tests gets stuck in ci" $ Format.tests + , FunctionalBadProject.tests + , HieBios.tests + , ignoreInEnv [HostOS Windows, GhcVer GHC90] "Tests gets stuck in ci" $ Progress.tests + ] diff --git a/test/functional/Progress.hs b/test/functional/Progress.hs index 6791eb223b..d7a0a4090c 100644 --- a/test/functional/Progress.hs +++ b/test/functional/Progress.hs @@ -18,7 +18,6 @@ import Data.Text (Text, pack) import Ide.Types import Language.LSP.Protocol.Capabilities import qualified Language.LSP.Protocol.Lens as L -import System.FilePath (()) import Test.Hls import Test.Hls.Command import Test.Hls.Flags @@ -29,10 +28,10 @@ tests = testGroup "window/workDoneProgress" [ testCase "sends indefinite progress notifications" $ - runSession hlsCommand progressCaps "test/testdata" $ do - let path = "diagnostics" "Foo.hs" + runSession hlsCommand progressCaps "test/testdata/diagnostics" $ do + let path = "Foo.hs" _ <- openDoc path "haskell" - expectProgressMessages [pack ("Setting up testdata (for " ++ path ++ ")"), "Processing", "Indexing"] [] + expectProgressMessages [pack ("Setting up diagnostics (for " ++ path ++ ")"), "Processing", "Indexing"] [] , requiresEvalPlugin $ testCase "eval plugin sends progress reports" $ runSession hlsCommand progressCaps "plugins/hls-eval-plugin/test/testdata" $ do doc <- openDoc "T1.hs" "haskell" diff --git a/test/functional/Reference.hs b/test/functional/Reference.hs deleted file mode 100644 index 7c9a11e4d1..0000000000 --- a/test/functional/Reference.hs +++ /dev/null @@ -1,31 +0,0 @@ -module Reference (tests) where - -import Control.Lens -import Data.Coerce -import Data.List -import Language.LSP.Protocol.Lens -import Test.Hls -import Test.Hls.Command - -tests :: TestTree -tests = testGroup "references" [ - ignoreTestBecause "Broken" $ testCase "works with definitions" $ runSession hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "References.hs" "haskell" - let pos = Position 2 7 -- foo = bar <-- - refs <- getReferences doc pos True - liftIO $ map (Location (doc ^. uri)) [ - mkRange 4 0 4 3 - , mkRange 8 11 8 14 - , mkRange 7 7 7 10 - , mkRange 4 14 4 17 - , mkRange 4 0 4 3 - , mkRange 2 6 2 9 - ] `isInfixOf` coerce refs @? "Contains references" - -- TODO: Respect withDeclaration parameter - -- ignoreTestBecause "Broken" $ testCase "works without definitions" $ runSession hlsCommand fullCaps "test/testdata" $ do - -- doc <- openDoc "References.hs" "haskell" - -- let pos = Position 2 7 -- foo = bar <-- - -- refs <- getReferences doc pos False - -- liftIO $ refs `shouldNotContain` [Location (doc ^. uri) (mkRange 4 0 4 3)] - ] - where mkRange sl sc el ec = Range (Position sl sc) (Position el ec) diff --git a/test/functional/Symbol.hs b/test/functional/Symbol.hs deleted file mode 100644 index 776296e3ff..0000000000 --- a/test/functional/Symbol.hs +++ /dev/null @@ -1,150 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} -module Symbol (tests) where - -import Control.Lens (_Just, ix, (^?)) -import Data.List -import Language.LSP.Protocol.Capabilities -import qualified Language.LSP.Protocol.Lens as L -import Language.LSP.Test as Test -import Test.Hls -import Test.Hls.Command - -tests :: TestTree -tests = testGroup "document symbols" [ - pre310Tests - , v310Tests - ] - -v310Tests :: TestTree -v310Tests = testGroup "3.10 hierarchical document symbols" [ - testCase "provides nested data types and constructors" $ runSession hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "Symbols.hs" "haskell" - Right symbs <- getDocumentSymbols doc - - let myData = DocumentSymbol "MyData" Nothing SymbolKind_Struct Nothing Nothing myDataR myDataSR (Just [a, b]) - a = DocumentSymbol "A" Nothing SymbolKind_Constructor Nothing Nothing aR aSR Nothing - b = DocumentSymbol "B" Nothing SymbolKind_Constructor Nothing Nothing bR bSR Nothing - let myData' = symbs ^? ix 0 . L.children . _Just . ix 2 - - liftIO $ Just myData == myData' @? "Contains symbol" - - , ignoreTestBecause "extracting symbols from nested wheres not supported" $ testCase "provides nested where functions" $ runSession hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "Symbols.hs" "haskell" - Right symbs <- getDocumentSymbols doc - - let foo = DocumentSymbol "foo" Nothing SymbolKind_Function Nothing Nothing fooR fooSR (Just [bar]) - bar = DocumentSymbol "bar" Nothing SymbolKind_Function Nothing Nothing barR barSR (Just [dog, cat]) - dog = DocumentSymbol "dog" Nothing SymbolKind_Variable Nothing Nothing dogR dogSR (Just mempty) - cat = DocumentSymbol "cat" Nothing SymbolKind_Variable Nothing Nothing catR catSR (Just mempty) - let foo' = symbs ^? ix 0 . L.children . _Just . ix 1 - - liftIO $ Just foo == foo' @? "Contains symbol" - - , ignoreTestBecause "extracting pattern synonym symbols not supported" $ testCase "provides pattern synonyms" $ runSession hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "Symbols.hs" "haskell" - Right symbs <- getDocumentSymbols doc - - let testPattern = DocumentSymbol "TestPattern" - Nothing SymbolKind_Function Nothing Nothing testPatternR testPatternSR (Just mempty) - let testPattern' = symbs ^? ix 0 . L.children . _Just . ix 3 - - liftIO $ Just testPattern == testPattern' @? "Contains symbol" - - , testCase "provides imports" $ runSession hlsCommand fullCaps "test/testdata" $ do - doc <- openDoc "Symbols.hs" "haskell" - Right symbs <- getDocumentSymbols doc - - let imports = DocumentSymbol "imports" Nothing SymbolKind_Module Nothing Nothing importsR importsSR (Just [importDataMaybe]) - importDataMaybe = DocumentSymbol "import Data.Maybe" Nothing SymbolKind_Module Nothing Nothing importDataMaybeR importDataMaybeSR Nothing - let imports' = symbs ^? ix 0 . L.children . _Just . ix 0 - - liftIO $ Just imports == imports' @? "Contains symbol" - ] - -pre310Tests :: TestTree -pre310Tests = testGroup "pre 3.10 symbol information" [ - testCase "provides nested data types and constructors" $ runSession hlsCommand oldCaps "test/testdata" $ do - doc@(TextDocumentIdentifier testUri) <- openDoc "Symbols.hs" "haskell" - Left symbs <- getDocumentSymbols doc - - let myData = SymbolInformation "MyData" SymbolKind_Struct Nothing (Just "Symbols") Nothing (Location testUri myDataR) - a = SymbolInformation "A" SymbolKind_Constructor Nothing (Just "MyData") Nothing (Location testUri aR) - b = SymbolInformation "B" SymbolKind_Constructor Nothing (Just "MyData") Nothing (Location testUri bR) - - liftIO $ [myData, a, b] `isInfixOf` symbs @? "Contains symbols" - - , ignoreTestBecause "extracting symbols from nested wheres not supported" $ testCase "provides nested where functions" $ runSession hlsCommand oldCaps "test/testdata" $ do - doc@(TextDocumentIdentifier testUri) <- openDoc "Symbols.hs" "haskell" - Left symbs <- getDocumentSymbols doc - - let foo = SymbolInformation "foo" SymbolKind_Function Nothing (Just "Symbols") Nothing (Location testUri fooR) - bar = SymbolInformation "bar" SymbolKind_Function Nothing (Just "foo") Nothing (Location testUri barR) - dog = SymbolInformation "dog" SymbolKind_Variable Nothing (Just "bar") Nothing (Location testUri dogR) - cat = SymbolInformation "cat" SymbolKind_Variable Nothing (Just "bar") Nothing (Location testUri catR) - - -- Order is important! - liftIO $ [foo, bar, dog, cat] `isInfixOf` symbs @? "Contains symbols" - - , ignoreTestBecause "extracting pattern synonym symbols not supported" $ testCase "provides pattern synonyms" $ runSession hlsCommand oldCaps "test/testdata" $ do - doc@(TextDocumentIdentifier testUri) <- openDoc "Symbols.hs" "haskell" - Left symbs <- getDocumentSymbols doc - - let testPattern = SymbolInformation "TestPattern" - SymbolKind_Function Nothing (Just "Symbols") Nothing (Location testUri testPatternR) - - liftIO $ testPattern `elem` symbs @? "Contains symbols" - - , testCase "provides imports" $ runSession hlsCommand oldCaps "test/testdata" $ do - doc@(TextDocumentIdentifier testUri) <- openDoc "Symbols.hs" "haskell" - Left symbs <- getDocumentSymbols doc - - let imports = SymbolInformation "imports" SymbolKind_Module Nothing (Just "Symbols") Nothing (Location testUri importsR) - importDataMaybe = SymbolInformation "import Data.Maybe" SymbolKind_Module Nothing (Just "imports") Nothing (Location testUri importDataMaybeR) - - liftIO $ [imports, importDataMaybe] `isInfixOf` symbs @? "Contains symbol" - ] - -oldCaps :: ClientCapabilities -oldCaps = capsForVersion (LSPVersion 3 9) - --- Some common ranges and selection ranges in Symbols.hs -importsR :: Range -importsR = Range (Position 3 0) (Position 3 17) -importsSR :: Range -importsSR = Range (Position 3 0) (Position 3 17) -importDataMaybeR :: Range -importDataMaybeR = Range (Position 3 0) (Position 3 17) -importDataMaybeSR :: Range -importDataMaybeSR = Range (Position 3 0) (Position 3 17) -fooSR :: Range -fooSR = Range (Position 5 0) (Position 7 43) -fooR :: Range -fooR = Range (Position 5 0) (Position 7 43) -barSR :: Range -barSR = Range (Position 6 8) (Position 6 11) -barR :: Range -barR = Range (Position 6 8) (Position 7 43) -dogSR :: Range -dogSR = Range (Position 7 17) (Position 7 20) -dogR :: Range -dogR = Range (Position 7 16) (Position 7 43) -catSR :: Range -catSR = Range (Position 7 22) (Position 7 25) -catR :: Range -catR = Range (Position 7 16) (Position 7 43) -myDataSR :: Range -myDataSR = Range (Position 9 0) (Position 10 22) -myDataR :: Range -myDataR = Range (Position 9 0) (Position 10 22) -aSR :: Range -aSR = Range (Position 9 14) (Position 9 15) -aR :: Range -aR = Range (Position 9 14) (Position 9 19) -bSR :: Range -bSR = Range (Position 10 14) (Position 10 15) -bR :: Range -bR = Range (Position 10 14) (Position 10 22) -testPatternSR :: Range -testPatternSR = Range (Position 13 8) (Position 13 19) -testPatternR :: Range -testPatternR = Range (Position 13 0) (Position 13 27) diff --git a/test/functional/TypeDefinition.hs b/test/functional/TypeDefinition.hs deleted file mode 100644 index c114c4ead1..0000000000 --- a/test/functional/TypeDefinition.hs +++ /dev/null @@ -1,42 +0,0 @@ -module TypeDefinition (tests) where - -import Data.Tuple.Extra (first3) -import System.FilePath (()) -import Test.Hls -import Test.Hls.Command - -tests :: TestTree -tests = testGroup "type definitions" [ - testCase "finds local definition of record variable" - $ getTypeDefinitionTest' 10 23 7 0 - , testCase "finds local definition of newtype variable" - $ getTypeDefinitionTest' 15 21 12 0 - , testCase "finds local definition of sum type variable" - $ getTypeDefinitionTest' 20 13 17 0 - , testCase "finds local definition of sum type constructor" - $ getTypeDefinitionTest' 23 7 17 0 - , testCase "finds non-local definition of type def" - $ getTypeDefinitionTest' 29 19 26 0 - , testCase "find local definition of type def" - $ getTypeDefinitionTest' 34 16 31 0 - , testCase "find type-definition of type def in component" - $ getTypeDefinitionTest ("src/Lib2.hs", 12, 20) [("src/Lib.hs", 7, 0)] - , testCase "find definition of parameterized data type" - $ getTypeDefinitionTest ("src/Lib.hs", 39, 19) [ ("src/Lib.hs", 36, 0) - , ("src/Lib.hs", 38, 0)] - ] - -definitionsPath :: FilePath -definitionsPath = "test/testdata/gototest" - -getTypeDefinitionTest :: SymbolLocation -> [SymbolLocation] -> Assertion -getTypeDefinitionTest (symbolFile, symbolLine, symbolCol) definitionLocations = - failIfSessionTimeout . runSession (hlsCommand ++ " --test") fullCaps definitionsPath $ do - doc <- openDoc symbolFile "haskell" - InL (Definition (InR defs)) <- getTypeDefinitions doc $ Position symbolLine symbolCol - liftIO $ defs `expectSameLocations` map (first3 (definitionsPath )) definitionLocations - -getTypeDefinitionTest' :: UInt -> UInt -> UInt -> UInt -> Assertion -getTypeDefinitionTest' symbolLine symbolCol definitionLine definitionCol = - getTypeDefinitionTest ("src/Lib.hs", symbolLine, symbolCol) - [("src/Lib.hs", definitionLine, definitionCol)] diff --git a/test/testdata/CodeActionImport.hs b/test/testdata/CodeActionImport.hs deleted file mode 100644 index 95520bbd2f..0000000000 --- a/test/testdata/CodeActionImport.hs +++ /dev/null @@ -1,2 +0,0 @@ -main :: IO () -main = when True $ putStrLn "hello" \ No newline at end of file diff --git a/test/testdata/CodeActionOnly.hs b/test/testdata/CodeActionOnly.hs deleted file mode 100644 index 1f8a403c8a..0000000000 --- a/test/testdata/CodeActionOnly.hs +++ /dev/null @@ -1,3 +0,0 @@ -module CodeActionOnly where -foo = bar - where bar = id Nothing \ No newline at end of file diff --git a/test/testdata/CodeActionRename.hs b/test/testdata/CodeActionRename.hs deleted file mode 100644 index 457d983b88..0000000000 --- a/test/testdata/CodeActionRename.hs +++ /dev/null @@ -1,2 +0,0 @@ -main = butStrLn "hello" -foo = putStrn "world" diff --git a/test/testdata/FuncTest.hs b/test/testdata/FuncTest.hs deleted file mode 100644 index 99ee963164..0000000000 --- a/test/testdata/FuncTest.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Main where - -main = putStrLn "hello" - -foo :: Int -foo = bb - -bb = 5 - -baz = do - putStrLn "hello" - -f x = x+1 \ No newline at end of file diff --git a/test/testdata/FuncTestError.hs b/test/testdata/FuncTestError.hs deleted file mode 100644 index 48b47a22b6..0000000000 --- a/test/testdata/FuncTestError.hs +++ /dev/null @@ -1,15 +0,0 @@ -module Main where - -main = putStrLn "hello" - -foo :: Int -foo = bb - -bb = 5 - -bug -- no hlint returned because of this, despite redundant do below - -baz = do - putStrLn "hello" - -f x = x+1 diff --git a/test/testdata/FuncTestFail.hs b/test/testdata/FuncTestFail.hs deleted file mode 100644 index ac61d11137..0000000000 --- a/test/testdata/FuncTestFail.hs +++ /dev/null @@ -1,2 +0,0 @@ -main :: IO Int -main = return "yow diff --git a/test/testdata/Highlight.hs b/test/testdata/Highlight.hs deleted file mode 100644 index b58460b896..0000000000 --- a/test/testdata/Highlight.hs +++ /dev/null @@ -1,5 +0,0 @@ -module Highlight where -foo :: Int -foo = 3 -bar = foo - where baz = let x = foo in id x diff --git a/test/testdata/Hover.hs b/test/testdata/Hover.hs deleted file mode 100644 index 977816c68f..0000000000 --- a/test/testdata/Hover.hs +++ /dev/null @@ -1,2 +0,0 @@ -main :: IO Int -main = return $ sum [1,2,3] diff --git a/test/testdata/References.hs b/test/testdata/References.hs deleted file mode 100644 index 34eb8c4e25..0000000000 --- a/test/testdata/References.hs +++ /dev/null @@ -1,9 +0,0 @@ -main = return () - -foo = bar - -bar = let x = bar 42 in const "hello" - -baz = do - x <- bar 23 - return $ bar 14 diff --git a/test/testdata/Symbols.hs b/test/testdata/Symbols.hs deleted file mode 100644 index 4b36275306..0000000000 --- a/test/testdata/Symbols.hs +++ /dev/null @@ -1,14 +0,0 @@ -{-# LANGUAGE PatternSynonyms #-} -module Symbols where - -import Data.Maybe - -foo = bar - where bar = 42 + dog - where (dog, cat) = (1234, "meow") - -data MyData = A Int - | B String - -pattern TestPattern :: Int -> MyData -pattern TestPattern x = A x diff --git a/test/testdata/TopLevelSignature.hs b/test/testdata/TopLevelSignature.hs deleted file mode 100644 index 71322f2edc..0000000000 --- a/test/testdata/TopLevelSignature.hs +++ /dev/null @@ -1,5 +0,0 @@ -{-# OPTIONS_GHC -Wall #-} -module TopLevelSignature where -main = do - putStrLn "Hello" - return () diff --git a/test/testdata/TypedHoles.hs b/test/testdata/TypedHoles.hs deleted file mode 100644 index a471d611b3..0000000000 --- a/test/testdata/TypedHoles.hs +++ /dev/null @@ -1,3 +0,0 @@ -module TypedHoles where -foo :: [Int] -> Int -foo x = _ \ No newline at end of file diff --git a/test/testdata/TypedHoles2.hs b/test/testdata/TypedHoles2.hs deleted file mode 100644 index cc10d249cf..0000000000 --- a/test/testdata/TypedHoles2.hs +++ /dev/null @@ -1,6 +0,0 @@ -module TypedHoles2 (foo2) where -newtype A = A Int -foo2 :: [A] -> A -foo2 x = _ - where - stuff (A a) = A (a + 1) diff --git a/test/testdata/UnusedTerm.hs b/test/testdata/UnusedTerm.hs deleted file mode 100644 index e49c2e8d07..0000000000 --- a/test/testdata/UnusedTerm.hs +++ /dev/null @@ -1,6 +0,0 @@ -{-# OPTIONS_GHC -Wall #-} -module UnusedTerm () where -imUnused :: Int -> Int -imUnused 1 = 1 -imUnused 2 = 2 -imUnused _ = 3 diff --git a/test/testdata/addPackageTest/cabal-exe/AddPackage.hs b/test/testdata/addPackageTest/cabal-exe/AddPackage.hs deleted file mode 100644 index e1bbc6678d..0000000000 --- a/test/testdata/addPackageTest/cabal-exe/AddPackage.hs +++ /dev/null @@ -1,3 +0,0 @@ -import Data.Text -foo = pack "I'm a Text" -main = putStrLn "hello" diff --git a/test/testdata/addPackageTest/cabal-exe/add-package-test.cabal b/test/testdata/addPackageTest/cabal-exe/add-package-test.cabal deleted file mode 100644 index edd2a92a70..0000000000 --- a/test/testdata/addPackageTest/cabal-exe/add-package-test.cabal +++ /dev/null @@ -1,14 +0,0 @@ -name: add-package-test -version: 0.1.0.0 -license: BSD3 -author: Luke Lau -maintainer: luke_lau@icloud.com -build-type: Simple -extra-source-files: ChangeLog.md -cabal-version: >=1.10 - -executable AddPackage - exposed-modules: ./. - main-is: AddPackage.hs - build-depends: base >=4.7 && <5 - default-language: Haskell2010 \ No newline at end of file diff --git a/test/testdata/addPackageTest/cabal-lib/AddPackage.hs b/test/testdata/addPackageTest/cabal-lib/AddPackage.hs deleted file mode 100644 index 24015b598e..0000000000 --- a/test/testdata/addPackageTest/cabal-lib/AddPackage.hs +++ /dev/null @@ -1,4 +0,0 @@ -module AddPackage where - -import Data.Text -foo = pack "I'm a Text" \ No newline at end of file diff --git a/test/testdata/addPackageTest/cabal-lib/add-package-test.cabal b/test/testdata/addPackageTest/cabal-lib/add-package-test.cabal deleted file mode 100644 index f979fe1f64..0000000000 --- a/test/testdata/addPackageTest/cabal-lib/add-package-test.cabal +++ /dev/null @@ -1,14 +0,0 @@ -name: add-package-test -version: 0.1.0.0 -license: BSD3 -author: Luke Lau -maintainer: luke_lau@icloud.com -build-type: Simple -extra-source-files: ChangeLog.md -cabal-version: >=1.10 - -library - exposed-modules: AddPackage - build-depends: base >=4.7 && <5 - -- hs-source-dirs: - default-language: Haskell2010 diff --git a/test/testdata/addPackageTest/hpack-exe/app/Asdf.hs b/test/testdata/addPackageTest/hpack-exe/app/Asdf.hs deleted file mode 100644 index fdd639ffe3..0000000000 --- a/test/testdata/addPackageTest/hpack-exe/app/Asdf.hs +++ /dev/null @@ -1,5 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -import Codec.Compression.GZip - -main = return $ compress "hello" \ No newline at end of file diff --git a/test/testdata/addPackageTest/hpack-exe/asdf.cabal b/test/testdata/addPackageTest/hpack-exe/asdf.cabal deleted file mode 100644 index e39c61d39c..0000000000 --- a/test/testdata/addPackageTest/hpack-exe/asdf.cabal +++ /dev/null @@ -1,37 +0,0 @@ -cabal-version: 1.12 - --- This file has been generated from package.yaml by hpack version 0.32.0. --- --- see: https://github.com/sol/hpack --- --- hash: 69241e1f4f912f034502d225d2017f035c38062080733108c11cd3d111cb9007 - -name: asdf -version: 0.1.0.0 -description: Please see the README on GitHub at -homepage: https://github.com/githubuser/asdf#readme -bug-reports: https://github.com/githubuser/asdf/issues -author: Author name here -maintainer: example@example.com -copyright: 2018 Author name here -license: BSD3 -build-type: Simple -extra-source-files: - README.md - ChangeLog.md - -source-repository head - type: git - location: https://github.com/githubuser/asdf - -executable asdf-exe - main-is: Main.hs - other-modules: - Asdf - Paths_asdf - hs-source-dirs: - app - ghc-options: -threaded -rtsopts -with-rtsopts=-N - build-depends: - base >=4.7 && <5 - default-language: Haskell2010 diff --git a/test/testdata/addPackageTest/hpack-lib/app/Asdf.hs b/test/testdata/addPackageTest/hpack-lib/app/Asdf.hs deleted file mode 100644 index ec4b229117..0000000000 --- a/test/testdata/addPackageTest/hpack-lib/app/Asdf.hs +++ /dev/null @@ -1,7 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module Asdf where - -import Codec.Compression.GZip - -main = return $ compress "hello" \ No newline at end of file diff --git a/test/testdata/addPackageTest/invalid/AddPackage.hs b/test/testdata/addPackageTest/invalid/AddPackage.hs deleted file mode 100644 index 963020508b..0000000000 --- a/test/testdata/addPackageTest/invalid/AddPackage.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Data.Text -foo = pack "I'm a Text" \ No newline at end of file diff --git a/test/testdata/badProjects/cabal/Foo.hs b/test/testdata/badProjects/cabal/Foo.hs deleted file mode 100644 index d2c06e960d..0000000000 --- a/test/testdata/badProjects/cabal/Foo.hs +++ /dev/null @@ -1,4 +0,0 @@ -module Foo where - -foo :: Int -foo = 3 diff --git a/test/testdata/badProjects/cabal/bad-cabal.cabal b/test/testdata/badProjects/cabal/bad-cabal.cabal deleted file mode 100644 index 28414e8314..0000000000 --- a/test/testdata/badProjects/cabal/bad-cabal.cabal +++ /dev/null @@ -1,16 +0,0 @@ -name: bad-cabal -version: 0.1.0.0 -license: BSD3 -author: Alan Zimmerman -maintainer: alan.zimm@gmail.com -build-type: Simple -extra-source-files: ChangeLog.md -cabal-version: >=1.10 - -library - exposed-modules: Foo - build-depends: base >=4.7 && <5 - -- missing dependency - , does-not-exist - -- hs-source-dirs: - default-language: Haskell2010 diff --git a/test/testdata/completion/AssociatedTypeFamily.hs b/test/testdata/completion/AssociatedTypeFamily.hs deleted file mode 100644 index f50c1e20cf..0000000000 --- a/test/testdata/completion/AssociatedTypeFamily.hs +++ /dev/null @@ -1,8 +0,0 @@ -{-# LANGUAGE TypeFamilies #-} -module AssociatedTypeFamily () where - -class C a where - type Fam a - -x :: C a => a -> Fam a -x = undefined diff --git a/test/testdata/completion/Context.hs b/test/testdata/completion/Context.hs deleted file mode 100644 index 0f3d350879..0000000000 --- a/test/testdata/completion/Context.hs +++ /dev/null @@ -1,4 +0,0 @@ -module Context where -import Control.Concurrent as Conc -foo :: Int -> Int -> Conc.MVar -foo x = abs 42 diff --git a/test/testdata/completion/DupRecFields.hs b/test/testdata/completion/DupRecFields.hs deleted file mode 100644 index 8ba3148d3a..0000000000 --- a/test/testdata/completion/DupRecFields.hs +++ /dev/null @@ -1,5 +0,0 @@ -{-# LANGUAGE DuplicateRecordFields #-} -module DupRecFields where - -newtype One = One { accessor :: Int } -newtype Two = Two { accessor :: Int } diff --git a/test/testdata/completion/FunctionCompletions.hs b/test/testdata/completion/FunctionCompletions.hs deleted file mode 100644 index eeda925498..0000000000 --- a/test/testdata/completion/FunctionCompletions.hs +++ /dev/null @@ -1,8 +0,0 @@ -import Control.Applicative (Alternative) -import qualified Data.List - -main :: IO () -main = putStrLn "hello" - -foo :: Either a b -> Either a b -foo = id diff --git a/test/testdata/completion/RecordDotSyntax.hs b/test/testdata/completion/RecordDotSyntax.hs deleted file mode 100644 index 4ea2f6994b..0000000000 --- a/test/testdata/completion/RecordDotSyntax.hs +++ /dev/null @@ -1,28 +0,0 @@ -{-# LANGUAGE OverloadedRecordDot #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE NoFieldSelectors #-} - -module Test where - -import qualified Data.Maybe as M - -data MyRecord = MyRecord1 - { a :: String - , b :: Integer - , c :: MyChild - } - | MyRecord2 { a2 :: String - , b2 :: Integer - , c2 :: MyChild - } deriving (Eq, Show) - -newtype MyChild = MyChild - { z :: String - } deriving (Eq, Show) - -x = MyRecord1 { a = "Hello", b = 12, c = MyChild { z = "there" } } - -y = x.a ++ show x.b - -y2 = x.c.z - diff --git a/test/testdata/completion/completions.cabal b/test/testdata/completion/completions.cabal deleted file mode 100644 index 8949d28622..0000000000 --- a/test/testdata/completion/completions.cabal +++ /dev/null @@ -1,10 +0,0 @@ -name: completions -version: 0.1.0.0 -cabal-version: 2.0 -build-type: Simple - -executable compl-exe - other-modules: DupRecFields, Context - main-is: Completion.hs - default-language: Haskell2010 - build-depends: base diff --git a/test/testdata/completion/hie.yaml b/test/testdata/completion/hie.yaml index 6e631ae549..8f2eee1478 100644 --- a/test/testdata/completion/hie.yaml +++ b/test/testdata/completion/hie.yaml @@ -2,6 +2,4 @@ cradle: direct: arguments: - "Completion" - - "Context" - - "DupRecFields" - "FieldsSharingSignature" diff --git a/test/testdata/context/ExampleContext.hs b/test/testdata/context/ExampleContext.hs deleted file mode 100644 index 324d055282..0000000000 --- a/test/testdata/context/ExampleContext.hs +++ /dev/null @@ -1,20 +0,0 @@ -module ExampleContext (foo) where - -import Data.List (find) -import Control.Monad hiding (fix) - -foo :: Int -> Int -foo xs = bar xs + 1 - where - bar :: Int -> Int - bar x = x + 2 - -data Foo a = Foo a - deriving (Show) - -class Bar a where - bar :: a -> Integer - -instance Integral a => Bar (Foo a) where - bar (Foo a) = toInteger a - diff --git a/test/testdata/context/Foo/Bar.hs b/test/testdata/context/Foo/Bar.hs deleted file mode 100644 index 0d6044ee85..0000000000 --- a/test/testdata/context/Foo/Bar.hs +++ /dev/null @@ -1,3 +0,0 @@ -module Foo.Bar where - - diff --git a/test/testdata/definition/Bar.hs b/test/testdata/definition/Bar.hs deleted file mode 100644 index 9ae116114e..0000000000 --- a/test/testdata/definition/Bar.hs +++ /dev/null @@ -1,9 +0,0 @@ -module Bar where - -a = 42 - --- These blank lines are here --- to ensure that b is defined --- on a line number larger than --- the number of lines in Foo.hs. -b = 43 diff --git a/test/testdata/definition/Foo.hs b/test/testdata/definition/Foo.hs deleted file mode 100644 index ca73e2d375..0000000000 --- a/test/testdata/definition/Foo.hs +++ /dev/null @@ -1,6 +0,0 @@ -module Foo (module Bar) where - -import Bar - -fortyTwo = a -fortyThree = b diff --git a/test/testdata/definition/definitions.cabal b/test/testdata/definition/definitions.cabal deleted file mode 100644 index cde0040a7e..0000000000 --- a/test/testdata/definition/definitions.cabal +++ /dev/null @@ -1,10 +0,0 @@ -name: definitions -version: 0.1.0.0 -cabal-version: 2.0 -build-type: Simple - -library - exposed-modules: Foo - other-modules: Bar - default-language: Haskell2010 - build-depends: base diff --git a/test/testdata/diagnostics/hie.yaml b/test/testdata/diagnostics/hie.yaml new file mode 100644 index 0000000000..dd3a73237e --- /dev/null +++ b/test/testdata/diagnostics/hie.yaml @@ -0,0 +1,5 @@ +cradle: + direct: + arguments: + - Foo + - -Wmissing-signatures diff --git a/test/testdata/definition/hie.yaml b/test/testdata/format/hie.yaml similarity index 54% rename from test/testdata/definition/hie.yaml rename to test/testdata/format/hie.yaml index 9adb47d0f3..24eab13a43 100644 --- a/test/testdata/definition/hie.yaml +++ b/test/testdata/format/hie.yaml @@ -1,5 +1,4 @@ cradle: direct: arguments: - - "Foo" - - "Bar" + - Format diff --git a/test/testdata/gototest/hie.yaml b/test/testdata/gototest/hie.yaml deleted file mode 100644 index 94c8271c18..0000000000 --- a/test/testdata/gototest/hie.yaml +++ /dev/null @@ -1,6 +0,0 @@ -cradle: - direct: - arguments: - - "-i src/" - - "Lib" - - "Lib2" diff --git a/test/testdata/gototest/src/Lib.hs b/test/testdata/gototest/src/Lib.hs deleted file mode 100644 index 5698c76832..0000000000 --- a/test/testdata/gototest/src/Lib.hs +++ /dev/null @@ -1,40 +0,0 @@ -module Lib - - where - -someFunc :: IO () -someFunc = putStrLn "someFunc" - -data DataType = DataType Int - -dataTypeId :: DataType -> DataType -dataTypeId dataType = dataType - -newtype NewType = NewType Int - -newTypeId :: NewType -> NewType -newTypeId newType = newType - -data Enu = First | Second - -enuId :: Enu -> Enu -enuId enu = enu - -toNum :: Enu -> Int -toNum First = 1 -toNum Second = 2 - -type MyInt = Int - -myIntId :: MyInt -> MyInt -myIntId myInt = myInt - -type TypEnu = Enu - -typEnuId :: TypEnu -> TypEnu -typEnuId enu = enu - -data Parameter a = Parameter a - -parameterId :: Parameter a -> Parameter a -parameterId pid = pid diff --git a/test/testdata/gototest/src/Lib2.hs b/test/testdata/gototest/src/Lib2.hs deleted file mode 100644 index c0ef7d46b0..0000000000 --- a/test/testdata/gototest/src/Lib2.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Lib2 where - -import Lib - -g = do - someFunc - print x - where z = 1+2 - y = z+z - x = y*z - -otherId :: DataType -> DataType -otherId dataType = dataType \ No newline at end of file diff --git a/test/testdata/hie.yaml b/test/testdata/hie.yaml deleted file mode 100644 index a8703fdd69..0000000000 --- a/test/testdata/hie.yaml +++ /dev/null @@ -1,12 +0,0 @@ -cradle: - direct: - arguments: - - "-Wmissing-signatures" - - "CodeActionImport" - - "CodeActionOnly" - - "CodeActionRename" - - "Highlight" - - "Symbols" - - "TopLevelSignature" - - "TypedHoles" - - "TypedHoles2" diff --git a/test/testdata/hieBiosMainIs/hie.yaml b/test/testdata/hieBiosMainIs/hie.yaml new file mode 100644 index 0000000000..04cd24395e --- /dev/null +++ b/test/testdata/hieBiosMainIs/hie.yaml @@ -0,0 +1,2 @@ +cradle: + cabal: diff --git a/test/testdata/liquid/Evens.hs b/test/testdata/liquid/Evens.hs deleted file mode 100644 index 38ac14b2be..0000000000 --- a/test/testdata/liquid/Evens.hs +++ /dev/null @@ -1,41 +0,0 @@ -module Main where - -{-@ type Even = {v:Int | v mod 2 = 0} @-} - -{-@ weAreEven :: [Even] @-} -weAreEven = [(0-10), (0-4), 0, 2, 666] - -{-@ notEven :: Even @-} -notEven = 7 - -{-@ isEven :: n:Nat -> {v:Bool | (v <=> (n mod 2 == 0))} @-} -isEven :: Int -> Bool -isEven 0 = True -isEven 1 = False -isEven n = not (isEven (n-1)) - -{-@ evens :: n:Nat -> [Even] @-} -evens n = [i | i <- range 0 n, isEven i] - -{-@ range :: lo:Int -> hi:Int -> [{v:Int | (lo <= v && v < hi)}] / [hi -lo] @-} -range lo hi - | lo < hi = lo : range (lo+1) hi - | otherwise = [] - -{-@ shift :: [Even] -> Even -> [Even] @-} -shift xs k = [x + k | x <- xs] - -{-@ double :: [Nat] -> [Even] @-} -double xs = [x + x | x <- xs] - - - ---- - -notEven :: Int -weAreEven :: [Int] -shift :: [Int] -> Int -> [Int] -double :: [Int] -> [Int] -range :: Int -> Int -> [Int] - -main = putStrLn "hello" diff --git a/test/testdata/redundantImportTest/hie.yaml b/test/testdata/redundantImportTest/hie.yaml deleted file mode 100644 index f9fbdb0e43..0000000000 --- a/test/testdata/redundantImportTest/hie.yaml +++ /dev/null @@ -1,5 +0,0 @@ -cradle: - direct: - arguments: - - "src/CodeActionRedundant" - - "src/MultipleImports" diff --git a/test/testdata/redundantImportTest/src/CodeActionRedundant.hs b/test/testdata/redundantImportTest/src/CodeActionRedundant.hs deleted file mode 100644 index 168868e3b9..0000000000 --- a/test/testdata/redundantImportTest/src/CodeActionRedundant.hs +++ /dev/null @@ -1,10 +0,0 @@ -{-# OPTIONS_GHC -Wunused-imports #-} -{-# LANGUAGE PatternSynonyms #-} -module CodeActionRedundant where -import Data.List --- We need a non-reduntant import in the import list --- to properly test the removal of the singular redundant item -import Data.Sequence (pattern Empty, singleton) -main :: IO () -main = putStrLn "hello" - where unused = Data.Sequence.singleton 42 diff --git a/test/testdata/redundantImportTest/src/MultipleImports.hs b/test/testdata/redundantImportTest/src/MultipleImports.hs deleted file mode 100644 index 7a8278b1d3..0000000000 --- a/test/testdata/redundantImportTest/src/MultipleImports.hs +++ /dev/null @@ -1,6 +0,0 @@ -{-# OPTIONS_GHC -Wunused-imports #-} -module MultipleImports where -import Data.Foldable -import Data.Maybe -foo :: Int -foo = fromJust (Just 3) diff --git a/test/testdata/redundantImportTest/test.cabal b/test/testdata/redundantImportTest/test.cabal deleted file mode 100644 index d185920d5b..0000000000 --- a/test/testdata/redundantImportTest/test.cabal +++ /dev/null @@ -1,18 +0,0 @@ -name: test -version: 0.1.0.0 --- synopsis: --- description: -license: BSD3 -author: Author name here -maintainer: example@example.com -copyright: 2017 Author name here -category: Web -build-type: Simple -cabal-version: >=1.10 - -library - exposed-modules: CodeActionRedundant, MultipleImports - hs-source-dirs: src - build-depends: base >= 4.7 && < 5 - default-language: Haskell2010 - ghc-options: -Wall -fwarn-unused-imports \ No newline at end of file diff --git a/test/testdata/testdata.cabal b/test/testdata/testdata.cabal deleted file mode 100644 index 279424e6b2..0000000000 --- a/test/testdata/testdata.cabal +++ /dev/null @@ -1,37 +0,0 @@ -name: testdata -version: 0.1.0.0 -cabal-version: 2.0 -build-type: Simple - -executable codeactionrename - build-depends: base - main-is: CodeActionRename.hs - default-language: Haskell2010 - -executable codeactiononly - build-depends: base - main-is: CodeActionOnly.hs - default-language: Haskell2010 - - - -executable hover - build-depends: base - main-is: Hover.hs - default-language: Haskell2010 - -executable symbols - build-depends: base - main-is: Symbols.hs - default-language: Haskell2010 - -executable functests - build-depends: base - main-is: FuncTest.hs - default-language: Haskell2010 - -executable evens - build-depends: base - main-is: Evens.hs - hs-source-dirs: liquid - default-language: Haskell2010 diff --git a/test/testdata/wErrorTest/cabal.project b/test/testdata/wErrorTest/cabal.project deleted file mode 100644 index 52db9d1bc4..0000000000 --- a/test/testdata/wErrorTest/cabal.project +++ /dev/null @@ -1 +0,0 @@ -packages: test.cabal diff --git a/test/testdata/wErrorTest/hie.yaml b/test/testdata/wErrorTest/hie.yaml deleted file mode 100644 index aa4b2f058f..0000000000 --- a/test/testdata/wErrorTest/hie.yaml +++ /dev/null @@ -1,4 +0,0 @@ -cradle: - cabal: - - path: "src" - component: "lib:test" diff --git a/test/testdata/wErrorTest/src/WError.hs b/test/testdata/wErrorTest/src/WError.hs deleted file mode 100644 index 70db26840d..0000000000 --- a/test/testdata/wErrorTest/src/WError.hs +++ /dev/null @@ -1,3 +0,0 @@ -module WError where -{-# ANN module "HLint: ignore" #-} -main = undefined diff --git a/test/testdata/wErrorTest/test.cabal b/test/testdata/wErrorTest/test.cabal deleted file mode 100644 index 4ce7fc3b9a..0000000000 --- a/test/testdata/wErrorTest/test.cabal +++ /dev/null @@ -1,18 +0,0 @@ -name: test -version: 0.1.0.0 --- synopsis: --- description: -license: BSD3 -author: Author name here -maintainer: example@example.com -copyright: 2017 Author name here -category: Web -build-type: Simple -cabal-version: >=1.10 - -library - exposed-modules: WError - hs-source-dirs: src - build-depends: base >= 4.7 && < 5 - default-language: Haskell2010 - ghc-options: -Wall -Werror diff --git a/test/utils/Test/Hls/Command.hs b/test/utils/Test/Hls/Command.hs index 90b1f62b7d..c8e7d4de45 100644 --- a/test/utils/Test/Hls/Command.hs +++ b/test/utils/Test/Hls/Command.hs @@ -1,18 +1,11 @@ module Test.Hls.Command - ( hlsCommand, - hlsCommandExamplePlugin, - hlsCommandVomit, - logFilePath, + ( hlsCommand ) where import Data.Maybe (fromMaybe) import System.Environment (lookupEnv) import System.IO.Unsafe (unsafePerformIO) -import Test.Hls - -logFilePath :: String -logFilePath = "hls-" ++ show ghcVersion ++ ".log" -- | The command to execute the version of hls for the current compiler. -- @@ -24,9 +17,3 @@ hlsCommand :: String hlsCommand = unsafePerformIO $ do testExe <- fromMaybe "haskell-language-server" <$> lookupEnv "HLS_TEST_EXE" pure $ testExe ++ " --lsp -d -j4" - -hlsCommandVomit :: String -hlsCommandVomit = hlsCommand ++ " --vomit" - -hlsCommandExamplePlugin :: String -hlsCommandExamplePlugin = hlsCommand ++ " --example"