Skip to content

Commit 4ad8f08

Browse files
committed
Replace some expectFail references with explicit checks
1 parent f628754 commit 4ad8f08

File tree

12 files changed

+88
-77
lines changed

12 files changed

+88
-77
lines changed

plugins/hls-explicit-fixity-plugin/test/Main.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ tests = testGroup "Explicit fixity"
4040
, hoverTest "signature" (Position 35 2) "infixr 9 `>>>:`"
4141
, hoverTest "operator" (Position 36 2) "infixr 9 `>>>:`"
4242
, hoverTest "escape" (Position 39 2) "infixl 3 `~\\:`"
43-
-- Ensure that there is no one extra new line in import statement
44-
, expectFail $ hoverTest "import" (Position 2 18) "Control.Monad***"
45-
-- Known issue, See https://github.com/haskell/haskell-language-server/pull/2973/files#r916535742
46-
, expectFail $ hoverTestImport "import" (Position 4 7) "infixr 9 `>>>:`"
43+
-- TODO: Ensure that there is no one extra new line in import statement
44+
, hoverTest "import" (Position 2 18) "Control.Monad\n\n"
45+
, hoverTestImport "import" (Position 4 7) "infixr 9 `>>>:`"
4746
]
4847

4948
hoverTest :: TestName -> Position -> T.Text -> TestTree

plugins/hls-explicit-imports-plugin/test/Main.hs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Main
77
) where
88

