From 1cadb79693d3b121a4a0992e92e3aeed330c1bea Mon Sep 17 00:00:00 2001 From: jneira Date: Thu, 28 Oct 2021 23:09:44 +0200 Subject: [PATCH 01/17] Rename test data files --- plugins/hls-hlint-plugin/test/Main.hs | 55 ++++++++++--------- .../testdata/{ApplyRefact2.hs => Base.hs} | 0 .../testdata/{ApplyRefact6.hs => Comments.hs} | 2 +- .../testdata/{ApplyRefact3.hs => CppCond.hs} | 2 +- .../{ApplyRefact7.hs => Generalise.hs} | 0 .../{ApplyRefact4.hs => IgnoreAnn.hs} | 2 +- .../{ApplyRefact5.hs => IgnoreAnnHlint.hs} | 2 +- .../{ApplyRefact1.hs => LambdaCase.hs} | 2 +- .../testdata/{ApplyRefact8.hs => TwoHints.hs} | 1 - .../cpp/{ApplyRefact3.hs => CppCond.hs} | 0 .../cpp/{ApplyRefact2.hs => CppHeader.hs} | 2 +- .../test/testdata/cpp/hie.yaml | 4 +- .../hls-hlint-plugin/test/testdata/hie.yaml | 14 +++-- .../ignore/{ApplyRefact.hs => CamelCase.hs} | 2 +- .../test/testdata/ignore/hie.yaml | 2 +- .../{ApplyRefact1.hs => LambdaCase.hs} | 2 +- .../test/testdata/lambdacase/hie.yaml | 2 +- .../test/testdata/typeapps/ApplyRefact1.hs | 3 - .../test/testdata/typeapps/TypeApplication.hs | 3 + .../test/testdata/typeapps/hie.yaml | 2 +- 20 files changed, 52 insertions(+), 50 deletions(-) rename plugins/hls-hlint-plugin/test/testdata/{ApplyRefact2.hs => Base.hs} (100%) rename plugins/hls-hlint-plugin/test/testdata/{ApplyRefact6.hs => Comments.hs} (88%) rename plugins/hls-hlint-plugin/test/testdata/{ApplyRefact3.hs => CppCond.hs} (70%) rename plugins/hls-hlint-plugin/test/testdata/{ApplyRefact7.hs => Generalise.hs} (100%) rename plugins/hls-hlint-plugin/test/testdata/{ApplyRefact4.hs => IgnoreAnn.hs} (70%) rename plugins/hls-hlint-plugin/test/testdata/{ApplyRefact5.hs => IgnoreAnnHlint.hs} (79%) rename plugins/hls-hlint-plugin/test/testdata/{ApplyRefact1.hs => LambdaCase.hs} (74%) rename plugins/hls-hlint-plugin/test/testdata/{ApplyRefact8.hs => TwoHints.hs} (94%) rename plugins/hls-hlint-plugin/test/testdata/cpp/{ApplyRefact3.hs => CppCond.hs} (100%) rename plugins/hls-hlint-plugin/test/testdata/cpp/{ApplyRefact2.hs => CppHeader.hs} (69%) rename plugins/hls-hlint-plugin/test/testdata/ignore/{ApplyRefact.hs => CamelCase.hs} (56%) rename plugins/hls-hlint-plugin/test/testdata/lambdacase/{ApplyRefact1.hs => LambdaCase.hs} (65%) delete mode 100644 plugins/hls-hlint-plugin/test/testdata/typeapps/ApplyRefact1.hs create mode 100644 plugins/hls-hlint-plugin/test/testdata/typeapps/TypeApplication.hs diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs index 0987a5ef3b..c6741f7f4a 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -4,17 +4,18 @@ module Main ) where import Control.Lens ((^.)) -import Data.Aeson (toJSON, Value (..), object, (.=)) +import Data.Aeson (Value (..), object, toJSON, (.=)) import Data.List (find) import qualified Data.Map as Map import Data.Maybe (fromJust, isJust) import qualified Data.Text as T +import Ide.Plugin.Config (Config (..), PluginConfig (..), + hlintOn) +import qualified Ide.Plugin.Config as Plugin import qualified Ide.Plugin.Hlint as HLint -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 @@ -32,7 +33,7 @@ suggestionsTests :: TestTree suggestionsTests = testGroup "hlint suggestions" [ testCase "provides 3.8 code actions including apply all" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" + doc <- openDoc "Base.hs" "haskell" diags@(reduceDiag:_) <- waitForDiagnosticsFromSource doc "hlint" liftIO $ do @@ -58,7 +59,7 @@ suggestionsTests = 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" + doc <- openDoc "Base.hs" "haskell" _ <- waitForDiagnosticsFromSource doc "hlint" @@ -71,7 +72,7 @@ suggestionsTests = liftIO $ contents @?= "main = undefined\nfoo = id\n" , testCase "changing document contents updates hlint diagnostics" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact2.hs" "haskell" + doc <- openDoc "Base.hs" "haskell" testHlintDiagnostics doc let change = TextDocumentContentChangeEvent @@ -88,58 +89,58 @@ suggestionsTests = , 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" + doc <- openDoc "CppCond.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" + doc <- openDoc "CppCond.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" + doc <- openDoc "CppHeader.hs" "haskell" testHlintDiagnostics doc , testCase "apply-refact works with -XLambdaCase argument (#590)" $ runHlintSession "lambdacase" $ do - testRefactor "ApplyRefact1.hs" "Redundant bracket" + testRefactor "LambdaCase.hs" "Redundant bracket" expectedLambdaCase , testCase "apply-refact works with -XTypeApplications argument (#1242)" $ runHlintSession "typeapps" $ do - testRefactor "ApplyRefact1.hs" "Redundant bracket" + testRefactor "TypeApplication.hs" "Redundant bracket" expectedTypeApp , testCase "apply hints works with LambdaCase via language pragma" $ runHlintSession "" $ do - testRefactor "ApplyRefact1.hs" "Redundant bracket" + testRefactor "LambdaCase.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" + testRefactor "CppCond.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" + testRefactor "CppCond.hs" "Redundant bracket" ("{-# LANGUAGE CPP #-}" : expectedCPP) , testCase "hlint diagnostics ignore hints honouring .hlint.yaml" $ runHlintSession "ignore" $ do - doc <- openDoc "ApplyRefact.hs" "haskell" + doc <- openDoc "CamelCase.hs" "haskell" expectNoMoreDiagnostics 3 doc "hlint" , testCase "hlint diagnostics ignore hints honouring ANN annotations" $ runHlintSession "" $ do - doc <- openDoc "ApplyRefact4.hs" "haskell" + doc <- openDoc "IgnoreAnn.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" + doc <- openDoc "IgnoreAnnHlint.hs" "haskell" expectNoMoreDiagnostics 3 doc "hlint" , testCase "apply-refact preserve regular comments" $ runHlintSession "" $ do - testRefactor "ApplyRefact6.hs" "Redundant bracket" expectedComments + testRefactor "Comments.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" + doc <- openDoc "TwoHints.hs" "haskell" _ <- waitForDiagnosticsFromSource doc "hlint" firstLine <- map fromAction <$> getCodeActions doc (mkRange 0 0 0 0) @@ -168,11 +169,11 @@ suggestionsTests = contents <- skipManyTill anyMessage $ getDocumentEdit doc liftIO $ contents @?= T.unlines expected - expectedLambdaCase = [ "module ApplyRefact1 where", "" + expectedLambdaCase = [ "module LambdaCase where", "" , "f = \\case \"true\" -> True" , " _ -> False" ] - expectedCPP = [ "module ApplyRefact3 where", "" + expectedCPP = [ "module CppCond where", "" , "#ifdef FLAG" , "f = 1" , "#else" @@ -180,14 +181,14 @@ suggestionsTests = , "#endif", "" ] expectedComments = [ "-- comment before header" - , "module ApplyRefact6 where", "" + , "module Comments where", "" , "{-# standalone annotation #-}", "" , "-- standalone comment", "" , "-- | haddock comment" , "f = {- inline comment -}{- inline comment inside refactored code -} 1 -- ending comment", "" , "-- final comment" ] - expectedTypeApp = [ "module ApplyRefact1 where", "" + expectedTypeApp = [ "module TypeApplication where", "" , "a = id @Int 1" ] @@ -198,7 +199,7 @@ configTests = testGroup "hlint plugin config" [ let config = def { hlintOn = True } sendConfigurationChanged (toJSON config) - doc <- openDoc "ApplyRefact2.hs" "haskell" + doc <- openDoc "Base.hs" "haskell" testHlintDiagnostics doc let config' = def { hlintOn = False } @@ -212,7 +213,7 @@ configTests = testGroup "hlint plugin config" [ let config = def { hlintOn = True } sendConfigurationChanged (toJSON config) - doc <- openDoc "ApplyRefact2.hs" "haskell" + doc <- openDoc "Base.hs" "haskell" testHlintDiagnostics doc let config' = pluginGlobalOn config "hlint" False @@ -226,7 +227,7 @@ configTests = testGroup "hlint plugin config" [ let config = def { hlintOn = True } sendConfigurationChanged (toJSON config) - doc <- openDoc "ApplyRefact2.hs" "haskell" + doc <- openDoc "Base.hs" "haskell" testHlintDiagnostics doc let config' = hlintConfigWithFlags ["--ignore=Redundant id", "--hint=test-hlint-config.yaml"] @@ -240,7 +241,7 @@ configTests = testGroup "hlint plugin config" [ let config = def { hlintOn = True } sendConfigurationChanged (toJSON config) - doc <- openDoc "ApplyRefact7.hs" "haskell" + doc <- openDoc "Generalise.hs" "haskell" expectNoMoreDiagnostics 3 doc "hlint" diff --git a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact2.hs b/plugins/hls-hlint-plugin/test/testdata/Base.hs similarity index 100% rename from plugins/hls-hlint-plugin/test/testdata/ApplyRefact2.hs rename to plugins/hls-hlint-plugin/test/testdata/Base.hs diff --git a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact6.hs b/plugins/hls-hlint-plugin/test/testdata/Comments.hs similarity index 88% rename from plugins/hls-hlint-plugin/test/testdata/ApplyRefact6.hs rename to plugins/hls-hlint-plugin/test/testdata/Comments.hs index 8c5debea21..849ebecf95 100644 --- a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact6.hs +++ b/plugins/hls-hlint-plugin/test/testdata/Comments.hs @@ -1,5 +1,5 @@ -- comment before header -module ApplyRefact6 where +module Comments where {-# standalone annotation #-} diff --git a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact3.hs b/plugins/hls-hlint-plugin/test/testdata/CppCond.hs similarity index 70% rename from plugins/hls-hlint-plugin/test/testdata/ApplyRefact3.hs rename to plugins/hls-hlint-plugin/test/testdata/CppCond.hs index 81e307b2d5..6ba9eadba3 100644 --- a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact3.hs +++ b/plugins/hls-hlint-plugin/test/testdata/CppCond.hs @@ -1,5 +1,5 @@ {-# LANGUAGE CPP #-} -module ApplyRefact3 where +module CppCond where #ifdef FLAG f = (1) diff --git a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact7.hs b/plugins/hls-hlint-plugin/test/testdata/Generalise.hs similarity index 100% rename from plugins/hls-hlint-plugin/test/testdata/ApplyRefact7.hs rename to plugins/hls-hlint-plugin/test/testdata/Generalise.hs diff --git a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact4.hs b/plugins/hls-hlint-plugin/test/testdata/IgnoreAnn.hs similarity index 70% rename from plugins/hls-hlint-plugin/test/testdata/ApplyRefact4.hs rename to plugins/hls-hlint-plugin/test/testdata/IgnoreAnn.hs index 8752966daa..402e0bb090 100644 --- a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact4.hs +++ b/plugins/hls-hlint-plugin/test/testdata/IgnoreAnn.hs @@ -1,4 +1,4 @@ -module ApplyRefact4 where +module IgnoreAnn where {-# ANN module "HLint: ignore Redundant bracket" #-} f = (1) diff --git a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact5.hs b/plugins/hls-hlint-plugin/test/testdata/IgnoreAnnHlint.hs similarity index 79% rename from plugins/hls-hlint-plugin/test/testdata/ApplyRefact5.hs rename to plugins/hls-hlint-plugin/test/testdata/IgnoreAnnHlint.hs index 1507bba739..27cd7f4851 100644 --- a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact5.hs +++ b/plugins/hls-hlint-plugin/test/testdata/IgnoreAnnHlint.hs @@ -1,4 +1,4 @@ -module ApplyRefact5 where +module IgnoreHlintAnn where {- HLINT ignore "Redundant bracket" -} f = (1) diff --git a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact1.hs b/plugins/hls-hlint-plugin/test/testdata/LambdaCase.hs similarity index 74% rename from plugins/hls-hlint-plugin/test/testdata/ApplyRefact1.hs rename to plugins/hls-hlint-plugin/test/testdata/LambdaCase.hs index 8ff4c6f00f..b0f36a258c 100644 --- a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact1.hs +++ b/plugins/hls-hlint-plugin/test/testdata/LambdaCase.hs @@ -1,5 +1,5 @@ {-# LANGUAGE LambdaCase #-} -module ApplyRefact1 where +module LambdaCase where f = \case "true" -> (True) _ -> False diff --git a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact8.hs b/plugins/hls-hlint-plugin/test/testdata/TwoHints.hs similarity index 94% rename from plugins/hls-hlint-plugin/test/testdata/ApplyRefact8.hs rename to plugins/hls-hlint-plugin/test/testdata/TwoHints.hs index 3ea5093476..64c57da7b0 100644 --- a/plugins/hls-hlint-plugin/test/testdata/ApplyRefact8.hs +++ b/plugins/hls-hlint-plugin/test/testdata/TwoHints.hs @@ -1,3 +1,2 @@ f = (1) g = (1) - diff --git a/plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact3.hs b/plugins/hls-hlint-plugin/test/testdata/cpp/CppCond.hs similarity index 100% rename from plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact3.hs rename to plugins/hls-hlint-plugin/test/testdata/cpp/CppCond.hs diff --git a/plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact2.hs b/plugins/hls-hlint-plugin/test/testdata/cpp/CppHeader.hs similarity index 69% rename from plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact2.hs rename to plugins/hls-hlint-plugin/test/testdata/cpp/CppHeader.hs index b25d6f77af..b4c3f9d69f 100644 --- a/plugins/hls-hlint-plugin/test/testdata/cpp/ApplyRefact2.hs +++ b/plugins/hls-hlint-plugin/test/testdata/cpp/CppHeader.hs @@ -1,4 +1,4 @@ -module ApplyRefact2 where +module CppHeader where #include "test.h" diff --git a/plugins/hls-hlint-plugin/test/testdata/cpp/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/cpp/hie.yaml index a30ec3673d..845a503179 100644 --- a/plugins/hls-hlint-plugin/test/testdata/cpp/hie.yaml +++ b/plugins/hls-hlint-plugin/test/testdata/cpp/hie.yaml @@ -3,5 +3,5 @@ cradle: arguments: - "-XCPP" - "-DFLAG" - - "ApplyRefact3" - - "ApplyRefact2" + - "CppCond" + - "CppHeader" diff --git a/plugins/hls-hlint-plugin/test/testdata/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/hie.yaml index 98942ebb69..445d93b62b 100644 --- a/plugins/hls-hlint-plugin/test/testdata/hie.yaml +++ b/plugins/hls-hlint-plugin/test/testdata/hie.yaml @@ -3,9 +3,11 @@ cradle: arguments: - "-DFLAG" - "-Wno-unrecognised-pragmas" - - "ApplyRefact1" - - "ApplyRefact2" - - "ApplyRefact3" - - "ApplyRefact4" - - "ApplyRefact5" - - "ApplyRefact6" + - "Base" + - "Comments" + - "CppCond" + - "Generalise" + - "IgnoreAnn" + - "IgnoreAnnHlint" + - "LambdaCase" + - "TwoHints" diff --git a/plugins/hls-hlint-plugin/test/testdata/ignore/ApplyRefact.hs b/plugins/hls-hlint-plugin/test/testdata/ignore/CamelCase.hs similarity index 56% rename from plugins/hls-hlint-plugin/test/testdata/ignore/ApplyRefact.hs rename to plugins/hls-hlint-plugin/test/testdata/ignore/CamelCase.hs index 50ad6d05f5..29cc08f961 100644 --- a/plugins/hls-hlint-plugin/test/testdata/ignore/ApplyRefact.hs +++ b/plugins/hls-hlint-plugin/test/testdata/ignore/CamelCase.hs @@ -1,4 +1,4 @@ -module ApplyRefact where +module CamelCase where f = (1) diff --git a/plugins/hls-hlint-plugin/test/testdata/ignore/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/ignore/hie.yaml index 2a9b3ee8dc..f792a84060 100644 --- a/plugins/hls-hlint-plugin/test/testdata/ignore/hie.yaml +++ b/plugins/hls-hlint-plugin/test/testdata/ignore/hie.yaml @@ -1,4 +1,4 @@ cradle: direct: arguments: - - "ApplyRefact" + - "CamelCase" diff --git a/plugins/hls-hlint-plugin/test/testdata/lambdacase/ApplyRefact1.hs b/plugins/hls-hlint-plugin/test/testdata/lambdacase/LambdaCase.hs similarity index 65% rename from plugins/hls-hlint-plugin/test/testdata/lambdacase/ApplyRefact1.hs rename to plugins/hls-hlint-plugin/test/testdata/lambdacase/LambdaCase.hs index b23fe74b05..555c764162 100644 --- a/plugins/hls-hlint-plugin/test/testdata/lambdacase/ApplyRefact1.hs +++ b/plugins/hls-hlint-plugin/test/testdata/lambdacase/LambdaCase.hs @@ -1,4 +1,4 @@ -module ApplyRefact1 where +module LambdaCase where f = \case "true" -> (True) _ -> False diff --git a/plugins/hls-hlint-plugin/test/testdata/lambdacase/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/lambdacase/hie.yaml index 645c4b4927..c9c69a13b5 100644 --- a/plugins/hls-hlint-plugin/test/testdata/lambdacase/hie.yaml +++ b/plugins/hls-hlint-plugin/test/testdata/lambdacase/hie.yaml @@ -2,4 +2,4 @@ cradle: direct: arguments: - "-XLambdaCase" - - "ApplyRefact1" + - "LambdaCase" diff --git a/plugins/hls-hlint-plugin/test/testdata/typeapps/ApplyRefact1.hs b/plugins/hls-hlint-plugin/test/testdata/typeapps/ApplyRefact1.hs deleted file mode 100644 index 78fa09aec4..0000000000 --- a/plugins/hls-hlint-plugin/test/testdata/typeapps/ApplyRefact1.hs +++ /dev/null @@ -1,3 +0,0 @@ -module ApplyRefact1 where - -a = (id @Int 1) diff --git a/plugins/hls-hlint-plugin/test/testdata/typeapps/TypeApplication.hs b/plugins/hls-hlint-plugin/test/testdata/typeapps/TypeApplication.hs new file mode 100644 index 0000000000..5fecd5cf6e --- /dev/null +++ b/plugins/hls-hlint-plugin/test/testdata/typeapps/TypeApplication.hs @@ -0,0 +1,3 @@ +module TypeApplication where + +a = (id @Int 1) diff --git a/plugins/hls-hlint-plugin/test/testdata/typeapps/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/typeapps/hie.yaml index 058382f9f0..17788bcb70 100644 --- a/plugins/hls-hlint-plugin/test/testdata/typeapps/hie.yaml +++ b/plugins/hls-hlint-plugin/test/testdata/typeapps/hie.yaml @@ -2,4 +2,4 @@ cradle: direct: arguments: - "-XTypeApplications" - - "ApplyRefact1" + - "TypeApplications" From 31fe987f4b8656beea8042e2039760d16d40d992 Mon Sep 17 00:00:00 2001 From: jneira Date: Mon, 1 Nov 2021 20:16:32 +0100 Subject: [PATCH 02/17] Add regression tests --- plugins/hls-hlint-plugin/test/Main.hs | 14 ++++++++++++++ plugins/hls-hlint-plugin/test/testdata/hie.yaml | 1 + 2 files changed, 15 insertions(+) diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs index c6741f7f4a..a2d10fece4 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -154,6 +154,20 @@ suggestionsTests = 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" + + , expectFailBecause "[#2042] To investigate" $ testCase "hlint should warn about unused extensions" $ runHlintSession "" $ do + doc <- openDoc "UnusedExtension.hs" "haskell" + diags@(unusedExt:_) <- waitForDiagnosticsFromSource doc "hlint" + + liftIO $ do + length diags @?= 1 -- "Eta Reduce" and "Redundant Id" + unusedExt ^. L.code @?= Just (InR "refact:Unused LANGUAGE pragma") + , testCase "hlint should not activate extensions like PatternSynonyms" runHlintSession "" $ do + doc <- openDoc "PatternKeyword.hs" "haskell" + diags <- waitForDiagnosticsFrom doc + + -- hlint will report a parse error if PatternSynonyms is enabled + liftIO $ noHlintDiagnostics diags ] where testRefactor file caTitle expected = do diff --git a/plugins/hls-hlint-plugin/test/testdata/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/hie.yaml index 445d93b62b..99fcc6cb99 100644 --- a/plugins/hls-hlint-plugin/test/testdata/hie.yaml +++ b/plugins/hls-hlint-plugin/test/testdata/hie.yaml @@ -11,3 +11,4 @@ cradle: - "IgnoreAnnHlint" - "LambdaCase" - "TwoHints" + - "PatternKeyword" From 1f929057352835f92aa115848eb48ec17f7e15c4 Mon Sep 17 00:00:00 2001 From: jneira Date: Tue, 2 Nov 2021 23:29:56 +0100 Subject: [PATCH 03/17] Add regression test for #1279 --- plugins/hls-hlint-plugin/test/Main.hs | 3 ++- plugins/hls-hlint-plugin/test/testdata/PatternKeyword.hs | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 plugins/hls-hlint-plugin/test/testdata/PatternKeyword.hs diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs index a2d10fece4..0bd2870e53 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -162,7 +162,8 @@ suggestionsTests = liftIO $ do length diags @?= 1 -- "Eta Reduce" and "Redundant Id" unusedExt ^. L.code @?= Just (InR "refact:Unused LANGUAGE pragma") - , testCase "hlint should not activate extensions like PatternSynonyms" runHlintSession "" $ do + + , testCase "hlint should not activate extensions like PatternSynonyms" $ runHlintSession "" $ do doc <- openDoc "PatternKeyword.hs" "haskell" diags <- waitForDiagnosticsFrom doc diff --git a/plugins/hls-hlint-plugin/test/testdata/PatternKeyword.hs b/plugins/hls-hlint-plugin/test/testdata/PatternKeyword.hs new file mode 100644 index 0000000000..21f430e104 --- /dev/null +++ b/plugins/hls-hlint-plugin/test/testdata/PatternKeyword.hs @@ -0,0 +1,3 @@ +module Foo (pattern) where + +pattern = 42 From 665069883e32d36f99d01171844a277bb184a2d8 Mon Sep 17 00:00:00 2001 From: jneira Date: Tue, 2 Nov 2021 23:44:14 +0100 Subject: [PATCH 04/17] Use timeout --- 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 0bd2870e53..1dd352d3fa 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -168,7 +168,7 @@ suggestionsTests = diags <- waitForDiagnosticsFrom doc -- hlint will report a parse error if PatternSynonyms is enabled - liftIO $ noHlintDiagnostics diags + expectNoMoreDiagnostics 3 doc "hlint" ] where testRefactor file caTitle expected = do From fc86b6ca9de0c335112b84c142627edd8e479bd3 Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 3 Nov 2021 20:55:08 +0100 Subject: [PATCH 05/17] Correct waitForProgressDone in ghcide --- ghcide/test/exe/Main.hs | 5 +++++ hls-test-utils/src/Test/Hls.hs | 19 +++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ghcide/test/exe/Main.hs b/ghcide/test/exe/Main.hs index ad54f5d6be..d4231d56b4 100644 --- a/ghcide/test/exe/Main.hs +++ b/ghcide/test/exe/Main.hs @@ -112,11 +112,14 @@ import Test.Tasty.QuickCheck import Text.Printf (printf) import Text.Regex.TDFA ((=~)) +-- | Wait for the next progress begin step waitForProgressBegin :: Session () waitForProgressBegin = skipManyTill anyMessage $ satisfyMaybe $ \case FromServerMess SProgress (NotificationMessage _ _ (ProgressParams _ (Begin _))) -> Just () _ -> Nothing +-- | Wait for the first progress end step +-- Also implemented in hls-test-utils Test.Hls waitForProgressDone :: Session () waitForProgressDone = skipManyTill anyMessage $ satisfyMaybe $ \case FromServerMess SProgress (NotificationMessage _ _ (ProgressParams _ (End _))) -> Just () @@ -124,6 +127,7 @@ waitForProgressDone = skipManyTill anyMessage $ satisfyMaybe $ \case -- | Wait for all progress to be done -- Needs at least one progress done notification to return +-- Also implemented in hls-test-utils Test.Hls waitForAllProgressDone :: Session () waitForAllProgressDone = loop where @@ -133,6 +137,7 @@ waitForAllProgressDone = loop _ -> Nothing done <- null <$> getIncompleteProgressSessions unless done loop + main :: IO () main = do -- We mess with env vars so run single-threaded. diff --git a/hls-test-utils/src/Test/Hls.hs b/hls-test-utils/src/Test/Hls.hs index 9d4014a7e5..9a008885a0 100644 --- a/hls-test-utils/src/Test/Hls.hs +++ b/hls-test-utils/src/Test/Hls.hs @@ -54,7 +54,8 @@ import Development.IDE.Plugin.Test (TestRequest (GetLastBuildKeys, import Development.IDE.Types.Options import GHC.IO.Handle import Ide.Plugin.Config (Config, formattingProvider) -import Ide.PluginUtils (idePluginsToPluginDesc, pluginDescToIdePlugins) +import Ide.PluginUtils (idePluginsToPluginDesc, + pluginDescToIdePlugins) import Ide.Types import Language.LSP.Test import Language.LSP.Types hiding @@ -190,17 +191,11 @@ runSessionWithServer' plugin conf sconf caps root s = withLock lock $ keepCurren putStrLn $ "Finishing canceling (took " <> showDuration t <> "s)" pure x --- | Wait for all progress to be done --- Needs at least one progress done notification to return +-- | Wait for the next progress end step waitForProgressDone :: Session () -waitForProgressDone = loop - where - loop = do - () <- skipManyTill anyMessage $ satisfyMaybe $ \case - FromServerMess SProgress (NotificationMessage _ _ (ProgressParams _ (End _))) -> Just () - _ -> Nothing - done <- null <$> getIncompleteProgressSessions - unless done loop +waitForProgressDone = skipManyTill anyMessage $ satisfyMaybe $ \case + FromServerMess SProgress (NotificationMessage _ _ (ProgressParams _ (End _))) -> Just () + _ -> Nothing -- | Wait for all progress to be done -- Needs at least one progress done notification to return @@ -233,7 +228,7 @@ callTestPlugin cmd = do return $ do e <- _result case A.fromJSON e of - A.Error err -> Left $ ResponseError InternalError (T.pack err) Nothing + A.Error err -> Left $ ResponseError InternalError (T.pack err) Nothing A.Success a -> pure a waitForAction :: String -> TextDocumentIdentifier -> Session (Either ResponseError WaitForIdeRuleResult) From 6024c06dca0bbff45a1a2028cd0aafc2a5f976b8 Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 3 Nov 2021 20:55:41 +0100 Subject: [PATCH 06/17] Remove unnecessary waitForDiagnostics --- 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 1dd352d3fa..6814ff03ec 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -165,8 +165,8 @@ suggestionsTests = , testCase "hlint should not activate extensions like PatternSynonyms" $ runHlintSession "" $ do doc <- openDoc "PatternKeyword.hs" "haskell" - diags <- waitForDiagnosticsFrom doc + waitForAllProgressDone -- hlint will report a parse error if PatternSynonyms is enabled expectNoMoreDiagnostics 3 doc "hlint" ] From 2f42755dedb1496c1c5caa666ed083f3a2d8c5be Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 3 Nov 2021 22:24:31 +0100 Subject: [PATCH 07/17] Mark test broken for hlint on ghclib --- plugins/hls-hlint-plugin/test/Main.hs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs index 6814ff03ec..2806f68f0f 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -87,25 +87,25 @@ suggestionsTests = 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 + , knownBrokenForHlintOnGhcLib "hlint doesn't take in account cpp flag as ghc -D argument" $ + testCase "[#554] hlint diagnostics works with CPP via ghc -XCPP argument" $ runHlintSession "cpp" $ do doc <- openDoc "CppCond.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 + , knownBrokenForHlintOnGhcLib "hlint doesn't take in account cpp flag as ghc -D argument" $ + testCase "[#554] hlint diagnostics works with CPP via language pragma" $ runHlintSession "" $ do doc <- openDoc "CppCond.hs" "haskell" testHlintDiagnostics doc - , testCase "hlint diagnostics works with CPP via -XCPP argument and flag via #include header (#554)" $ runHlintSession "cpp" $ do + , testCase "[#554] hlint diagnostics works with CPP via -XCPP argument and flag via #include header" $ runHlintSession "cpp" $ do doc <- openDoc "CppHeader.hs" "haskell" testHlintDiagnostics doc - , testCase "apply-refact works with -XLambdaCase argument (#590)" $ runHlintSession "lambdacase" $ do + , testCase "[#590] apply-refact works with -XLambdaCase argument" $ runHlintSession "lambdacase" $ do testRefactor "LambdaCase.hs" "Redundant bracket" expectedLambdaCase - , testCase "apply-refact works with -XTypeApplications argument (#1242)" $ runHlintSession "typeapps" $ do + , testCase "[#1242] apply-refact works with -XTypeApplications argument" $ runHlintSession "typeapps" $ do testRefactor "TypeApplication.hs" "Redundant bracket" expectedTypeApp @@ -131,7 +131,7 @@ suggestionsTests = doc <- openDoc "IgnoreAnn.hs" "haskell" expectNoMoreDiagnostics 3 doc "hlint" - , knownBrokenForGhcVersions [GHC810, GHC90] "hlint plugin doesn't honour HLINT annotations (#838)" $ + , knownBrokenForHlintOnRawGhc "[#838] hlint plugin doesn't honour HLINT annotations" $ testCase "hlint diagnostics ignore hints honouring HLINT annotations" $ runHlintSession "" $ do doc <- openDoc "IgnoreAnnHlint.hs" "haskell" expectNoMoreDiagnostics 3 doc "hlint" @@ -163,7 +163,8 @@ suggestionsTests = length diags @?= 1 -- "Eta Reduce" and "Redundant Id" unusedExt ^. L.code @?= Just (InR "refact:Unused LANGUAGE pragma") - , testCase "hlint should not activate extensions like PatternSynonyms" $ runHlintSession "" $ do + , knownBrokenForHlintOnGhcLib "[#1279] hlint uses a fixed set of extensions" $ + testCase "hlint should not activate extensions like PatternSynonyms" $ runHlintSession "" $ do doc <- openDoc "PatternKeyword.hs" "haskell" waitForAllProgressDone @@ -301,3 +302,9 @@ hlintConfigWithFlags flags = where unObject (Object obj) = obj unObject _ = undefined + +knownBrokenForHlintOnGhcLib :: String -> TestTree -> TestTree +knownBrokenForHlintOnGhcLib = knownBrokenForGhcVersions [GHC88, GHC86] + +knownBrokenForHlintOnRawGhc :: String -> TestTree -> TestTree +knownBrokenForHlintOnRawGhc = knownBrokenForGhcVersions [GHC810, GHC90] From 647efd3d50cc02a5023b7cc55d694bce3245e86a Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 3 Nov 2021 23:02:09 +0100 Subject: [PATCH 08/17] Add test over unused extensions --- plugins/hls-hlint-plugin/test/Main.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs index 2806f68f0f..b9695f7efb 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -155,12 +155,12 @@ suggestionsTests = liftIO $ not (hasApplyAll thirdLine) @? "Unexpected apply all code action" liftIO $ hasApplyAll multiLine @? "Missing apply all code action" - , expectFailBecause "[#2042] To investigate" $ testCase "hlint should warn about unused extensions" $ runHlintSession "" $ do + , testCase "hlint should warn about unused extensions" $ runHlintSession "unusedext" $ do doc <- openDoc "UnusedExtension.hs" "haskell" diags@(unusedExt:_) <- waitForDiagnosticsFromSource doc "hlint" liftIO $ do - length diags @?= 1 -- "Eta Reduce" and "Redundant Id" + length diags @?= 1 unusedExt ^. L.code @?= Just (InR "refact:Unused LANGUAGE pragma") , knownBrokenForHlintOnGhcLib "[#1279] hlint uses a fixed set of extensions" $ From e703df40bab9344d0f9d2e12ff9fe4cd44cae32e Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 3 Nov 2021 23:34:11 +0100 Subject: [PATCH 09/17] Add test for #2042 --- plugins/hls-hlint-plugin/test/Main.hs | 5 +++-- .../test/testdata/unusedext/UnusedExtension.hs | 1 + plugins/hls-hlint-plugin/test/testdata/unusedext/hie.yaml | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 plugins/hls-hlint-plugin/test/testdata/unusedext/UnusedExtension.hs create mode 100644 plugins/hls-hlint-plugin/test/testdata/unusedext/hie.yaml diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs index b9695f7efb..41c9f03dea 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -155,7 +155,8 @@ suggestionsTests = liftIO $ not (hasApplyAll thirdLine) @? "Unexpected apply all code action" liftIO $ hasApplyAll multiLine @? "Missing apply all code action" - , testCase "hlint should warn about unused extensions" $ runHlintSession "unusedext" $ do + , knownBrokenForHlintOnRawGhc "[#2042] maybe hlint is ignoring pragmas" $ + testCase "hlint should warn about unused extensions" $ runHlintSession "unusedext" $ do doc <- openDoc "UnusedExtension.hs" "haskell" diags@(unusedExt:_) <- waitForDiagnosticsFromSource doc "hlint" @@ -164,7 +165,7 @@ suggestionsTests = unusedExt ^. L.code @?= Just (InR "refact:Unused LANGUAGE pragma") , knownBrokenForHlintOnGhcLib "[#1279] hlint uses a fixed set of extensions" $ - testCase "hlint should not activate extensions like PatternSynonyms" $ runHlintSession "" $ do + testCase "hlint should not activate extensions like PatternSynonyms" $ runHlintSession "" $ do doc <- openDoc "PatternKeyword.hs" "haskell" waitForAllProgressDone diff --git a/plugins/hls-hlint-plugin/test/testdata/unusedext/UnusedExtension.hs b/plugins/hls-hlint-plugin/test/testdata/unusedext/UnusedExtension.hs new file mode 100644 index 0000000000..f652e62f05 --- /dev/null +++ b/plugins/hls-hlint-plugin/test/testdata/unusedext/UnusedExtension.hs @@ -0,0 +1 @@ +{-# LANGUAGE BangPatterns #-} diff --git a/plugins/hls-hlint-plugin/test/testdata/unusedext/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/unusedext/hie.yaml new file mode 100644 index 0000000000..5d6dfc5138 --- /dev/null +++ b/plugins/hls-hlint-plugin/test/testdata/unusedext/hie.yaml @@ -0,0 +1,4 @@ +cradle: + direct: + arguments: + - "UnusedExtension" From d44baecaa144d7fddc602ff07aa07005bb54e593 Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 3 Nov 2021 23:55:37 +0100 Subject: [PATCH 10/17] Add data for #2280 --- plugins/hls-hlint-plugin/test/testdata/StrictData.hs | 2 ++ plugins/hls-hlint-plugin/test/testdata/hie.yaml | 1 + 2 files changed, 3 insertions(+) create mode 100644 plugins/hls-hlint-plugin/test/testdata/StrictData.hs diff --git a/plugins/hls-hlint-plugin/test/testdata/StrictData.hs b/plugins/hls-hlint-plugin/test/testdata/StrictData.hs new file mode 100644 index 0000000000..0865b611e3 --- /dev/null +++ b/plugins/hls-hlint-plugin/test/testdata/StrictData.hs @@ -0,0 +1,2 @@ +{-# LANGUAGE Strict #-} +f ~x = x diff --git a/plugins/hls-hlint-plugin/test/testdata/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/hie.yaml index 99fcc6cb99..cd9c0df566 100644 --- a/plugins/hls-hlint-plugin/test/testdata/hie.yaml +++ b/plugins/hls-hlint-plugin/test/testdata/hie.yaml @@ -12,3 +12,4 @@ cradle: - "LambdaCase" - "TwoHints" - "PatternKeyword" + - "StrictData" From c65e354339656436974b83fa8201e2f26a806fa5 Mon Sep 17 00:00:00 2001 From: jneira Date: Thu, 4 Nov 2021 13:45:09 +0100 Subject: [PATCH 11/17] Use waitForAllProgressDone --- plugins/hls-splice-plugin/test/Main.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/hls-splice-plugin/test/Main.hs b/plugins/hls-splice-plugin/test/Main.hs index 23c187846c..44494f5f22 100644 --- a/plugins/hls-splice-plugin/test/Main.hs +++ b/plugins/hls-splice-plugin/test/Main.hs @@ -86,8 +86,7 @@ goldenTestWithEdit fp tc line col = { _start = Position 0 0 , _end = Position (length lns + 1) 1 } - waitForProgressDone -- cradle - waitForProgressDone + waitForAllProgressDone -- cradle alt <- liftIO $ T.readFile (fp <.> "error.hs") void $ applyEdit doc $ TextEdit theRange alt changeDoc doc [TextDocumentContentChangeEvent (Just theRange) Nothing alt] From 6482215ced44cea09e760b351deaf1001e3b7007 Mon Sep 17 00:00:00 2001 From: jneira Date: Thu, 4 Nov 2021 14:48:49 +0100 Subject: [PATCH 12/17] Add test for #2280 --- plugins/hls-hlint-plugin/test/Main.hs | 7 +++++++ plugins/hls-splice-plugin/test/Main.hs | 1 + 2 files changed, 8 insertions(+) diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs index 41c9f03dea..c6c7f75ecd 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -170,6 +170,13 @@ suggestionsTests = waitForAllProgressDone -- hlint will report a parse error if PatternSynonyms is enabled + expectNoMoreDiagnostics 3 doc "hlint" + , knownBrokenForHlintOnRawGhc "[#2280] maybe hlint is ignoring pragmas" $ + testCase "hlint should not warn about redundant irrefutable pattern with LANGUAGE Strict" $ runHlintSession "" $ do + doc <- openDoc "StrictDo.hs" "haskell" + + waitForAllProgressDone + expectNoMoreDiagnostics 3 doc "hlint" ] where diff --git a/plugins/hls-splice-plugin/test/Main.hs b/plugins/hls-splice-plugin/test/Main.hs index 44494f5f22..1d0b2783a9 100644 --- a/plugins/hls-splice-plugin/test/Main.hs +++ b/plugins/hls-splice-plugin/test/Main.hs @@ -87,6 +87,7 @@ goldenTestWithEdit fp tc line col = , _end = Position (length lns + 1) 1 } waitForAllProgressDone -- cradle + waitForAllProgressDone alt <- liftIO $ T.readFile (fp <.> "error.hs") void $ applyEdit doc $ TextEdit theRange alt changeDoc doc [TextDocumentContentChangeEvent (Just theRange) Nothing alt] From 92f776d1563856adfef442cd25a0823493581221 Mon Sep 17 00:00:00 2001 From: Javier Neira Date: Thu, 4 Nov 2021 17:27:58 +0100 Subject: [PATCH 13/17] correct module name --- 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 c6c7f75ecd..41b99c9734 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -173,7 +173,7 @@ suggestionsTests = expectNoMoreDiagnostics 3 doc "hlint" , knownBrokenForHlintOnRawGhc "[#2280] maybe hlint is ignoring pragmas" $ testCase "hlint should not warn about redundant irrefutable pattern with LANGUAGE Strict" $ runHlintSession "" $ do - doc <- openDoc "StrictDo.hs" "haskell" + doc <- openDoc "StrictData.hs" "haskell" waitForAllProgressDone From ebd9445ca5d33f722a4cf7946fcbe04d30b9d97a Mon Sep 17 00:00:00 2001 From: jneira Date: Fri, 5 Nov 2021 22:24:47 +0100 Subject: [PATCH 14/17] Add reproduction for #2290 --- plugins/hls-hlint-plugin/test/Main.hs | 6 ++++++ .../hls-hlint-plugin/test/testdata/TwoHintsAndComment.hs | 3 +++ plugins/hls-hlint-plugin/test/testdata/hie.yaml | 1 + 3 files changed, 10 insertions(+) create mode 100644 plugins/hls-hlint-plugin/test/testdata/TwoHintsAndComment.hs diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs index 41b99c9734..94505295ad 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -139,6 +139,9 @@ suggestionsTests = , testCase "apply-refact preserve regular comments" $ runHlintSession "" $ do testRefactor "Comments.hs" "Redundant bracket" expectedComments + , testCase "[#2290] apply all hints works with a trailing comment" $ runHlintSession "" $ do + testRefactor "TwoHintsAndComment.hs" "Apply all hints" expectedComments2 + , testCase "applyAll is shown only when there is at least one diagnostic in range" $ runHlintSession "" $ do doc <- openDoc "TwoHints.hs" "haskell" _ <- waitForDiagnosticsFromSource doc "hlint" @@ -212,6 +215,9 @@ suggestionsTests = , "f = {- inline comment -}{- inline comment inside refactored code -} 1 -- ending comment", "" , "-- final comment" ] + expectedComments2 = [ "module TwoHintsAndComment where" + , "biggest items = foldr1 max -- the line above will show two hlint hints, \"eta reduce\" and \"use maximum\"" + ] expectedTypeApp = [ "module TypeApplication where", "" , "a = id @Int 1" ] diff --git a/plugins/hls-hlint-plugin/test/testdata/TwoHintsAndComment.hs b/plugins/hls-hlint-plugin/test/testdata/TwoHintsAndComment.hs new file mode 100644 index 0000000000..615e85f8e2 --- /dev/null +++ b/plugins/hls-hlint-plugin/test/testdata/TwoHintsAndComment.hs @@ -0,0 +1,3 @@ +module TwoHintsAndComments where + +biggest items = foldr1 max items -- the line above will show two hlint hints, "eta reduce" and "use maximum" diff --git a/plugins/hls-hlint-plugin/test/testdata/hie.yaml b/plugins/hls-hlint-plugin/test/testdata/hie.yaml index cd9c0df566..28e1a7bbc1 100644 --- a/plugins/hls-hlint-plugin/test/testdata/hie.yaml +++ b/plugins/hls-hlint-plugin/test/testdata/hie.yaml @@ -13,3 +13,4 @@ cradle: - "TwoHints" - "PatternKeyword" - "StrictData" + - "TwoHintsAndComment" From 8fe3e0c4464e6c60412dcaf40b8dd8d76341fd04 Mon Sep 17 00:00:00 2001 From: jneira Date: Fri, 5 Nov 2021 23:00:40 +0100 Subject: [PATCH 15/17] Correct test case --- plugins/hls-hlint-plugin/test/Main.hs | 2 +- plugins/hls-hlint-plugin/test/testdata/TwoHintsAndComment.hs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs index 94505295ad..4c2007ac3c 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -216,7 +216,7 @@ suggestionsTests = , "-- final comment" ] expectedComments2 = [ "module TwoHintsAndComment where" - , "biggest items = foldr1 max -- the line above will show two hlint hints, \"eta reduce\" and \"use maximum\"" + , "biggest = foldr1 max -- the line above will show two hlint hints, \"eta reduce\" and \"use maximum\"" ] expectedTypeApp = [ "module TypeApplication where", "" , "a = id @Int 1" diff --git a/plugins/hls-hlint-plugin/test/testdata/TwoHintsAndComment.hs b/plugins/hls-hlint-plugin/test/testdata/TwoHintsAndComment.hs index 615e85f8e2..f017bd0762 100644 --- a/plugins/hls-hlint-plugin/test/testdata/TwoHintsAndComment.hs +++ b/plugins/hls-hlint-plugin/test/testdata/TwoHintsAndComment.hs @@ -1,3 +1,2 @@ -module TwoHintsAndComments where - +module TwoHintsAndComment where biggest items = foldr1 max items -- the line above will show two hlint hints, "eta reduce" and "use maximum" From 6d41d82eaf6cce14263e4b970fb8631c56a2993f Mon Sep 17 00:00:00 2001 From: Javier Neira Date: Wed, 10 Nov 2021 07:55:16 +0100 Subject: [PATCH 16/17] Comment about knownBrokenForHlint* --- plugins/hls-hlint-plugin/test/Main.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/hls-hlint-plugin/test/Main.hs b/plugins/hls-hlint-plugin/test/Main.hs index 4c2007ac3c..67446c5d2c 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -317,6 +317,13 @@ hlintConfigWithFlags flags = unObject (Object obj) = obj unObject _ = undefined +-- We have two main code paths in the plugin depending on how hlint interacts with ghc: +-- * One when hlint uses ghc-lib (all ghc versions but the last version supported by hlint) +-- * Another one when hlint uses directly ghc (only one version, which not have to be the last version supported by ghcide) +-- As we always are using ghc through ghcide the code to get the ghc parsed AST differs +-- So the issues and bugs usually only affects to one oce path or the other. +-- Although a given hlint version supports one direct ghc, we could use several versions of hlint +-- each one supporting a different ghc version. It should be a temporary situation though. knownBrokenForHlintOnGhcLib :: String -> TestTree -> TestTree knownBrokenForHlintOnGhcLib = knownBrokenForGhcVersions [GHC88, GHC86] From dae293b5966ccf61255cc0e472ca39c0334bbe15 Mon Sep 17 00:00:00 2001 From: Javier Neira Date: Wed, 10 Nov 2021 07:56:58 +0100 Subject: [PATCH 17/17] Correction --- 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 67446c5d2c..19619dcffb 100644 --- a/plugins/hls-hlint-plugin/test/Main.hs +++ b/plugins/hls-hlint-plugin/test/Main.hs @@ -321,7 +321,7 @@ hlintConfigWithFlags flags = -- * One when hlint uses ghc-lib (all ghc versions but the last version supported by hlint) -- * Another one when hlint uses directly ghc (only one version, which not have to be the last version supported by ghcide) -- As we always are using ghc through ghcide the code to get the ghc parsed AST differs --- So the issues and bugs usually only affects to one oce path or the other. +-- So the issues and bugs usually only affects to one code path or the other. -- Although a given hlint version supports one direct ghc, we could use several versions of hlint -- each one supporting a different ghc version. It should be a temporary situation though. knownBrokenForHlintOnGhcLib :: String -> TestTree -> TestTree