From cc884c286f0fd97e892e669a118096c6b4037043 Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 20 Oct 2021 09:42:16 +0200 Subject: [PATCH 01/13] Move hlint tests to its package --- hls-test-utils/src/Test/Hls.hs | 12 +- hls-test-utils/src/Test/Hls/Util.hs | 7 + .../hls-hlint-plugin/hls-hlint-plugin.cabal | 17 ++ plugins/hls-hlint-plugin/test/Main.hs | 210 ++++++++++++++++++ .../test/testdata}/ApplyRefact1.hs | 0 .../test/testdata}/ApplyRefact2.hs | 0 .../test/testdata}/ApplyRefact3.hs | 0 .../test/testdata}/ApplyRefact4.hs | 0 .../test/testdata}/ApplyRefact5.hs | 0 .../test/testdata}/ApplyRefact6.hs | 0 .../test/testdata}/ApplyRefact7.hs | 0 .../test/testdata}/ApplyRefact8.hs | 0 .../test/testdata}/cpp/ApplyRefact2.hs | 0 .../test/testdata}/cpp/ApplyRefact3.hs | 0 .../test/testdata}/cpp/hie.yaml | 0 .../test/testdata}/cpp/test.h | 0 .../hls-hlint-plugin/test/testdata}/hie.yaml | 0 .../test/testdata}/ignore/.hlint.yaml | 0 .../test/testdata}/ignore/ApplyRefact.hs | 0 .../test/testdata}/ignore/hie.yaml | 0 .../test/testdata}/lambdacase/ApplyRefact1.hs | 0 .../test/testdata}/lambdacase/hie.yaml | 0 .../test/testdata}/test-hlint-config.yaml | 0 .../test/testdata}/typeapps/ApplyRefact1.hs | 0 .../test/testdata}/typeapps/hie.yaml | 0 test/functional/FunctionalCodeAction.hs | 204 +---------------- 26 files changed, 244 insertions(+), 206 deletions(-) create mode 100644 plugins/hls-hlint-plugin/test/Main.hs rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/ApplyRefact1.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/ApplyRefact2.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/ApplyRefact3.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/ApplyRefact4.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/ApplyRefact5.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/ApplyRefact6.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/ApplyRefact7.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/ApplyRefact8.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/cpp/ApplyRefact2.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/cpp/ApplyRefact3.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/cpp/hie.yaml (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/cpp/test.h (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/hie.yaml (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/ignore/.hlint.yaml (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/ignore/ApplyRefact.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/ignore/hie.yaml (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/lambdacase/ApplyRefact1.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/lambdacase/hie.yaml (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/test-hlint-config.yaml (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/typeapps/ApplyRefact1.hs (100%) rename {test/testdata/hlint => plugins/hls-hlint-plugin/test/testdata}/typeapps/hie.yaml (100%) diff --git a/hls-test-utils/src/Test/Hls.hs b/hls-test-utils/src/Test/Hls.hs index 512ae1b744..dfbbb8dac4 100644 --- a/hls-test-utils/src/Test/Hls.hs +++ b/hls-test-utils/src/Test/Hls.hs @@ -24,8 +24,10 @@ module Test.Hls waitForAllProgressDone, PluginDescriptor, IdeState, - waitForBuildQueue - ,waitForTypecheck,waitForAction) + waitForBuildQueue, + waitForTypecheck, + waitForAction, + sendConfigurationChanged) where import Control.Applicative.Combinators @@ -222,8 +224,12 @@ waitForAction key TextDocumentIdentifier{_uri} = do return $ do e <- _result case A.fromJSON e of - A.Error e -> Left $ ResponseError InternalError (T.pack e) Nothing + A.Error err -> Left $ ResponseError InternalError (T.pack err) Nothing A.Success a -> pure a waitForTypecheck :: TextDocumentIdentifier -> Session (Either ResponseError Bool) waitForTypecheck tid = fmap ideResultSuccess <$> waitForAction "typecheck" tid + +sendConfigurationChanged :: Config -> Session () +sendConfigurationChanged config = + sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) diff --git a/hls-test-utils/src/Test/Hls/Util.hs b/hls-test-utils/src/Test/Hls/Util.hs index 05e06b7d64..9add1ca02f 100644 --- a/hls-test-utils/src/Test/Hls/Util.hs +++ b/hls-test-utils/src/Test/Hls/Util.hs @@ -22,6 +22,7 @@ module Test.Hls.Util , ghcVersion, GhcVersion(..) , hostOS, OS(..) , matchesCurrentEnv, EnvSpec(..) + , noLiteralCaps , ignoreForGhcVersions , ignoreInEnv , inspectCodeAction @@ -74,6 +75,12 @@ import Test.Tasty.HUnit (Assertion, assertFailure, import Text.Blaze.Internal hiding (null) import Text.Blaze.Renderer.String (renderMarkup) +noLiteralCaps :: C.ClientCapabilities +noLiteralCaps = def { C._textDocument = Just textDocumentCaps } + where + textDocumentCaps = def { C._codeAction = Just codeActionCaps } + codeActionCaps = CodeActionClientCapabilities (Just True) Nothing Nothing Nothing Nothing Nothing Nothing + codeActionSupportCaps :: C.ClientCapabilities codeActionSupportCaps = def { C._textDocument = Just textDocumentCaps } where diff --git a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal index 3153e1cb33..880f37440a 100644 --- a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal +++ b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal @@ -101,3 +101,20 @@ library default-extensions: DataKinds TypeOperators + +test-suite tests + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: test + main-is: Main.hs + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + aeson + , base + , filepath + , hls-hlint-plugin + , hls-plugin-api + , hls-test-utils >=1.0 && <1.2 + , lens + , lsp-types + , text diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs new file mode 100644 index 0000000000..ae2e790916 --- /dev/null +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -0,0 +1,210 @@ +{-# LANGUAGE OverloadedStrings #-} +module Main + ( main + ) where + +import Control.Lens ((^.)) +import Data.Aeson (toJSON) +import Data.List (find) +import Data.Maybe (fromJust, isJust) +import qualified Data.Text as T +import qualified Ide.Plugin.Hlint as HLint +import Ide.Plugin.Config (hlintOn) +import qualified Language.LSP.Types.Lens as L +import System.FilePath (()) +import Test.Hls + +main :: IO () +main = defaultTestRunner tests + +hlintPlugin :: PluginDescriptor IdeState +hlintPlugin = HLint.descriptor "hlint" + +tests :: TestTree +tests = + testGroup "hlint suggestions" [ + testCase "provides 3.8 code actions including apply all" $ runHlintSession "" $ do + doc <- openDoc "ApplyRefact2.hs" "haskell" + diags@(reduceDiag:_) <- waitForDiagnosticsFromSource doc "hlint" + + liftIO $ do + length diags @?= 2 -- "Eta Reduce" and "Redundant Id" + reduceDiag ^. L.range @?= Range (Position 1 0) (Position 1 12) + reduceDiag ^. L.severity @?= Just DsInfo + reduceDiag ^. L.code @?= Just (InR "refact:Eta reduce") + reduceDiag ^. L.source @?= Just "hlint" + + cas <- map fromAction <$> getAllCodeActions doc + + let applyAll = find (\ca -> "Apply all hints" `T.isSuffixOf` (ca ^. L.title)) cas + let redId = find (\ca -> "Redundant id" `T.isSuffixOf` (ca ^. L.title)) cas + let redEta = find (\ca -> "Eta reduce" `T.isSuffixOf` (ca ^. L.title)) cas + + liftIO $ isJust applyAll @? "There is 'Apply all hints' code action" + liftIO $ isJust redId @? "There is 'Redundant id' code action" + liftIO $ isJust redEta @? "There is 'Eta reduce' code action" + + executeCodeAction (fromJust redId) + + contents <- skipManyTill anyMessage $ getDocumentEdit doc + liftIO $ contents @?= "main = undefined\nfoo x = x\n" + + , testCase "falls back to pre 3.8 code actions" $ runSessionWithServer' [hlintPlugin] def def noLiteralCaps "test/testdata" $ do + doc <- openDoc "ApplyRefact2.hs" "haskell" + + _ <- waitForDiagnosticsFromSource doc "hlint" + + cars <- getAllCodeActions doc + etaReduce <- liftIO $ inspectCommand cars ["Eta reduce"] + + executeCommand etaReduce + + contents <- skipManyTill anyMessage $ getDocumentEdit doc + liftIO $ contents @?= "main = undefined\nfoo = id\n" + + , testCase "changing configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do + let config = def { hlintOn = True } + sendConfigurationChanged config + + doc <- openDoc "ApplyRefact2.hs" "haskell" + testHlintDiagnostics doc + + let config' = def { hlintOn = False } + sendConfigurationChanged config' + + diags' <- waitForDiagnosticsFrom doc + + liftIO $ noHlintDiagnostics diags' + + , testCase "changing document contents updates hlint diagnostics" $ runHlintSession "" $ do + doc <- openDoc "ApplyRefact2.hs" "haskell" + testHlintDiagnostics doc + + let change = TextDocumentContentChangeEvent + (Just (Range (Position 1 8) (Position 1 12))) + Nothing "x" + changeDoc doc [change] + expectNoMoreDiagnostics 3 doc "hlint" + + let change' = TextDocumentContentChangeEvent + (Just (Range (Position 1 8) (Position 1 12))) + Nothing "id x" + changeDoc doc [change'] + testHlintDiagnostics doc + + , knownBrokenForGhcVersions [GHC88, GHC86] "hlint doesn't take in account cpp flag as ghc -D argument" $ + testCase "hlint diagnostics works with CPP via ghc -XCPP argument (#554)" $ runHlintSession "cpp" $ do + doc <- openDoc "ApplyRefact3.hs" "haskell" + testHlintDiagnostics doc + + , knownBrokenForGhcVersions [GHC88, GHC86] "hlint doesn't take in account cpp flag as ghc -D argument" $ + testCase "hlint diagnostics works with CPP via language pragma (#554)" $ runHlintSession "" $ do + doc <- openDoc "ApplyRefact3.hs" "haskell" + testHlintDiagnostics doc + + , testCase "hlint diagnostics works with CPP via -XCPP argument and flag via #include header (#554)" $ runHlintSession "cpp" $ do + doc <- openDoc "ApplyRefact2.hs" "haskell" + testHlintDiagnostics doc + + , testCase "apply-refact works with -XLambdaCase argument (#590)" $ runHlintSession "lambdacase" $ do + testRefactor "ApplyRefact1.hs" "Redundant bracket" + expectedLambdaCase + + , testCase "apply-refact works with -XTypeApplications argument (#1242)" $ runHlintSession "typeapps" $ do + testRefactor "ApplyRefact1.hs" "Redundant bracket" + expectedTypeApp + + , testCase "apply hints works with LambdaCase via language pragma" $ runHlintSession "" $ do + testRefactor "ApplyRefact1.hs" "Redundant bracket" + ("{-# LANGUAGE LambdaCase #-}" : expectedLambdaCase) + + , expectFailBecause "apply-refact doesn't work with cpp" $ + testCase "apply hints works with CPP via -XCPP argument" $ runHlintSession "cpp" $ do + testRefactor "ApplyRefact3.hs" "Redundant bracket" + expectedCPP + + , expectFailBecause "apply-refact doesn't work with cpp" $ + testCase "apply hints works with CPP via language pragma" $ runHlintSession "" $ do + testRefactor "ApplyRefact3.hs" "Redundant bracket" + ("{-# LANGUAGE CPP #-}" : expectedCPP) + + , testCase "hlint diagnostics ignore hints honouring .hlint.yaml" $ runHlintSession "ignore" $ do + doc <- openDoc "ApplyRefact.hs" "haskell" + expectNoMoreDiagnostics 3 doc "hlint" + + , testCase "hlint diagnostics ignore hints honouring ANN annotations" $ runHlintSession "" $ do + doc <- openDoc "ApplyRefact4.hs" "haskell" + expectNoMoreDiagnostics 3 doc "hlint" + + , knownBrokenForGhcVersions [GHC810, GHC90] "hlint plugin doesn't honour HLINT annotations (#838)" $ + testCase "hlint diagnostics ignore hints honouring HLINT annotations" $ runHlintSession "" $ do + doc <- openDoc "ApplyRefact5.hs" "haskell" + expectNoMoreDiagnostics 3 doc "hlint" + + , testCase "apply-refact preserve regular comments" $ runHlintSession "" $ do + testRefactor "ApplyRefact6.hs" "Redundant bracket" expectedComments + + , testCase "applyAll is shown only when there is at least one diagnostic in range" $ runHlintSession "" $ do + doc <- openDoc "ApplyRefact8.hs" "haskell" + _ <- waitForDiagnosticsFromSource doc "hlint" + + firstLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 0 0) + secondLine <- map fromAction <$> getCodeActions doc (mkRange 1 0 1 0) + thirdLine <- map fromAction <$> getCodeActions doc (mkRange 2 0 2 0) + multiLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 2 0) + + let hasApplyAll = isJust . find (\ca -> "Apply all hints" `T.isSuffixOf` (ca ^. L.title)) + + liftIO $ hasApplyAll firstLine @? "Missing apply all code action" + liftIO $ hasApplyAll secondLine @? "Missing apply all code action" + liftIO $ not (hasApplyAll thirdLine) @? "Unexpected apply all code action" + liftIO $ hasApplyAll multiLine @? "Missing apply all code action" + ] + where + runHlintSession :: FilePath -> Session a -> IO a + runHlintSession subdir = + failIfSessionTimeout . runSessionWithServer hlintPlugin ("test/testdata/hlint" subdir) + + noHlintDiagnostics :: [Diagnostic] -> Assertion + noHlintDiagnostics diags = + Just "hlint" `notElem` map (^. L.source) diags @? "There are no hlint diagnostics" + + testHlintDiagnostics doc = do + diags <- waitForDiagnosticsFromSource doc "hlint" + liftIO $ length diags > 0 @? "There are hlint diagnostics" + + testRefactor file caTitle expected = do + doc <- openDoc file "haskell" + testHlintDiagnostics doc + + cas <- map fromAction <$> getAllCodeActions doc + let ca = find (\ca -> caTitle `T.isSuffixOf` (ca ^. L.title)) cas + liftIO $ isJust ca @? ("There is '" ++ T.unpack caTitle ++"' code action") + + executeCodeAction (fromJust ca) + + contents <- skipManyTill anyMessage $ getDocumentEdit doc + liftIO $ contents @?= T.unlines expected + + expectedLambdaCase = [ "module ApplyRefact1 where", "" + , "f = \\case \"true\" -> True" + , " _ -> False" + ] + expectedCPP = [ "module ApplyRefact3 where", "" + , "#ifdef FLAG" + , "f = 1" + , "#else" + , "g = 2" + , "#endif", "" + ] + expectedComments = [ "-- comment before header" + , "module ApplyRefact6 where", "" + , "{-# standalone annotation #-}", "" + , "-- standalone comment", "" + , "-- | haddock comment" + , "f = {- inline comment -}{- inline comment inside refactored code -} 1 -- ending comment", "" + , "-- final comment" + ] + expectedTypeApp = [ "module ApplyRefact1 where", "" + , "a = id @Int 1" + ] diff --git a/test/testdata/hlint/ApplyRefact1.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact1.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact1.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact1.hs diff --git a/test/testdata/hlint/ApplyRefact2.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact2.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact2.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact2.hs diff --git a/test/testdata/hlint/ApplyRefact3.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact3.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact3.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact3.hs diff --git a/test/testdata/hlint/ApplyRefact4.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact4.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact4.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact4.hs diff --git a/test/testdata/hlint/ApplyRefact5.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact5.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact5.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact5.hs diff --git a/test/testdata/hlint/ApplyRefact6.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact6.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact6.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact6.hs diff --git a/test/testdata/hlint/ApplyRefact7.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact7.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact7.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact7.hs diff --git a/test/testdata/hlint/ApplyRefact8.hs b/plugins/hls-hlint-plugin/test/testdata/ApplyRefact8.hs similarity index 100% rename from test/testdata/hlint/ApplyRefact8.hs rename to plugins/hls-hlint-plugin/test/testdata/ApplyRefact8.hs diff --git a/test/testdata/hlint/cpp/ApplyRefact2.hs b/plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact2.hs similarity index 100% rename from test/testdata/hlint/cpp/ApplyRefact2.hs rename to plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact2.hs diff --git a/test/testdata/hlint/cpp/ApplyRefact3.hs b/plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact3.hs similarity index 100% rename from test/testdata/hlint/cpp/ApplyRefact3.hs rename to plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact3.hs diff --git a/test/testdata/hlint/cpp/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/cpp/hie.yaml similarity index 100% rename from test/testdata/hlint/cpp/hie.yaml rename to plugins/hls-hlint-plugin/test/testdata/cpp/hie.yaml diff --git a/test/testdata/hlint/cpp/test.h b/plugins/hls-hlint-plugin/test/testdata/cpp/test.h similarity index 100% rename from test/testdata/hlint/cpp/test.h rename to plugins/hls-hlint-plugin/test/testdata/cpp/test.h diff --git a/test/testdata/hlint/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/hie.yaml similarity index 100% rename from test/testdata/hlint/hie.yaml rename to plugins/hls-hlint-plugin/test/testdata/hie.yaml diff --git a/test/testdata/hlint/ignore/.hlint.yaml b/plugins/hls-hlint-plugin/test/testdata/ignore/.hlint.yaml similarity index 100% rename from test/testdata/hlint/ignore/.hlint.yaml rename to plugins/hls-hlint-plugin/test/testdata/ignore/.hlint.yaml diff --git a/test/testdata/hlint/ignore/ApplyRefact.hs b/plugins/hls-hlint-plugin/test/testdata/ignore/ApplyRefact.hs similarity index 100% rename from test/testdata/hlint/ignore/ApplyRefact.hs rename to plugins/hls-hlint-plugin/test/testdata/ignore/ApplyRefact.hs diff --git a/test/testdata/hlint/ignore/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/ignore/hie.yaml similarity index 100% rename from test/testdata/hlint/ignore/hie.yaml rename to plugins/hls-hlint-plugin/test/testdata/ignore/hie.yaml diff --git a/test/testdata/hlint/lambdacase/ApplyRefact1.hs b/plugins/hls-hlint-plugin/test/testdata/lambdacase/ApplyRefact1.hs similarity index 100% rename from test/testdata/hlint/lambdacase/ApplyRefact1.hs rename to plugins/hls-hlint-plugin/test/testdata/lambdacase/ApplyRefact1.hs diff --git a/test/testdata/hlint/lambdacase/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/lambdacase/hie.yaml similarity index 100% rename from test/testdata/hlint/lambdacase/hie.yaml rename to plugins/hls-hlint-plugin/test/testdata/lambdacase/hie.yaml diff --git a/test/testdata/hlint/test-hlint-config.yaml b/plugins/hls-hlint-plugin/test/testdata/test-hlint-config.yaml similarity index 100% rename from test/testdata/hlint/test-hlint-config.yaml rename to plugins/hls-hlint-plugin/test/testdata/test-hlint-config.yaml diff --git a/test/testdata/hlint/typeapps/ApplyRefact1.hs b/plugins/hls-hlint-plugin/test/testdata/typeapps/ApplyRefact1.hs similarity index 100% rename from test/testdata/hlint/typeapps/ApplyRefact1.hs rename to plugins/hls-hlint-plugin/test/testdata/typeapps/ApplyRefact1.hs diff --git a/test/testdata/hlint/typeapps/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/typeapps/hie.yaml similarity index 100% rename from test/testdata/hlint/typeapps/hie.yaml rename to plugins/hls-hlint-plugin/test/testdata/typeapps/hie.yaml diff --git a/test/functional/FunctionalCodeAction.hs b/test/functional/FunctionalCodeAction.hs index 6c0bd95c4a..74c0aa9be5 100644 --- a/test/functional/FunctionalCodeAction.hs +++ b/test/functional/FunctionalCodeAction.hs @@ -14,20 +14,17 @@ import Data.Maybe import qualified Data.Text as T import Ide.Plugin.Config import Language.LSP.Test as Test -import qualified Language.LSP.Types.Capabilities as C import qualified Language.LSP.Types.Lens as L import Test.Hls import Test.Hspec.Expectations -import System.FilePath (()) import Test.Hls.Command {-# ANN module ("HLint: ignore Reduce duplication"::String) #-} tests :: TestTree tests = testGroup "code actions" [ - hlintTests - , importTests + importTests , packageTests , redundantImportTests , renameTests @@ -36,194 +33,6 @@ tests = testGroup "code actions" [ , unusedTermTests ] - -hlintTests :: TestTree -hlintTests = testGroup "hlint suggestions" [ - testCase "provides 3.8 code actions including apply all" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" - diags@(reduceDiag:_) <- waitForDiagnosticsFromSource doc "hlint" - - liftIO $ do - length diags @?= 2 -- "Eta Reduce" and "Redundant Id" - reduceDiag ^. L.range @?= Range (Position 1 0) (Position 1 12) - reduceDiag ^. L.severity @?= Just DsInfo - reduceDiag ^. L.code @?= Just (InR "refact:Eta reduce") - reduceDiag ^. L.source @?= Just "hlint" - - cas <- map fromAction <$> getAllCodeActions doc - - let applyAll = find (\ca -> "Apply all hints" `T.isSuffixOf` (ca ^. L.title)) cas - let redId = find (\ca -> "Redundant id" `T.isSuffixOf` (ca ^. L.title)) cas - let redEta = find (\ca -> "Eta reduce" `T.isSuffixOf` (ca ^. L.title)) cas - - liftIO $ isJust applyAll @? "There is 'Apply all hints' code action" - liftIO $ isJust redId @? "There is 'Redundant id' code action" - liftIO $ isJust redEta @? "There is 'Eta reduce' code action" - - executeCodeAction (fromJust redId) - - contents <- skipManyTill anyMessage $ getDocumentEdit doc - liftIO $ contents @?= "main = undefined\nfoo x = x\n" - - , testCase "falls back to pre 3.8 code actions" $ runSession hlsCommand noLiteralCaps "test/testdata/hlint" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" - - _ <- waitForDiagnosticsFromSource doc "hlint" - - cars <- getAllCodeActions doc - etaReduce <- liftIO $ inspectCommand cars ["Eta reduce"] - - executeCommand etaReduce - - contents <- skipManyTill anyMessage $ getDocumentEdit doc - liftIO $ contents @?= "main = undefined\nfoo = id\n" - - , testCase "changing configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do - let config = def { hlintOn = True } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) - - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - let config' = def { hlintOn = False } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config')) - - diags' <- waitForDiagnosticsFrom doc - - liftIO $ noHlintDiagnostics diags' - - , testCase "changing document contents updates hlint diagnostics" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - let change = TextDocumentContentChangeEvent - (Just (Range (Position 1 8) (Position 1 12))) - Nothing "x" - changeDoc doc [change] - expectNoMoreDiagnostics 3 doc "hlint" - - let change' = TextDocumentContentChangeEvent - (Just (Range (Position 1 8) (Position 1 12))) - Nothing "id x" - changeDoc doc [change'] - testHlintDiagnostics doc - - , knownBrokenForGhcVersions [GHC88, GHC86] "hlint doesn't take in account cpp flag as ghc -D argument" $ - testCase "hlint diagnostics works with CPP via ghc -XCPP argument (#554)" $ runHlintSession "cpp" $ do - doc <- openDoc "ApplyRefact3.hs" "haskell" - testHlintDiagnostics doc - - , knownBrokenForGhcVersions [GHC88, GHC86] "hlint doesn't take in account cpp flag as ghc -D argument" $ - testCase "hlint diagnostics works with CPP via language pragma (#554)" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact3.hs" "haskell" - testHlintDiagnostics doc - - , testCase "hlint diagnostics works with CPP via -XCPP argument and flag via #include header (#554)" $ runHlintSession "cpp" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - , testCase "apply-refact works with -XLambdaCase argument (#590)" $ runHlintSession "lambdacase" $ do - testRefactor "ApplyRefact1.hs" "Redundant bracket" - expectedLambdaCase - - , testCase "apply-refact works with -XTypeApplications argument (#1242)" $ runHlintSession "typeapps" $ do - testRefactor "ApplyRefact1.hs" "Redundant bracket" - expectedTypeApp - - , testCase "apply hints works with LambdaCase via language pragma" $ runHlintSession "" $ do - testRefactor "ApplyRefact1.hs" "Redundant bracket" - ("{-# LANGUAGE LambdaCase #-}" : expectedLambdaCase) - - , expectFailBecause "apply-refact doesn't work with cpp" $ - testCase "apply hints works with CPP via -XCPP argument" $ runHlintSession "cpp" $ do - testRefactor "ApplyRefact3.hs" "Redundant bracket" - expectedCPP - - , expectFailBecause "apply-refact doesn't work with cpp" $ - testCase "apply hints works with CPP via language pragma" $ runHlintSession "" $ do - testRefactor "ApplyRefact3.hs" "Redundant bracket" - ("{-# LANGUAGE CPP #-}" : expectedCPP) - - , testCase "hlint diagnostics ignore hints honouring .hlint.yaml" $ runHlintSession "ignore" $ do - doc <- openDoc "ApplyRefact.hs" "haskell" - expectNoMoreDiagnostics 3 doc "hlint" - - , testCase "hlint diagnostics ignore hints honouring ANN annotations" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact4.hs" "haskell" - expectNoMoreDiagnostics 3 doc "hlint" - - , knownBrokenForGhcVersions [GHC810, GHC90] "hlint plugin doesn't honour HLINT annotations (#838)" $ - testCase "hlint diagnostics ignore hints honouring HLINT annotations" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact5.hs" "haskell" - expectNoMoreDiagnostics 3 doc "hlint" - - , testCase "apply-refact preserve regular comments" $ runHlintSession "" $ do - testRefactor "ApplyRefact6.hs" "Redundant bracket" expectedComments - - , testCase "applyAll is shown only when there is at least one diagnostic in range" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact8.hs" "haskell" - _ <- waitForDiagnosticsFromSource doc "hlint" - - firstLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 0 0) - secondLine <- map fromAction <$> getCodeActions doc (mkRange 1 0 1 0) - thirdLine <- map fromAction <$> getCodeActions doc (mkRange 2 0 2 0) - multiLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 2 0) - - let hasApplyAll = isJust . find (\ca -> "Apply all hints" `T.isSuffixOf` (ca ^. L.title)) - - liftIO $ hasApplyAll firstLine @? "Missing apply all code action" - liftIO $ hasApplyAll secondLine @? "Missing apply all code action" - liftIO $ not (hasApplyAll thirdLine) @? "Unexpected apply all code action" - liftIO $ hasApplyAll multiLine @? "Missing apply all code action" - ] - where - runHlintSession :: FilePath -> Session a -> IO a - runHlintSession subdir = - failIfSessionTimeout . runSession hlsCommand fullCaps ("test/testdata/hlint" subdir) - - noHlintDiagnostics :: [Diagnostic] -> Assertion - noHlintDiagnostics diags = - Just "hlint" `notElem` map (^. L.source) diags @? "There are no hlint diagnostics" - - testHlintDiagnostics doc = do - diags <- waitForDiagnosticsFromSource doc "hlint" - liftIO $ length diags > 0 @? "There are hlint diagnostics" - - testRefactor file caTitle expected = do - doc <- openDoc file "haskell" - testHlintDiagnostics doc - - cas <- map fromAction <$> getAllCodeActions doc - let ca = find (\ca -> caTitle `T.isSuffixOf` (ca ^. L.title)) cas - liftIO $ isJust ca @? ("There is '" ++ T.unpack caTitle ++"' code action") - - executeCodeAction (fromJust ca) - - contents <- skipManyTill anyMessage $ getDocumentEdit doc - liftIO $ contents @?= T.unlines expected - - expectedLambdaCase = [ "module ApplyRefact1 where", "" - , "f = \\case \"true\" -> True" - , " _ -> False" - ] - expectedCPP = [ "module ApplyRefact3 where", "" - , "#ifdef FLAG" - , "f = 1" - , "#else" - , "g = 2" - , "#endif", "" - ] - expectedComments = [ "-- comment before header" - , "module ApplyRefact6 where", "" - , "{-# standalone annotation #-}", "" - , "-- standalone comment", "" - , "-- | haddock comment" - , "f = {- inline comment -}{- inline comment inside refactored code -} 1 -- ending comment", "" - , "-- final comment" - ] - expectedTypeApp = [ "module ApplyRefact1 where", "" - , "a = id @Int 1" - ] renameTests :: TestTree renameTests = testGroup "rename suggestions" [ testCase "works" $ runSession hlsCommand noLiteralCaps "test/testdata" $ do @@ -556,14 +365,3 @@ disableWingman = sendConfigurationChanged $ def { plugins = M.fromList [ ("tactics", def { plcGlobalOn = False }) ] } - - -sendConfigurationChanged :: Config -> Session () -sendConfigurationChanged config = - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) - -noLiteralCaps :: C.ClientCapabilities -noLiteralCaps = def { C._textDocument = Just textDocumentCaps } - where - textDocumentCaps = def { C._codeAction = Just codeActionCaps } - codeActionCaps = CodeActionClientCapabilities (Just True) Nothing Nothing Nothing Nothing Nothing Nothing From 2204c02d15f017de170ec17565fa7c2afc6931cb Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 20 Oct 2021 10:09:33 +0200 Subject: [PATCH 02/13] Move hlint config tests to its package --- hls-test-utils/src/Test/Hls.hs | 4 +- .../hls-hlint-plugin/hls-hlint-plugin.cabal | 1 + plugins/hls-hlint-plugin/test/Main.hs | 135 ++++++++++++++---- test/functional/Completion.hs | 3 +- test/functional/Config.hs | 104 +------------- test/functional/FunctionalCodeAction.hs | 2 +- 6 files changed, 114 insertions(+), 135 deletions(-) diff --git a/hls-test-utils/src/Test/Hls.hs b/hls-test-utils/src/Test/Hls.hs index dfbbb8dac4..dec2542f7a 100644 --- a/hls-test-utils/src/Test/Hls.hs +++ b/hls-test-utils/src/Test/Hls.hs @@ -230,6 +230,6 @@ waitForAction key TextDocumentIdentifier{_uri} = do waitForTypecheck :: TextDocumentIdentifier -> Session (Either ResponseError Bool) waitForTypecheck tid = fmap ideResultSuccess <$> waitForAction "typecheck" tid -sendConfigurationChanged :: Config -> Session () +sendConfigurationChanged :: Value -> Session () sendConfigurationChanged config = - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) + sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams config) diff --git a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal index 880f37440a..28eee2ba8a 100644 --- a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal +++ b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal @@ -111,6 +111,7 @@ test-suite tests build-depends: aeson , base + , containers , filepath , hls-hlint-plugin , hls-plugin-api diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs index ae2e790916..5c1d4d5d75 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -4,15 +4,17 @@ module Main ) where import Control.Lens ((^.)) -import Data.Aeson (toJSON) +import Data.Aeson (toJSON, Value (..), object, (.=)) import Data.List (find) +import qualified Data.Map as Map import Data.Maybe (fromJust, isJust) import qualified Data.Text as T import qualified Ide.Plugin.Hlint as HLint -import Ide.Plugin.Config (hlintOn) +import Ide.Plugin.Config (hlintOn, Config (..), PluginConfig (..)) import qualified Language.LSP.Types.Lens as L import System.FilePath (()) import Test.Hls +import qualified Ide.Plugin.Config as Plugin main :: IO () main = defaultTestRunner tests @@ -21,7 +23,13 @@ hlintPlugin :: PluginDescriptor IdeState hlintPlugin = HLint.descriptor "hlint" tests :: TestTree -tests = +tests = testGroup "hlint" [ + suggestionsTests + , configTests + ] + +suggestionsTests :: TestTree +suggestionsTests = testGroup "hlint suggestions" [ testCase "provides 3.8 code actions including apply all" $ runHlintSession "" $ do doc <- openDoc "ApplyRefact2.hs" "haskell" @@ -62,20 +70,6 @@ tests = contents <- skipManyTill anyMessage $ getDocumentEdit doc liftIO $ contents @?= "main = undefined\nfoo = id\n" - , testCase "changing configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do - let config = def { hlintOn = True } - sendConfigurationChanged config - - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - let config' = def { hlintOn = False } - sendConfigurationChanged config' - - diags' <- waitForDiagnosticsFrom doc - - liftIO $ noHlintDiagnostics diags' - , testCase "changing document contents updates hlint diagnostics" $ runHlintSession "" $ do doc <- openDoc "ApplyRefact2.hs" "haskell" testHlintDiagnostics doc @@ -161,18 +155,6 @@ tests = liftIO $ hasApplyAll multiLine @? "Missing apply all code action" ] where - runHlintSession :: FilePath -> Session a -> IO a - runHlintSession subdir = - failIfSessionTimeout . runSessionWithServer hlintPlugin ("test/testdata/hlint" subdir) - - noHlintDiagnostics :: [Diagnostic] -> Assertion - noHlintDiagnostics diags = - Just "hlint" `notElem` map (^. L.source) diags @? "There are no hlint diagnostics" - - testHlintDiagnostics doc = do - diags <- waitForDiagnosticsFromSource doc "hlint" - liftIO $ length diags > 0 @? "There are hlint diagnostics" - testRefactor file caTitle expected = do doc <- openDoc file "haskell" testHlintDiagnostics doc @@ -208,3 +190,98 @@ tests = expectedTypeApp = [ "module ApplyRefact1 where", "" , "a = id @Int 1" ] + +configTests :: TestTree +configTests = testGroup "hlint plugin config" [ + + testCase "changing hlintOn configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do + let config = def { hlintOn = True } + sendConfigurationChanged (toJSON config) + + doc <- openDoc "ApplyRefact2.hs" "haskell" + testHlintDiagnostics doc + + let config' = def { hlintOn = False } + sendConfigurationChanged (toJSON config') + + diags' <- waitForDiagnosticsFrom doc + + liftIO $ noHlintDiagnostics diags' + + , testCase "changing hlint plugin configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do + let config = def { hlintOn = True } + sendConfigurationChanged (toJSON config) + + doc <- openDoc "ApplyRefact2.hs" "haskell" + testHlintDiagnostics doc + + let config' = pluginGlobalOn config "hlint" False + sendConfigurationChanged (toJSON config') + + diags' <- waitForDiagnosticsFrom doc + + liftIO $ noHlintDiagnostics diags' + + , testCase "adding hlint flags to plugin configuration removes hlint diagnostics" $ runHlintSession "" $ do + let config = def { hlintOn = True } + sendConfigurationChanged (toJSON config) + + doc <- openDoc "ApplyRefact2.hs" "haskell" + testHlintDiagnostics doc + + let config' = hlintConfigWithFlags ["--ignore=Redundant id", "--hint=test-hlint-config.yaml"] + sendConfigurationChanged (toJSON config') + + diags' <- waitForDiagnosticsFrom doc + + liftIO $ noHlintDiagnostics diags' + + , testCase "adding hlint flags to plugin configuration adds hlint diagnostics" $ runHlintSession "" $ do + let config = def { hlintOn = True } + sendConfigurationChanged (toJSON config) + + doc <- openDoc "ApplyRefact7.hs" "haskell" + + expectNoMoreDiagnostics 3 doc "hlint" + + let config' = hlintConfigWithFlags ["--with-group=generalise"] + sendConfigurationChanged (toJSON config') + + diags' <- waitForDiagnosticsFromSource doc "hlint" + d <- liftIO $ inspectDiagnostic diags' ["Use <>"] + + liftIO $ do + length diags' @?= 1 + d ^. L.range @?= Range (Position 1 10) (Position 1 21) + d ^. L.severity @?= Just DsInfo + ] + +runHlintSession :: FilePath -> Session a -> IO a +runHlintSession subdir = + failIfSessionTimeout . runSessionWithServer hlintPlugin ("test/testdata/hlint" subdir) + +noHlintDiagnostics :: [Diagnostic] -> Assertion +noHlintDiagnostics diags = + Just "hlint" `notElem` map (^. L.source) diags @? "There are no hlint diagnostics" + +testHlintDiagnostics :: TextDocumentIdentifier -> Session () +testHlintDiagnostics doc = do + diags <- waitForDiagnosticsFromSource doc "hlint" + liftIO $ length diags > 0 @? "There are hlint diagnostics" + +pluginGlobalOn :: Config -> T.Text -> Bool -> Config +pluginGlobalOn config pid state = config' + where + pluginConfig = def { plcGlobalOn = state } + config' = def { plugins = Map.insert pid pluginConfig (plugins config) } + +hlintConfigWithFlags :: [T.Text] -> Config +hlintConfigWithFlags flags = + def + { hlintOn = True + , Plugin.plugins = Map.fromList [("hlint", + def { Plugin.plcConfig = unObject $ object ["flags" .= flags] } + )] } + where + unObject (Object obj) = obj + unObject _ = undefined diff --git a/test/functional/Completion.hs b/test/functional/Completion.hs index 94faa05f1e..baabbae830 100644 --- a/test/functional/Completion.hs +++ b/test/functional/Completion.hs @@ -253,8 +253,7 @@ snippetTests = testGroup "snippets" [ let config = object ["haskell" .= object ["plugin" .= object ["ghcide-completions" .= object ["config" .= object ["snippetsOn" .= False]]]]] - sendNotification SWorkspaceDidChangeConfiguration - (DidChangeConfigurationParams config) + sendConfigurationChanged config checkNoSnippets doc diff --git a/test/functional/Config.hs b/test/functional/Config.hs index 6965ffb017..5002058964 100644 --- a/test/functional/Config.hs +++ b/test/functional/Config.hs @@ -5,10 +5,7 @@ module Config (tests) where import Control.Lens hiding (List, (.=)) import Control.Monad import Data.Aeson -import qualified Data.Map as Map import qualified Data.Text as T -import Ide.Plugin.Config -import qualified Ide.Plugin.Config as Plugin import Language.LSP.Test as Test import qualified Language.LSP.Types.Lens as L import System.FilePath (()) @@ -19,89 +16,11 @@ import Test.Hls.Command tests :: TestTree tests = testGroup "plugin config" [ - -- Note: because the flag is treated generically in the plugin handler, we - -- do not have to test each individual plugin - hlintTests - , configTests + -- Note: there are more comprehensive tests over config in hls-hlint-plugin + -- TODO: Add generic tests over some example plugin + configTests ] -hlintTests :: TestTree -hlintTests = testGroup "hlint plugin enables" [ - - testCase "changing hlintOn configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do - let config = def { hlintOn = True } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) - - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - let config' = def { hlintOn = False } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config')) - - diags' <- waitForDiagnosticsFrom doc - - liftIO $ noHlintDiagnostics diags' - - , testCase "changing hlint plugin configuration enables or disables hlint diagnostics" $ runHlintSession "" $ do - let config = def { hlintOn = True } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) - - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - let config' = pluginGlobalOn config "hlint" False - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config')) - - diags' <- waitForDiagnosticsFrom doc - - liftIO $ noHlintDiagnostics diags' - - , testCase "adding hlint flags to plugin configuration removes hlint diagnostics" $ runHlintSession "" $ do - let config = def { hlintOn = True } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) - - doc <- openDoc "ApplyRefact2.hs" "haskell" - testHlintDiagnostics doc - - let config' = hlintConfigWithFlags ["--ignore=Redundant id", "--hint=test-hlint-config.yaml"] - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config')) - - diags' <- waitForDiagnosticsFrom doc - - liftIO $ noHlintDiagnostics diags' - - , testCase "adding hlint flags to plugin configuration adds hlint diagnostics" $ runHlintSession "" $ do - let config = def { hlintOn = True } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) - - doc <- openDoc "ApplyRefact7.hs" "haskell" - - expectNoMoreDiagnostics 3 doc "hlint" - - let config' = hlintConfigWithFlags ["--with-group=generalise"] - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config')) - - diags' <- waitForDiagnosticsFromSource doc "hlint" - d <- liftIO $ inspectDiagnostic diags' ["Use <>"] - - liftIO $ do - length diags' @?= 1 - d ^. L.range @?= Range (Position 1 10) (Position 1 21) - d ^. L.severity @?= Just DsInfo - ] - where - runHlintSession :: FilePath -> Session a -> IO a - runHlintSession subdir = - failIfSessionTimeout . runSession hlsCommand fullCaps ("test/testdata/hlint" subdir) - - noHlintDiagnostics :: [Diagnostic] -> Assertion - noHlintDiagnostics diags = - Just "hlint" `notElem` map (^. L.source) diags @? "There are no hlint diagnostics" - - testHlintDiagnostics doc = do - diags <- waitForDiagnosticsFromSource doc "hlint" - liftIO $ length diags > 0 @? "There are hlint diagnostics" - configTests :: TestTree configTests = testGroup "config parsing" [ testCase "empty object as user configuration should not send error logMessage" $ runConfigSession "" $ do @@ -121,20 +40,3 @@ configTests = testGroup "config parsing" [ runConfigSession :: FilePath -> Session a -> IO a runConfigSession subdir = failIfSessionTimeout . runSession hlsCommand fullCaps ("test/testdata" subdir) - -pluginGlobalOn :: Config -> T.Text -> Bool -> Config -pluginGlobalOn config pid state = config' - where - pluginConfig = def { plcGlobalOn = state } - config' = def { plugins = Map.insert pid pluginConfig (plugins config) } - -hlintConfigWithFlags :: [T.Text] -> Config -hlintConfigWithFlags flags = - def - { hlintOn = True - , Plugin.plugins = Map.fromList [("hlint", - def { Plugin.plcConfig = unObject $ object ["flags" .= flags] } - )] } - where - unObject (Object obj) = obj - unObject _ = undefined diff --git a/test/functional/FunctionalCodeAction.hs b/test/functional/FunctionalCodeAction.hs index 74c0aa9be5..1c00c21c4c 100644 --- a/test/functional/FunctionalCodeAction.hs +++ b/test/functional/FunctionalCodeAction.hs @@ -362,6 +362,6 @@ expectFailIfGhc9 reason = disableWingman :: Session () disableWingman = - sendConfigurationChanged $ def + sendConfigurationChanged $ toJSON $ def { plugins = M.fromList [ ("tactics", def { plcGlobalOn = False }) ] } From 058e0d23a801d2af9b9834fa15b89dc5976fb88f Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 20 Oct 2021 10:42:28 +0200 Subject: [PATCH 03/13] Update extra-source-files --- haskell-language-server.cabal | 3 --- plugins/hls-hlint-plugin/hls-hlint-plugin.cabal | 10 +++++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index 032a8b699f..0002f6932b 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -21,9 +21,6 @@ extra-source-files: test/testdata/**/*.project test/testdata/**/*.cabal test/testdata/**/*.yaml - -- this one is not matched by the previous glob - test/testdata/hlint/ignore/.hlint.yaml - test/testdata/**/*.h test/testdata/**/*.hs flag pedantic diff --git a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal index 28eee2ba8a..3f5a890202 100644 --- a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal +++ b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal @@ -1,4 +1,4 @@ -cabal-version: 2.2 +cabal-version: 2.4 name: hls-hlint-plugin version: 1.0.1.1 synopsis: Hlint integration plugin with Haskell Language Server @@ -12,6 +12,14 @@ maintainer: alan.zimm@gmail.com copyright: The Haskell IDE Team category: Development build-type: Simple +extra-source-files: + LICENSE + test/testdata/**/*.cabal + test/testdata/**/*.yaml + -- this one is not matched by the previous glob + test/testdata/hlint/ignore/.hlint.yaml + test/testdata/**/*.hs + test/testdata/**/*.h flag pedantic description: Enable -Werror From 91378b17dc8dd5a4da150de0e677f440a708dbd2 Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 20 Oct 2021 10:42:47 +0200 Subject: [PATCH 04/13] Remove unused cabal-helper test data --- .../testdata/cabal-helper/implicit-exe/Setup.hs | 2 -- .../cabal-helper/implicit-exe/cabal.project | 1 - .../implicit-exe/implicit-exe.cabal | 17 ----------------- .../cabal-helper/implicit-exe/src/Exe.hs | 4 ---- .../cabal-helper/implicit-exe/src/Lib.hs | 4 ---- test/testdata/cabal-helper/mono-repo/A/A.cabal | 15 --------------- test/testdata/cabal-helper/mono-repo/A/Main.hs | 8 -------- test/testdata/cabal-helper/mono-repo/A/MyLib.hs | 4 ---- test/testdata/cabal-helper/mono-repo/A/Setup.hs | 2 -- test/testdata/cabal-helper/mono-repo/B/B.cabal | 15 --------------- test/testdata/cabal-helper/mono-repo/B/Main.hs | 8 -------- test/testdata/cabal-helper/mono-repo/B/MyLib.hs | 4 ---- test/testdata/cabal-helper/mono-repo/B/Setup.hs | 2 -- test/testdata/cabal-helper/mono-repo/C/C.cabal | 9 --------- test/testdata/cabal-helper/mono-repo/C/MyLib.hs | 4 ---- test/testdata/cabal-helper/mono-repo/C/Setup.hs | 2 -- .../cabal-helper/mono-repo/cabal.project | 4 ---- .../cabal-helper/multi-source-dirs/Setup.hs | 2 -- .../multi-source-dirs/multi-source-dirs.cabal | 11 ----------- .../multi-source-dirs/src/BetterLib.hs | 5 ----- .../multi-source-dirs/src/input/Lib.hs | 6 ------ .../testdata/cabal-helper/simple-cabal/MyLib.hs | 4 ---- .../testdata/cabal-helper/simple-cabal/Setup.hs | 2 -- .../simple-cabal/simple-cabal-test.cabal | 10 ---------- .../testdata/cabal-helper/simple-stack/MyLib.hs | 4 ---- .../testdata/cabal-helper/simple-stack/Setup.hs | 2 -- .../simple-stack/simple-stack-test.cabal | 10 ---------- test/testdata/cabal-helper/sub-package/Setup.hs | 2 -- .../cabal-helper/sub-package/app/Main.hs | 8 -------- .../sub-package/plugins-api/PluginLib.hs | 4 ---- .../sub-package/plugins-api/Setup.hs | 2 -- .../sub-package/plugins-api/plugins-api.cabal | 10 ---------- .../cabal-helper/sub-package/src/MyLib.hs | 6 ------ .../cabal-helper/sub-package/sub-package.cabal | 17 ----------------- 34 files changed, 210 deletions(-) delete mode 100644 test/testdata/cabal-helper/implicit-exe/Setup.hs delete mode 100644 test/testdata/cabal-helper/implicit-exe/cabal.project delete mode 100644 test/testdata/cabal-helper/implicit-exe/implicit-exe.cabal delete mode 100644 test/testdata/cabal-helper/implicit-exe/src/Exe.hs delete mode 100644 test/testdata/cabal-helper/implicit-exe/src/Lib.hs delete mode 100644 test/testdata/cabal-helper/mono-repo/A/A.cabal delete mode 100644 test/testdata/cabal-helper/mono-repo/A/Main.hs delete mode 100644 test/testdata/cabal-helper/mono-repo/A/MyLib.hs delete mode 100644 test/testdata/cabal-helper/mono-repo/A/Setup.hs delete mode 100644 test/testdata/cabal-helper/mono-repo/B/B.cabal delete mode 100644 test/testdata/cabal-helper/mono-repo/B/Main.hs delete mode 100644 test/testdata/cabal-helper/mono-repo/B/MyLib.hs delete mode 100644 test/testdata/cabal-helper/mono-repo/B/Setup.hs delete mode 100644 test/testdata/cabal-helper/mono-repo/C/C.cabal delete mode 100644 test/testdata/cabal-helper/mono-repo/C/MyLib.hs delete mode 100644 test/testdata/cabal-helper/mono-repo/C/Setup.hs delete mode 100644 test/testdata/cabal-helper/mono-repo/cabal.project delete mode 100644 test/testdata/cabal-helper/multi-source-dirs/Setup.hs delete mode 100644 test/testdata/cabal-helper/multi-source-dirs/multi-source-dirs.cabal delete mode 100644 test/testdata/cabal-helper/multi-source-dirs/src/BetterLib.hs delete mode 100644 test/testdata/cabal-helper/multi-source-dirs/src/input/Lib.hs delete mode 100644 test/testdata/cabal-helper/simple-cabal/MyLib.hs delete mode 100644 test/testdata/cabal-helper/simple-cabal/Setup.hs delete mode 100644 test/testdata/cabal-helper/simple-cabal/simple-cabal-test.cabal delete mode 100644 test/testdata/cabal-helper/simple-stack/MyLib.hs delete mode 100644 test/testdata/cabal-helper/simple-stack/Setup.hs delete mode 100644 test/testdata/cabal-helper/simple-stack/simple-stack-test.cabal delete mode 100644 test/testdata/cabal-helper/sub-package/Setup.hs delete mode 100644 test/testdata/cabal-helper/sub-package/app/Main.hs delete mode 100644 test/testdata/cabal-helper/sub-package/plugins-api/PluginLib.hs delete mode 100644 test/testdata/cabal-helper/sub-package/plugins-api/Setup.hs delete mode 100644 test/testdata/cabal-helper/sub-package/plugins-api/plugins-api.cabal delete mode 100644 test/testdata/cabal-helper/sub-package/src/MyLib.hs delete mode 100644 test/testdata/cabal-helper/sub-package/sub-package.cabal diff --git a/test/testdata/cabal-helper/implicit-exe/Setup.hs b/test/testdata/cabal-helper/implicit-exe/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/implicit-exe/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/implicit-exe/cabal.project b/test/testdata/cabal-helper/implicit-exe/cabal.project deleted file mode 100644 index bfe6289656..0000000000 --- a/test/testdata/cabal-helper/implicit-exe/cabal.project +++ /dev/null @@ -1 +0,0 @@ -packages: ./ \ No newline at end of file diff --git a/test/testdata/cabal-helper/implicit-exe/implicit-exe.cabal b/test/testdata/cabal-helper/implicit-exe/implicit-exe.cabal deleted file mode 100644 index 3aca1b42fa..0000000000 --- a/test/testdata/cabal-helper/implicit-exe/implicit-exe.cabal +++ /dev/null @@ -1,17 +0,0 @@ -cabal-version: >=1.10 -name: implicit-exe -version: 0.1.0.0 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: Lib - hs-source-dirs: src - build-depends: base - default-language: Haskell2010 - - -executable implicit-exe - main-is: src/Exe.hs - build-depends: base, implicit-exe - default-language: Haskell2010 \ No newline at end of file diff --git a/test/testdata/cabal-helper/implicit-exe/src/Exe.hs b/test/testdata/cabal-helper/implicit-exe/src/Exe.hs deleted file mode 100644 index ed41929e78..0000000000 --- a/test/testdata/cabal-helper/implicit-exe/src/Exe.hs +++ /dev/null @@ -1,4 +0,0 @@ - -import Lib (someFunc) - -main = someFunc \ No newline at end of file diff --git a/test/testdata/cabal-helper/implicit-exe/src/Lib.hs b/test/testdata/cabal-helper/implicit-exe/src/Lib.hs deleted file mode 100644 index f51af83e20..0000000000 --- a/test/testdata/cabal-helper/implicit-exe/src/Lib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module Lib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/mono-repo/A/A.cabal b/test/testdata/cabal-helper/mono-repo/A/A.cabal deleted file mode 100644 index e70b43fc1d..0000000000 --- a/test/testdata/cabal-helper/mono-repo/A/A.cabal +++ /dev/null @@ -1,15 +0,0 @@ -cabal-version: >=1.10 -name: A -version: 0.1.0.0 -build-type: Simple - -library - exposed-modules: MyLib - build-depends: base - default-language: Haskell2010 - -executable A - main-is: Main.hs - other-modules: MyLib - build-depends: base, A - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/mono-repo/A/Main.hs b/test/testdata/cabal-helper/mono-repo/A/Main.hs deleted file mode 100644 index 60d904e8c1..0000000000 --- a/test/testdata/cabal-helper/mono-repo/A/Main.hs +++ /dev/null @@ -1,8 +0,0 @@ -module Main where - -import qualified MyLib (someFunc) - -main :: IO () -main = do - putStrLn "Hello, Haskell!" - MyLib.someFunc diff --git a/test/testdata/cabal-helper/mono-repo/A/MyLib.hs b/test/testdata/cabal-helper/mono-repo/A/MyLib.hs deleted file mode 100644 index e657c4403f..0000000000 --- a/test/testdata/cabal-helper/mono-repo/A/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/mono-repo/A/Setup.hs b/test/testdata/cabal-helper/mono-repo/A/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/mono-repo/A/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/mono-repo/B/B.cabal b/test/testdata/cabal-helper/mono-repo/B/B.cabal deleted file mode 100644 index 4093e1d0f6..0000000000 --- a/test/testdata/cabal-helper/mono-repo/B/B.cabal +++ /dev/null @@ -1,15 +0,0 @@ -cabal-version: >=1.10 -name: B -version: 0.1.0.0 -build-type: Simple - -library - exposed-modules: MyLib - build-depends: base - default-language: Haskell2010 - -executable B - main-is: Main.hs - other-modules: MyLib - build-depends: base, B - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/mono-repo/B/Main.hs b/test/testdata/cabal-helper/mono-repo/B/Main.hs deleted file mode 100644 index 60d904e8c1..0000000000 --- a/test/testdata/cabal-helper/mono-repo/B/Main.hs +++ /dev/null @@ -1,8 +0,0 @@ -module Main where - -import qualified MyLib (someFunc) - -main :: IO () -main = do - putStrLn "Hello, Haskell!" - MyLib.someFunc diff --git a/test/testdata/cabal-helper/mono-repo/B/MyLib.hs b/test/testdata/cabal-helper/mono-repo/B/MyLib.hs deleted file mode 100644 index e657c4403f..0000000000 --- a/test/testdata/cabal-helper/mono-repo/B/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/mono-repo/B/Setup.hs b/test/testdata/cabal-helper/mono-repo/B/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/mono-repo/B/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/mono-repo/C/C.cabal b/test/testdata/cabal-helper/mono-repo/C/C.cabal deleted file mode 100644 index db5e380f49..0000000000 --- a/test/testdata/cabal-helper/mono-repo/C/C.cabal +++ /dev/null @@ -1,9 +0,0 @@ -cabal-version: >=1.10 -name: C -version: 0.1.0.0 -build-type: Simple - -library - exposed-modules: MyLib - build-depends: base - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/mono-repo/C/MyLib.hs b/test/testdata/cabal-helper/mono-repo/C/MyLib.hs deleted file mode 100644 index e657c4403f..0000000000 --- a/test/testdata/cabal-helper/mono-repo/C/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/mono-repo/C/Setup.hs b/test/testdata/cabal-helper/mono-repo/C/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/mono-repo/C/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/mono-repo/cabal.project b/test/testdata/cabal-helper/mono-repo/cabal.project deleted file mode 100644 index cf2eab3e10..0000000000 --- a/test/testdata/cabal-helper/mono-repo/cabal.project +++ /dev/null @@ -1,4 +0,0 @@ -packages: - ./A/ - ./B/ - ./C/ \ No newline at end of file diff --git a/test/testdata/cabal-helper/multi-source-dirs/Setup.hs b/test/testdata/cabal-helper/multi-source-dirs/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/multi-source-dirs/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/multi-source-dirs/multi-source-dirs.cabal b/test/testdata/cabal-helper/multi-source-dirs/multi-source-dirs.cabal deleted file mode 100644 index 58568683dd..0000000000 --- a/test/testdata/cabal-helper/multi-source-dirs/multi-source-dirs.cabal +++ /dev/null @@ -1,11 +0,0 @@ -cabal-version: >=1.10 -name: multi-source-dirs -version: 0.1.0.0 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: Lib, BetterLib - hs-source-dirs: src, src/input - build-depends: base - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/multi-source-dirs/src/BetterLib.hs b/test/testdata/cabal-helper/multi-source-dirs/src/BetterLib.hs deleted file mode 100644 index 0784c76d48..0000000000 --- a/test/testdata/cabal-helper/multi-source-dirs/src/BetterLib.hs +++ /dev/null @@ -1,5 +0,0 @@ -module BetterLib where - - -foo = 3 -bar = "String" \ No newline at end of file diff --git a/test/testdata/cabal-helper/multi-source-dirs/src/input/Lib.hs b/test/testdata/cabal-helper/multi-source-dirs/src/input/Lib.hs deleted file mode 100644 index 6c37234910..0000000000 --- a/test/testdata/cabal-helper/multi-source-dirs/src/input/Lib.hs +++ /dev/null @@ -1,6 +0,0 @@ -module Lib where - -foobar = 15 - -fizbuzz :: Int -> String -fizbuzz n = "Fizz" \ No newline at end of file diff --git a/test/testdata/cabal-helper/simple-cabal/MyLib.hs b/test/testdata/cabal-helper/simple-cabal/MyLib.hs deleted file mode 100644 index e657c4403f..0000000000 --- a/test/testdata/cabal-helper/simple-cabal/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/simple-cabal/Setup.hs b/test/testdata/cabal-helper/simple-cabal/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/simple-cabal/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/simple-cabal/simple-cabal-test.cabal b/test/testdata/cabal-helper/simple-cabal/simple-cabal-test.cabal deleted file mode 100644 index 3c8be5d868..0000000000 --- a/test/testdata/cabal-helper/simple-cabal/simple-cabal-test.cabal +++ /dev/null @@ -1,10 +0,0 @@ -cabal-version: >=1.10 -name: simple-cabal-test -version: 0.1.0.0 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: MyLib - build-depends: base - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/simple-stack/MyLib.hs b/test/testdata/cabal-helper/simple-stack/MyLib.hs deleted file mode 100644 index e657c4403f..0000000000 --- a/test/testdata/cabal-helper/simple-stack/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/simple-stack/Setup.hs b/test/testdata/cabal-helper/simple-stack/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/simple-stack/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/simple-stack/simple-stack-test.cabal b/test/testdata/cabal-helper/simple-stack/simple-stack-test.cabal deleted file mode 100644 index 264baebfd1..0000000000 --- a/test/testdata/cabal-helper/simple-stack/simple-stack-test.cabal +++ /dev/null @@ -1,10 +0,0 @@ -cabal-version: >=1.10 -name: simple-stack-test -version: 0.1.0.0 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: MyLib - build-depends: base - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/sub-package/Setup.hs b/test/testdata/cabal-helper/sub-package/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/sub-package/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/sub-package/app/Main.hs b/test/testdata/cabal-helper/sub-package/app/Main.hs deleted file mode 100644 index 60d904e8c1..0000000000 --- a/test/testdata/cabal-helper/sub-package/app/Main.hs +++ /dev/null @@ -1,8 +0,0 @@ -module Main where - -import qualified MyLib (someFunc) - -main :: IO () -main = do - putStrLn "Hello, Haskell!" - MyLib.someFunc diff --git a/test/testdata/cabal-helper/sub-package/plugins-api/PluginLib.hs b/test/testdata/cabal-helper/sub-package/plugins-api/PluginLib.hs deleted file mode 100644 index 55a7098c23..0000000000 --- a/test/testdata/cabal-helper/sub-package/plugins-api/PluginLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module PluginLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/test/testdata/cabal-helper/sub-package/plugins-api/Setup.hs b/test/testdata/cabal-helper/sub-package/plugins-api/Setup.hs deleted file mode 100644 index 9a994af677..0000000000 --- a/test/testdata/cabal-helper/sub-package/plugins-api/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/test/testdata/cabal-helper/sub-package/plugins-api/plugins-api.cabal b/test/testdata/cabal-helper/sub-package/plugins-api/plugins-api.cabal deleted file mode 100644 index 223fa73b95..0000000000 --- a/test/testdata/cabal-helper/sub-package/plugins-api/plugins-api.cabal +++ /dev/null @@ -1,10 +0,0 @@ -cabal-version: >=1.10 -name: plugins-api -version: 0.1.0.0 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: PluginLib - build-depends: base - default-language: Haskell2010 diff --git a/test/testdata/cabal-helper/sub-package/src/MyLib.hs b/test/testdata/cabal-helper/sub-package/src/MyLib.hs deleted file mode 100644 index 53ea5c6332..0000000000 --- a/test/testdata/cabal-helper/sub-package/src/MyLib.hs +++ /dev/null @@ -1,6 +0,0 @@ -module MyLib (someFunc) where - -import qualified PluginLib as L - -someFunc :: IO () -someFunc = L.someFunc diff --git a/test/testdata/cabal-helper/sub-package/sub-package.cabal b/test/testdata/cabal-helper/sub-package/sub-package.cabal deleted file mode 100644 index ba36f1b4d1..0000000000 --- a/test/testdata/cabal-helper/sub-package/sub-package.cabal +++ /dev/null @@ -1,17 +0,0 @@ -cabal-version: >=1.10 -name: sub-package -version: 0.1.0.0 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: MyLib - build-depends: base, plugins-api - hs-source-dirs: src - default-language: Haskell2010 - -executable sub-package - main-is: Main.hs - build-depends: base, sub-package - hs-source-dirs: app - default-language: Haskell2010 From 9c7543265779c7d2f1fd09286b042b3edf72f641 Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 20 Oct 2021 10:48:24 +0200 Subject: [PATCH 05/13] Add hlint test suite --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 884140c4e6..b8fda76503 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -215,3 +215,7 @@ jobs: - if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test}} name: Test hls-rename-plugin test suite run: cabal test hls-rename-plugin --test-options="-j1 --rerun-update" || cabal test hls-rename-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-rename-plugin --test-options="-j1 --rerun" + + - if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test}} + name: Test hls-hlint-plugin test suite + run: cabal test hls-hlint-plugin --test-options="-j1 --rerun-update" || cabal test hls-hlint-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-hlint-plugin --test-options="-j1 --rerun" From 2907204d557e5885315640524ab83ebc8abeb61f Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 20 Oct 2021 11:55:00 +0200 Subject: [PATCH 06/13] Make diganostic tests work without hlint --- test/functional/Diagnostic.hs | 18 +++--------------- test/testdata/diagnostics/Foo.hs | 2 ++ 2 files changed, 5 insertions(+), 15 deletions(-) create mode 100644 test/testdata/diagnostics/Foo.hs diff --git a/test/functional/Diagnostic.hs b/test/functional/Diagnostic.hs index bfe304d99e..3cf3db2e58 100644 --- a/test/functional/Diagnostic.hs +++ b/test/functional/Diagnostic.hs @@ -21,21 +21,9 @@ tests = testGroup "diagnostics providers" [ basicTests :: TestTree basicTests = testGroup "Diagnostics work" [ - testCase "hlint produces diagnostics" $ - runSession hlsCommand fullCaps "test/testdata/hlint" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" - diags <- waitForDiagnosticsFromSource doc "hlint" - reduceDiag <- liftIO $ inspectDiagnostic diags ["Eta reduce"] - redundantID <- liftIO $ inspectDiagnostic diags ["Redundant id"] - liftIO $ do - length diags @?= 2 - reduceDiag ^. LSP.range @?= Range (Position 1 0) (Position 1 12) - reduceDiag ^. LSP.severity @?= Just DsInfo - redundantID ^. LSP.severity @?= Just DsInfo - - , testCase "example plugin produces diagnostics" $ - runSession hlsCommandExamplePlugin fullCaps "test/testdata/hlint" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" + testCase "example plugin produces diagnostics" $ + runSession hlsCommandExamplePlugin fullCaps "test/testdata/diagnostics" $ do + doc <- openDoc "Foo.hs" "haskell" diags <- waitForDiagnosticsFromSource doc "example2" reduceDiag <- liftIO $ inspectDiagnostic diags ["example2 diagnostic, hello world"] liftIO $ do diff --git a/test/testdata/diagnostics/Foo.hs b/test/testdata/diagnostics/Foo.hs new file mode 100644 index 0000000000..d83992f387 --- /dev/null +++ b/test/testdata/diagnostics/Foo.hs @@ -0,0 +1,2 @@ +main = undefined +foo x = id x From 8b4956b42cfabf6074f982e266fb4db3e14a7eeb Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 20 Oct 2021 11:59:37 +0200 Subject: [PATCH 07/13] Make progressCap test work without hlint files --- test/functional/Progress.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/Progress.hs b/test/functional/Progress.hs index a4b9ac4fa1..853bb4f822 100644 --- a/test/functional/Progress.hs +++ b/test/functional/Progress.hs @@ -27,7 +27,7 @@ tests = "window/workDoneProgress" [ testCase "sends indefinite progress notifications" $ runSession hlsCommand progressCaps "test/testdata" $ do - let path = "hlint" "ApplyRefact2.hs" + let path = "diagnostics" "Foo.hs" _ <- openDoc path "haskell" expectProgressReports [pack ("Setting up hlint (for " ++ path ++ ")"), "Processing", "Indexing"] , requiresEvalPlugin $ testCase "eval plugin sends progress reports" $ From 91284d717d78dacc8447627a1901bbb9e879df7c Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 20 Oct 2021 12:45:04 +0200 Subject: [PATCH 08/13] No cabal files in hlint test data --- plugins/hls-hlint-plugin/hls-hlint-plugin.cabal | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal index 3f5a890202..21b87d2e89 100644 --- a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal +++ b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal @@ -14,7 +14,6 @@ category: Development build-type: Simple extra-source-files: LICENSE - test/testdata/**/*.cabal test/testdata/**/*.yaml -- this one is not matched by the previous glob test/testdata/hlint/ignore/.hlint.yaml From 9adc503f5937a0372eb1b0e05f3ae55d7e2e7212 Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 20 Oct 2021 14:09:25 +0200 Subject: [PATCH 09/13] Fix progress test --- test/functional/Progress.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/Progress.hs b/test/functional/Progress.hs index 853bb4f822..49b390dc29 100644 --- a/test/functional/Progress.hs +++ b/test/functional/Progress.hs @@ -29,7 +29,7 @@ tests = runSession hlsCommand progressCaps "test/testdata" $ do let path = "diagnostics" "Foo.hs" _ <- openDoc path "haskell" - expectProgressReports [pack ("Setting up hlint (for " ++ path ++ ")"), "Processing", "Indexing"] + expectProgressReports [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" From 8fddcfce51e84382e0a91fbaed1c0e16efbe0486 Mon Sep 17 00:00:00 2001 From: Javier Neira Date: Wed, 20 Oct 2021 17:06:32 +0200 Subject: [PATCH 10/13] Fix parent folder name --- test/functional/Progress.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/Progress.hs b/test/functional/Progress.hs index 49b390dc29..c25dea2cba 100644 --- a/test/functional/Progress.hs +++ b/test/functional/Progress.hs @@ -29,7 +29,7 @@ tests = runSession hlsCommand progressCaps "test/testdata" $ do let path = "diagnostics" "Foo.hs" _ <- openDoc path "haskell" - expectProgressReports [pack ("Setting up diagnostics (for " ++ path ++ ")"), "Processing", "Indexing"] + expectProgressReports [pack ("Setting up testdata (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" From d8ff2d42a7f6cec467cf29826d38108a6d2ee8c7 Mon Sep 17 00:00:00 2001 From: Javier Neira Date: Wed, 20 Oct 2021 18:31:57 +0200 Subject: [PATCH 11/13] Correct test data dir --- plugins/hls-hlint-plugin/test/Main.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs index 5c1d4d5d75..0987a5ef3b 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -258,7 +258,7 @@ configTests = testGroup "hlint plugin config" [ runHlintSession :: FilePath -> Session a -> IO a runHlintSession subdir = - failIfSessionTimeout . runSessionWithServer hlintPlugin ("test/testdata/hlint" subdir) + failIfSessionTimeout . runSessionWithServer hlintPlugin ("test/testdata" subdir) noHlintDiagnostics :: [Diagnostic] -> Assertion noHlintDiagnostics diags = From 4ae8cfb04e41f82ad35508fb48c3860df80c5ffa Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 20 Oct 2021 21:39:13 +0200 Subject: [PATCH 12/13] Correct extra-source dir and update maintainer --- plugins/hls-hlint-plugin/hls-hlint-plugin.cabal | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal index 21b87d2e89..316bdf0f36 100644 --- a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal +++ b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal @@ -8,7 +8,7 @@ description: license: Apache-2.0 license-file: LICENSE author: The Haskell IDE Team -maintainer: alan.zimm@gmail.com +maintainer: atreyu.bbb@gmail.com copyright: The Haskell IDE Team category: Development build-type: Simple @@ -16,7 +16,7 @@ extra-source-files: LICENSE test/testdata/**/*.yaml -- this one is not matched by the previous glob - test/testdata/hlint/ignore/.hlint.yaml + test/testdata/ignore/.hlint.yaml test/testdata/**/*.hs test/testdata/**/*.h From 7833533098abae98c0086776bd007931b89a6219 Mon Sep 17 00:00:00 2001 From: jneira Date: Fri, 22 Oct 2021 09:20:53 +0200 Subject: [PATCH 13/13] Use sendConfigurationChanged everywhere --- test/functional/Config.hs | 2 +- test/functional/Diagnostic.hs | 2 +- test/functional/Format.hs | 10 +++++----- test/functional/FunctionalCodeAction.hs | 2 +- test/functional/FunctionalLiquid.hs | 2 +- test/functional/Progress.hs | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/functional/Config.hs b/test/functional/Config.hs index 5002058964..2ad8966034 100644 --- a/test/functional/Config.hs +++ b/test/functional/Config.hs @@ -25,7 +25,7 @@ configTests :: TestTree configTests = testGroup "config parsing" [ testCase "empty object as user configuration should not send error logMessage" $ runConfigSession "" $ do let config = object [] - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) + sendConfigurationChanged (toJSON config) -- Send custom request so server returns a response to prevent blocking void $ sendNotification (SCustomMethod "non-existent-method") Null diff --git a/test/functional/Diagnostic.hs b/test/functional/Diagnostic.hs index 3cf3db2e58..06d6bf5e03 100644 --- a/test/functional/Diagnostic.hs +++ b/test/functional/Diagnostic.hs @@ -46,7 +46,7 @@ saveTests = testGroup "only diagnostics on save" [ ignoreTestBecause "diagnosticsOnChange parameter is not supported right now" $ testCase "Respects diagnosticsOnChange setting" $ runSession hlsCommandExamplePlugin codeActionSupportCaps "test/testdata" $ do let config = Data.Default.def { diagnosticsOnChange = False } :: Config - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) + sendConfigurationChanged (toJSON config) doc <- openDoc "Hover.hs" "haskell" diags <- waitForDiagnosticsFrom doc diff --git a/test/functional/Format.hs b/test/functional/Format.hs index 4620f4fdd8..43e9366843 100644 --- a/test/functional/Format.hs +++ b/test/functional/Format.hs @@ -56,15 +56,15 @@ providerTests = testGroup "formatting provider" [ doc <- openDoc "Format.hs" "haskell" - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu")) + sendConfigurationChanged (formatLspConfig "ormolu") formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) documentContents doc >>= liftIO . (@?= formattedOrmolu) - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "floskell")) + sendConfigurationChanged (formatLspConfig "floskell") formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) documentContents doc >>= liftIO . (@?= formattedFloskell) - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu")) + sendConfigurationChanged (formatLspConfig "ormolu") formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) documentContents doc >>= liftIO . (@?= formattedOrmoluPostFloskell) , requiresOrmoluPlugin . requiresFloskellPlugin $ testCase "supports both new and old configuration sections" $ runSession hlsCommand fullCaps "test/testdata/format" $ do @@ -73,11 +73,11 @@ providerTests = testGroup "formatting provider" [ doc <- openDoc "Format.hs" "haskell" - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "ormolu")) + sendConfigurationChanged (formatLspConfigOld "ormolu") formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) documentContents doc >>= liftIO . (@?= formattedOrmolu) - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "floskell")) + sendConfigurationChanged (formatLspConfigOld "floskell") formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) documentContents doc >>= liftIO . (@?= formattedFloskell) ] diff --git a/test/functional/FunctionalCodeAction.hs b/test/functional/FunctionalCodeAction.hs index 1c00c21c4c..cf368b0613 100644 --- a/test/functional/FunctionalCodeAction.hs +++ b/test/functional/FunctionalCodeAction.hs @@ -78,7 +78,7 @@ importTests = testGroup "import suggestions" [ doc <- openDoc "CodeActionImport.hs" "haskell" -- No Formatting: let config = def { formattingProvider = "none" } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) + sendConfigurationChanged (toJSON config) (diag:_) <- waitForDiagnosticsFrom doc liftIO $ diag ^. L.message @?= "Variable not in scope: when :: Bool -> IO () -> IO ()" diff --git a/test/functional/FunctionalLiquid.hs b/test/functional/FunctionalLiquid.hs index 77a553f7ad..06a489c523 100644 --- a/test/functional/FunctionalLiquid.hs +++ b/test/functional/FunctionalLiquid.hs @@ -19,7 +19,7 @@ tests = testGroup "liquid haskell diagnostics" [ doc <- openDoc "liquid/Evens.hs" "haskell" let config = def { liquidOn = True, hlintOn = False } - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) + sendConfigurationChanged (toJSON config) diags <- waitForDiagnosticsFromSource doc "liquid" d <- liftIO $ inspectDiagnostic diags ["Liquid Type Mismatch"] diff --git a/test/functional/Progress.hs b/test/functional/Progress.hs index c25dea2cba..1f8c987cf0 100644 --- a/test/functional/Progress.hs +++ b/test/functional/Progress.hs @@ -40,14 +40,14 @@ tests = expectProgressReports ["Evaluating"] , requiresOrmoluPlugin $ testCase "ormolu plugin sends progress notifications" $ do runSession hlsCommand progressCaps "test/testdata/format" $ do - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu")) + sendConfigurationChanged (formatLspConfig "ormolu") doc <- openDoc "Format.hs" "haskell" expectProgressReports ["Setting up testdata (for Format.hs)", "Processing", "Indexing"] _ <- sendRequest STextDocumentFormatting $ DocumentFormattingParams Nothing doc (FormattingOptions 2 True Nothing Nothing Nothing) expectProgressReports ["Formatting Format.hs"] , requiresFourmoluPlugin $ testCase "fourmolu plugin sends progress notifications" $ do runSession hlsCommand progressCaps "test/testdata/format" $ do - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "fourmolu")) + sendConfigurationChanged (formatLspConfig "fourmolu") doc <- openDoc "Format.hs" "haskell" expectProgressReports ["Setting up testdata (for Format.hs)", "Processing", "Indexing"] _ <- sendRequest STextDocumentFormatting $ DocumentFormattingParams Nothing doc (FormattingOptions 2 True Nothing Nothing Nothing) @@ -57,7 +57,7 @@ tests = runSession hlsCommand progressCaps "test/testdata" $ do doc <- openDoc "liquid/Evens.hs" "haskell" let config = def{liquidOn = True, hlintOn = False} - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config)) + sendConfigurationChanged (toJSON config) sendNotification STextDocumentDidSave (DidSaveTextDocumentParams doc Nothing) expectProgressReports ["Running Liquid Haskell on Evens.hs"] ]