Skip to content

Commit edfc677

Browse files
committed
Replace expectFail references with explicit checks
1 parent f628754 commit edfc677

File tree

20 files changed

+165
-147
lines changed

20 files changed

+165
-147
lines changed

ghcide/test/exe/Config.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module Config(
3030

3131
import Control.Exception (bracket_)
3232
import Control.Lens.Setter ((.~))
33+
import Control.Monad (unless)
3334
import Data.Foldable (traverse_)
3435
import Data.Function ((&))
3536
import qualified Data.Text as T
@@ -100,6 +101,7 @@ pattern R x y x' y' = Range (Position x y) (Position x' y')
100101

101102
data Expect
102103
= ExpectRange Range -- Both gotoDef and hover should report this range
104+
| ExpectRanges [Range] -- definition lookup with multiple results
103105
| ExpectLocation Location
104106
-- | ExpectDefRange Range -- Only gotoDef should report this range
105107
| ExpectHoverRange Range -- Only hover should report this range
@@ -124,6 +126,8 @@ checkDefs (defToLocation -> defs) mkExpectations = traverse_ check =<< mkExpecta
124126
check (ExpectRange expectedRange) = do
125127
def <- assertOneDefinitionFound defs
126128
assertRangeCorrect def expectedRange
129+
check (ExpectRanges ranges) =
130+
traverse_ (assertHasRange defs) ranges
127131
check (ExpectLocation expectedLocation) = do
128132
def <- assertOneDefinitionFound defs
129133
liftIO $ do
@@ -142,6 +146,10 @@ checkDefs (defToLocation -> defs) mkExpectations = traverse_ check =<< mkExpecta
142146
assertRangeCorrect Location{_range = foundRange} expectedRange =
143147
liftIO $ expectedRange @=? foundRange
144148

149+
assertHasRange actualRanges expectedRange = do
150+
let hasRange = any (\Location{_range=foundRange} -> foundRange == expectedRange) actualRanges
151+
unless hasRange $ liftIO $ assertFailure $
152+
"expected range: " <> show expectedRange <> "\nbut got ranges: " <> show defs
145153

146154
canonicalizeLocation :: Location -> IO Location
147155
canonicalizeLocation (Location uri range) = Location <$> canonicalizeUri uri <*> pure range

ghcide/test/exe/FindDefinitionAndHoverTests.hs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ tests = let
119119
hover = (getHover , checkHover)
120120

121121
-- search locations expectations on results
122-
fffL4 = fffR ^. L.start; fffR = mkRange 8 4 8 7 ; fff = [ExpectRange fffR]
123-
fffL8 = Position 12 4 ;
122+
-- TODO: Lookup of record field should return exactly one result
123+
fffL4 = fffR ^. L.start; fffR = mkRange 8 4 8 7; fff = [ExpectRanges [fffR, mkRange 7 23 9 16]]
124+
fffL8 = Position 12 4 ; fff' = [ExpectRange fffR]
124125
fffL14 = Position 18 7 ;
125126
aL20 = Position 19 15
126127
aaaL14 = Position 18 20 ; aaa = [mkR 11 0 11 3]
@@ -148,13 +149,19 @@ tests = let
148149
; constr = [ExpectHoverText ["Monad m"]]
149150
eitL40 = Position 44 28 ; kindE = [ExpectHoverText [":: Type -> Type -> Type\n"]]
150151
intL40 = Position 44 34 ; kindI = [ExpectHoverText [":: Type\n"]]
151-
tvrL40 = Position 44 37 ; kindV = [ExpectHoverText [":: * -> *\n"]]
152-
intL41 = Position 45 20 ; litI = [ExpectHoverText ["7518"]]
153-
chrL36 = Position 41 24 ; litC = [ExpectHoverText ["'f'"]]
154-
txtL8 = Position 12 14 ; litT = [ExpectHoverText ["\"dfgy\""]]
155-
lstL43 = Position 47 12 ; litL = [ExpectHoverText ["[8391 :: Int, 6268]"]]
152+
-- TODO: Kind signature of type variables should be `Type -> Type`
153+
tvrL40 = Position 44 37 ; kindV = [ExpectHoverText ["m"]]
154+
-- TODO: Hover of integer literal should be `7518`
155+
intL41 = Position 45 20 ; litI = [ExpectHoverText ["_ :: Int"]]
156+
-- TODO: Hover info of char literal should be `'f'`
157+
chrL36 = Position 41 24 ; litC = [ExpectHoverText ["_ :: Char"]]
158+
-- TODO: Hover info of Text literal should be `"dfgy"`
159+
txtL8 = Position 12 14 ; litT = [ExpectHoverText ["_ :: Text"]]
160+
-- TODO: Hover info of List literal should be `[8391 :: Int, 6268]`
161+
lstL43 = Position 47 12 ; litL = [ExpectHoverText ["[Int]"]]
156162
outL45 = Position 49 3 ; outSig = [ExpectHoverText ["outer", "Bool"], mkR 50 0 50 5]
157-
innL48 = Position 52 5 ; innSig = [ExpectHoverText ["inner", "Char"], mkR 49 2 49 7]
163+
-- TODO: Hover info of local function signature should be `inner :: Bool`
164+
innL48 = Position 52 5 ; innSig = [ExpectHoverText ["inner"], mkR 53 2 53 7]
158165
holeL60 = Position 62 7 ; hleInfo = [ExpectHoverText ["_ ::"]]
159166
holeL65 = Position 65 8 ; hleInfo2 = [ExpectHoverText ["_ :: a -> Maybe a"]]
160167
cccL17 = Position 17 16 ; docLink = [ExpectHoverTextRegex "\\*Defined in 'GHC.Types'\\* \\*\\(ghc-prim-[0-9.]+\\)\\*\n\n"]
@@ -167,9 +174,9 @@ tests = let
167174
mkFindTests
168175
-- def hover look expect
169176
[ -- It suggests either going to the constructor or to the field
170-
test broken yes fffL4 fff "field in record definition"
171-
, test yes yes fffL8 fff "field in record construction #1102"
172-
, test yes yes fffL14 fff "field name used as accessor" -- https://github.com/haskell/ghcide/pull/120 in Calculate.hs
177+
test yes yes fffL4 fff "field in record definition"
178+
, test yes yes fffL8 fff' "field in record construction #1102"
179+
, test yes yes fffL14 fff' "field name used as accessor" -- https://github.com/haskell/ghcide/pull/120 in Calculate.hs
173180
, test yes yes aaaL14 aaa "top-level name" -- https://github.com/haskell/ghcide/pull/120
174181
, test yes yes dcL7 tcDC "data constructor record #1029"
175182
, test yes yes dcL12 tcDC "data constructor plain" -- https://github.com/haskell/ghcide/pull/121
@@ -194,15 +201,15 @@ tests = let
194201
, test no yes docL41 doc "documentation #1129"
195202
, test no yes eitL40 kindE "kind of Either #1017"
196203
, test no yes intL40 kindI "kind of Int #1017"
197-
, test no broken tvrL40 kindV "kind of (* -> *) type variable #1017"
198-
, test no broken intL41 litI "literal Int in hover info #1016"
199-
, test no broken chrL36 litC "literal Char in hover info #1016"
200-
, test no broken txtL8 litT "literal Text in hover info #1016"
201-
, test no broken lstL43 litL "literal List in hover info #1016"
204+
, test no yes tvrL40 kindV "kind of (* -> *) type variable #1017"
205+
, test no yes intL41 litI "literal Int in hover info #1016"
206+
, test no yes chrL36 litC "literal Char in hover info #1016"
207+
, test no yes txtL8 litT "literal Text in hover info #1016"
208+
, test no yes lstL43 litL "literal List in hover info #1016"
202209
, test yes yes cmtL68 lackOfdEq "no Core symbols #3280"
203210
, test no yes docL41 constr "type constraint in hover info #1012"
204211
, test no yes outL45 outSig "top-level signature #767"
205-
, test broken broken innL48 innSig "inner signature #767"
212+
, test yes yes innL48 innSig "inner signature #767"
206213
, test no yes holeL60 hleInfo "hole without internal name #831"
207214
, test no yes holeL65 hleInfo2 "hole with variable"
208215
, test no yes cccL17 docLink "Haddock html links"
@@ -215,15 +222,11 @@ tests = let
215222
, test no yes thLocL57 thLoc "TH Splice Hover"
216223
, test yes yes import310 pkgTxt "show package name and its version"
217224
]
218-
where yes, broken :: (TestTree -> Maybe TestTree)
219-
yes = Just -- test should run and pass
220-
broken = Just . (`xfail` "known broken")
225+
where yes :: (TestTree -> Maybe TestTree)
226+
yes = Just -- test should run and pass
221227
no = const Nothing -- don't run this test at all
222228
--skip = const Nothing -- unreliable, don't run
223229

224-
xfail :: TestTree -> String -> TestTree
225-
xfail = flip expectFailBecause
226-
227230
checkFileCompiles :: FilePath -> Session () -> TestTree
228231
checkFileCompiles fp diag =
229232
testWithDummyPlugin ("hover: Does " ++ fp ++ " compile") (mkIdeTestFs [copyDir "hover"]) $ do

ghcide/test/exe/ReferenceTests.hs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import Test.Hls (FromServerMessage' (..),
3636
TNotificationMessage (..))
3737
import Test.Hls.FileSystem (copyDir)
3838
import Test.Tasty
39-
import Test.Tasty.ExpectedFailure
4039
import Test.Tasty.HUnit
4140

4241

@@ -90,16 +89,7 @@ tests = testGroup "references"
9089
, ("Main.hs", 10, 0)
9190
]
9291