99
import Control.Lens ((^.))
10+
import Control.Monad (unless)
1011
import Data.Either.Extra
1112
import Data.Foldable (find)
1213
import Data.Text (Text)
@@ -47,7 +48,7 @@ main = defaultTestRunner $ testGroup "import-actions"
4748
, inlayHintsTestWithoutCap "ExplicitOnlyThis" 3 $ (@=?) []
4849
-- Only when the client does not support inlay hints, explicit will be provided by code lens
4950
, codeLensGoldenTest codeActionNoInlayHintsCaps notRefineImports "ExplicitUsualCase" 0
50-
, expectFail $ codeLensGoldenTest codeActionNoResolveCaps notRefineImports "ExplicitUsualCase" 0
51+
, noCodeLensTest codeActionNoResolveCaps "ExplicitUsualCase"
5152
, codeActionBreakFile "ExplicitBreakFile" 4 0
5253
, inlayHintsTestWithCap "ExplicitBreakFile" 3 $ (@=?)
5354
[mkInlayHint (Position 3 16) "( a1 )"
@@ -193,6 +194,23 @@ codeLensGoldenTest caps predicate fp i = goldenWithImportActions " code lens" fp
193194
(CodeLens {_command = Just c}) <- pure (filter predicate resolvedCodeLenses !! i)
194195
executeCmd c
195196

197+
noCodeLensTest :: ClientCapabilities -> FilePath -> TestTree
198+
noCodeLensTest caps fp = do
199+
testCase (fp ++ " no code lens") $ run $ \_ -> do
200+
doc <- openDoc (fp ++ ".hs") "haskell"
201+
codeLenses <- getCodeLenses doc
202+
resolvedCodeLenses <- for codeLenses resolveCodeLens
203+
unless (null resolvedCodeLenses) $
204+
liftIO (assertFailure "Unexpected code lens")
205+
where
206+
run = runSessionWithTestConfig def
207+
{ testDirLocation = Left testDataDir
208+
, testConfigCaps = caps
209+
, testLspConfig = def
210+
, testPluginDescriptor = explicitImportsPlugin
211+
}
212+
213+
196214
notRefineImports :: CodeLens -> Bool
197215
notRefineImports (CodeLens _ (Just (Command text _ _)) _)
198216
| "Refine imports to" `T.isPrefixOf` text = False

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

Lines changed: 55 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -337,67 +337,61 @@ insertImportTests = testGroup "insert import"
337337
"WhereDeclLowerInFileWithCommentsBeforeIt.hs"
338338
"WhereDeclLowerInFileWithCommentsBeforeIt.expected.hs"
339339
"import Data.Int"
340-
, expectFailBecause
341-
"'findNextPragmaPosition' function doesn't account for case when shebang is not placed at top of file"
342-
(checkImport
343-
"Shebang not at top with spaces"
344-
"ShebangNotAtTopWithSpaces.hs"
345-
"ShebangNotAtTopWithSpaces.expected.hs"
346-
"import Data.Monoid")
347-
, expectFailBecause
348-
"'findNextPragmaPosition' function doesn't account for case when shebang is not placed at top of file"
349-
(checkImport
350-
"Shebang not at top no space"
351-
"ShebangNotAtTopNoSpace.hs"
352-
"ShebangNotAtTopNoSpace.expected.hs"
353-
"import Data.Monoid")
354-
, expectFailBecause
355-
("'findNextPragmaPosition' function doesn't account for case "
356-
++ "when OPTIONS_GHC pragma is not placed at top of file")
357-
(checkImport
358-
"OPTIONS_GHC pragma not at top with spaces"
359-
"OptionsNotAtTopWithSpaces.hs"
360-
"OptionsNotAtTopWithSpaces.expected.hs"
361-
"import Data.Monoid")
362-
, expectFailBecause
363-
("'findNextPragmaPosition' function doesn't account for "
364-
++ "case when shebang is not placed at top of file")
365-
(checkImport
366-
"Shebang not at top of file"
367-
"ShebangNotAtTop.hs"
368-
"ShebangNotAtTop.expected.hs"
369-
"import Data.Monoid")
370-
, expectFailBecause
371-
("'findNextPragmaPosition' function doesn't account for case "
372-
++ "when OPTIONS_GHC is not placed at top of file")
373-
(checkImport
374-
"OPTIONS_GHC pragma not at top of file"
375-
"OptionsPragmaNotAtTop.hs"
376-
"OptionsPragmaNotAtTop.expected.hs"
377-
"import Data.Monoid")
378-
, expectFailBecause
379-
("'findNextPragmaPosition' function doesn't account for case when "
380-
++ "OPTIONS_GHC pragma is not placed at top of file")
381-
(checkImport
382-
"pragma not at top with comment at top"
383-
"PragmaNotAtTopWithCommentsAtTop.hs"
384-
"PragmaNotAtTopWithCommentsAtTop.expected.hs"
385-
"import Data.Monoid")
386-
, expectFailBecause
387-
("'findNextPragmaPosition' function doesn't account for case when "
388-
++ "OPTIONS_GHC pragma is not placed at top of file")
389-
(checkImport
390-
"pragma not at top multiple comments"
391-
"PragmaNotAtTopMultipleComments.hs"
392-
"PragmaNotAtTopMultipleComments.expected.hs"
393-
"import Data.Monoid")
394-
, expectFailBecause
395-
"'findNextPragmaPosition' function doesn't account for case of multiline pragmas"
396-
(checkImport
397-
"after multiline language pragmas"
398-
"MultiLinePragma.hs"
399-
"MultiLinePragma.expected.hs"
400-
"import Data.Monoid")
340+
-- TODO: 'findNextPragmaPosition' function doesn't account for case when shebang is not
341+
-- placed at top of file"
342+
, checkImport
343+
"Shebang not at top with spaces"
344+
"ShebangNotAtTopWithSpaces.hs"
345+
"ShebangNotAtTopWithSpaces.expected.hs"
346+
"import Data.Monoid"
347+
-- TODO: 'findNextPragmaPosition' function doesn't account for case when shebang is not
348+
-- placed at top of file"
349+
, checkImport
350+
"Shebang not at top no space"
351+
"ShebangNotAtTopNoSpace.hs"
352+
"ShebangNotAtTopNoSpace.expected.hs"
353+
"import Data.Monoid"
354+
-- TODO: 'findNextPragmaPosition' function doesn't account for case when OPTIONS_GHC pragma is
355+
-- not placed at top of file
356+
, checkImport
357+
"OPTIONS_GHC pragma not at top with spaces"
358+
"OptionsNotAtTopWithSpaces.hs"
359+
"OptionsNotAtTopWithSpaces.expected.hs"
360+
"import Data.Monoid"
361+
-- TODO: findNextPragmaPosition' function doesn't account for case when shebang is not placed
362+
-- at top of file
363+
, checkImport
364+
"Shebang not at top of file"
365+
"ShebangNotAtTop.hs"
366+
"ShebangNotAtTop.expected.hs"
367+
"import Data.Monoid"
368+
-- TODO: findNextPragmaPosition' function doesn't account for case when OPTIONS_GHC is not
369+
-- placed at top of file
370+
, checkImport
371+
"OPTIONS_GHC pragma not at top of file"
372+
"OptionsPragmaNotAtTop.hs"
373+
"OptionsPragmaNotAtTop.expected.hs"
374+
"import Data.Monoid"
375+
-- TODO: findNextPragmaPosition' function doesn't account for case when OPTIONS_GHC pragma is
376+
-- not placed at top of file
377+
, checkImport
378+
"pragma not at top with comment at top"
379+
"PragmaNotAtTopWithCommentsAtTop.hs"
380+
"PragmaNotAtTopWithCommentsAtTop.expected.hs"
381+
"import Data.Monoid"
382+
-- TODO: findNextPragmaPosition' function doesn't account for case when OPTIONS_GHC pragma is
383+
-- not placed at top of file
384+
, checkImport
385+
"pragma not at top multiple comments"
386+
"PragmaNotAtTopMultipleComments.hs"
387+
"PragmaNotAtTopMultipleComments.expected.hs"
388+
"import Data.Monoid"
389+
-- TODO: 'findNextPragmaPosition' function doesn't account for case of multiline pragmas
390+
, checkImport
391+
"after multiline language pragmas"
392+
"MultiLinePragma.hs"
393+
"MultiLinePragma.expected.hs"
394+
"import Data.Monoid"
401395
, checkImport
402396
"pragmas not at top with module declaration"
403397
"PragmaNotAtTopWithModuleDecl.hs"

plugins/hls-refactor-plugin/test/data/import-placement/MultiLinePragma.expected.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{-# LANGUAGE RecordWildCards,
44
OverloadedStrings #-}
55
{-# OPTIONS_GHC -Wall,
6-
-Wno-unused-imports #-}
76
import Data.Monoid
7+
-Wno-unused-imports #-}
88

99

1010
-- some comment

plugins/hls-refactor-plugin/test/data/import-placement/OptionsNotAtTopWithSpaces.expected.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
{-# LANGUAGE TupleSections #-}
5-
import Data.Monoid
65

76

87

@@ -11,6 +10,7 @@ class Semigroup a => SomeData a
1110
instance SomeData All
1211

1312
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
13+
import Data.Monoid
1414

1515
addOne :: Int -> Int
1616
addOne x = x + 1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import Data.Monoid
21
class Semigroup a => SomeData a
32
instance SomeData All
43

54
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
5+
import Data.Monoid
66

77
addOne :: Int -> Int
88
addOne x = x + 1

plugins/hls-refactor-plugin/test/data/import-placement/PragmaNotAtTopMultipleComments.expected.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ comment
99
-}
1010

1111
{-# LANGUAGE TupleSections #-}
12-
import Data.Monoid
1312
{- some comment -}
1413

1514
-- again
@@ -18,6 +17,7 @@ instance SomeData All
1817

1918
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
2019
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
20+
import Data.Monoid
2121

2222
addOne :: Int -> Int
2323
addOne x = x + 1

plugins/hls-refactor-plugin/test/data/import-placement/PragmaNotAtTopWithCommentsAtTop.expected.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
-- another comment
55

66
{-# LANGUAGE TupleSections #-}
7-
import Data.Monoid
87
{- some comment -}
98

109

@@ -13,6 +12,7 @@ instance SomeData All
1312

1413
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
1514
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
15+
import Data.Monoid
1616

1717
addOne :: Int -> Int
1818
addOne x = x + 1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{-# LANGUAGE OverloadedStrings #-}
2-
import Data.Monoid
32

43
class Semigroup a => SomeData a
54
instance SomeData All
65

76
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
7+
import Data.Monoid
88

99
f :: Int -> Int
1010
f x = x * x
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import Data.Monoid
21
class Semigroup a => SomeData a
32
instance SomeData All
43

54
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
5+
import Data.Monoid
66

77
f :: Int -> Int
88
f x = x * x

plugins/hls-refactor-plugin/test/data/import-placement/ShebangNotAtTopWithSpaces.expected.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
{-# LANGUAGE TupleSections #-}
9-
import Data.Monoid
109

1110

1211

@@ -16,6 +15,7 @@ instance SomeData All
1615

1716
#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])"
1817
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
18+
import Data.Monoid
1919

2020
addOne :: Int -> Int
2121
addOne x = x + 1

test/functional/Config.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ genericConfigTests = testGroup "generic plugin config"
4343
setHlsConfig $ changeConfig "someplugin" def{plcHoverOn = False}
4444
-- getting only the expected diagnostics means the plugin wasn't enabled
4545
expectDiagnostics standardDiagnostics
46-
, expectFailBecause "partial config is not supported" $
47-
testCase "custom defaults and non overlapping user config" $ runConfigSession "diagnostics" $ do
46+
-- TODO: Partial config is not supported
47+
, testCase "custom defaults and non overlapping user config" $ runConfigSession "diagnostics" $ do
4848
_doc <- createDoc "Foo.hs" "haskell" "module Foo where\nfoo = False"
4949
-- test that the user config doesn't accidentally override the initial config
5050
setHlsConfig $ changeConfig testPluginId def{plcHoverOn = False}
5151
-- getting only the expected diagnostics means the plugin wasn't enabled
52-
expectDiagnostics standardDiagnostics
52+
expectDiagnostics testPluginDiagnostics
5353
, testCase "custom defaults and overlapping user plugin config" $ runConfigSession "diagnostics" $ do
5454
_doc <- createDoc "Foo.hs" "haskell" "module Foo where\nfoo = False"
5555
-- test that the user config overrides the default initial config

0 commit comments

Comments
 (0)