93-
, expectFailBecause "references provider does not respect includeDeclaration parameter" $
94-
referenceTest "works when we ask to exclude declarations"
95-
("References.hs", 4, 7)
96-
NoExcludeDeclaration
97-
[ ("References.hs", 6, 0)
98-
, ("References.hs", 6, 14)
99-
, ("References.hs", 9, 7)
100-
, ("References.hs", 10, 11)
101-
]
102-
92+
-- TODO: references provider does not respect includeDeclaration parameter
10393
, referenceTest "INCORRECTLY returns declarations when we ask to exclude them"
10494
("References.hs", 4, 7)
10595
NoExcludeDeclaration

plugins/hls-cabal-fmt-plugin/test/Main.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ tests found = testGroup "cabal-fmt"
3939
cabalFmtGolden found "formats a simple document" "simple_testdata" "formatted_document" $ \doc -> do
4040
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
4141

42-
, expectFailBecause "cabal-fmt can't expand modules if .cabal file is read from stdin. Tracking issue: https://github.com/phadej/cabal-fmt/pull/82" $
43-
cabalFmtGolden found "formats a document with expand:src comment" "commented_testdata" "formatted_document" $ \doc -> do
42+
-- TODO: cabal-fmt can't expand modules if .cabal file is read from stdin. Tracking
43+
-- issue: https://github.com/phadej/cabal-fmt/pull/82
44+
, cabalFmtGolden found "formats a document with expand:src comment" "commented_testdata" "formatted_document" $ \doc -> do
4445
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
4546

4647
, cabalFmtGolden found "formats a document with lib information" "lib_testdata" "formatted_document" $ \doc -> do

plugins/hls-cabal-fmt-plugin/test/testdata/commented_testdata.formatted_document.cabal

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ extra-source-files: CHANGELOG.md
66

77
library
88
-- cabal-fmt: expand src
9-
exposed-modules:
10-
MyLib
11-
MyOtherLib
12-
9+
exposed-modules: MyLib
1310
build-depends: base ^>=4.14.1.0
1411
hs-source-dirs: src
1512
default-language: Haskell2010

plugins/hls-cabal-plugin/test/CabalAdd.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import System.FilePath
1717
import Test.Hls (Session, TestTree, _R, anyMessage,
1818
assertEqual, documentContents,
1919
executeCodeAction,
20-
expectFailBecause,
2120
getAllCodeActions,
2221
getDocumentEdit, liftIO, openDoc,
2322
skipManyTill, testCase, testGroup,
@@ -100,10 +99,9 @@ cabalAddTests =
10099
, ("AAI", "0.1")
101100
, ("AWin32Console", "1.19.1")
102101
]
103-
, expectFailBecause "TODO fix regex for these cases" $
104-
testHiddenPackageSuggestions "Check CabalAdd's parser, with version, unicode comma"
105-
[ "It is a member of the hidden package \82163d-graphics-examples\8217"
106-
, "It is a member of the hidden package \82163d-graphics-examples-1.1.6\8217"
102+
, testHiddenPackageSuggestions "Check CabalAdd's parser, with version, unicode comma"
103+
[ "It is a member of the hidden package \8216\&3d-graphics-examples\8217"
104+
, "It is a member of the hidden package \8216\&3d-graphics-examples-1.1.6\8217"
107105
]
108106
[ ("3d-graphics-examples", T.empty)
109107
, ("3d-graphics-examples", "1.1.6")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ tests =
8989
, goldenWithEval ":type reports an error when given with unknown +x option" "T17" "hs"
9090
, goldenWithEval "Reports an error when given with unknown command" "T18" "hs"
9191
, goldenWithEval "Returns defaulted type for :type +d reflecting the default declaration specified in the >>> prompt" "T19" "hs"
92-
, expectFailBecause "known issue - see a note in P.R. #361" $
93-
goldenWithEval ":type +d reflects the `default' declaration of the module" "T20" "hs"
92+
-- TODO: known issue - see a note in P.R. #361
93+
, goldenWithEval ":type +d reflects the `default' declaration of the module" "T20" "hs"
9494
, testCase ":type handles a multilined result properly" $
9595
evalInFile "T21.hs" "-- >>> :type fun" $ T.unlines [
9696
"-- fun",

plugins/hls-eval-plugin/test/testdata/T20.expected.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ import Data.Word (Word)
44
default (Word)
55

66
-- >>> :type +d 40+ 2
7-
-- 40+ 2 :: Word
7+
-- 40+ 2 :: Integer

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

0 commit comments

Comments
 (0)