Skip to content

Commit 7679ed3

Browse files
committed
Remove unused test code with helpful error message
1 parent fe5206c commit 7679ed3

File tree

1 file changed

+8
-49
lines changed

1 file changed

+8
-49
lines changed

ghcide/test/exe/FindImplementationAndHoverTests.hs

+8-49
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ module FindImplementationAndHoverTests (tests) where
77
import Control.Monad
88
import Data.Foldable
99
import Data.Maybe
10-
import qualified Data.Text as T
11-
import qualified Language.LSP.Protocol.Lens as L
10+
import Data.Text (Text)
11+
import qualified Data.Text as T
1212
import Language.LSP.Test
13-
import Text.Regex.TDFA ((=~))
13+
import Text.Regex.TDFA ((=~))
1414

1515
import Config
16-
import Control.Category ((>>>))
17-
import Control.Lens ((^.))
18-
import Data.Text (Text)
19-
import Development.IDE.Test (standardizeQuotes)
16+
import Development.IDE.Test (standardizeQuotes)
2017
import Test.Hls
21-
import Test.Hls.FileSystem (copyDir)
18+
import Test.Hls.FileSystem (copyDir)
2219

2320
tests :: TestTree
2421
tests = let
@@ -39,55 +36,17 @@ tests = let
3936
case hover of
4037
Nothing -> unless (expected == ExpectNoHover) $ liftIO $ assertFailure "no hover found"
4138
Just Hover{_contents = (InL MarkupContent{_value = standardizeQuotes -> msg})
42-
,_range = rangeInHover } ->
39+
,_range = _rangeInHover } ->
4340
case expected of
44-
ExpectRange expectedRange -> checkHoverRange expectedRange rangeInHover msg
45-
ExpectHoverRange expectedRange -> checkHoverRange expectedRange rangeInHover msg
41+
ExpectRange _expectedRange -> liftIO $ assertFailure $ "ExpectRange assertion not implemented, yet."
42+
ExpectHoverRange _expectedRange -> liftIO $ assertFailure $ "ExpectHoverRange assertion not implemented, yet."
4643
ExpectHoverText snippets -> liftIO $ traverse_ (`assertFoundIn` msg) snippets
4744
ExpectHoverExcludeText snippets -> liftIO $ traverse_ (`assertNotFoundIn` msg) snippets
4845
ExpectHoverTextRegex re -> liftIO $ assertBool ("Regex not found in " <> T.unpack msg) (msg =~ re :: Bool)
4946
ExpectNoHover -> liftIO $ assertFailure $ "Expected no hover but got " <> show hover
5047
_ -> pure () -- all other expectations not relevant to hover
5148
_ -> liftIO $ assertFailure $ "test not expecting this kind of hover info" <> show hover
5249

53-
extractLineColFromHoverMsg :: T.Text -> [T.Text]
54-
extractLineColFromHoverMsg =
55-
-- Hover messages contain multiple lines, and we are looking for the definition
56-
-- site
57-
T.lines
58-
-- The line we are looking for looks like: "*Defined at /tmp/GotoHover.hs:22:3*"
59-
-- So filter by the start of the line
60-
>>> mapMaybe (T.stripPrefix "*Defined at")
61-
-- There can be multiple definitions per hover message!
62-
-- See the test "field in record definition" for example.
63-
-- The tests check against the last line that contains the above line.
64-
>>> last
65-
-- [" /tmp/", "22:3*"]
66-
>>> T.splitOn (sourceFileName <> ":")
67-
-- "22:3*"
68-
>>> last
69-
-- ["22:3", ""]
70-
>>> T.splitOn "*"
71-
-- "22:3"
72-
>>> head
73-
-- ["22", "3"]
74-
>>> T.splitOn ":"
75-
76-
checkHoverRange :: Range -> Maybe Range -> T.Text -> Session ()
77-
checkHoverRange expectedRange rangeInHover msg =
78-
let
79-
lineCol = extractLineColFromHoverMsg msg
80-
-- looks like hovers use 1-based numbering while definitions use 0-based
81-
-- turns out that they are stored 1-based in RealSrcLoc by GHC itself.
82-
adjust Position{_line = l, _character = c} =
83-
Position{_line = l + 1, _character = c + 1}
84-
in
85-
case map (read . T.unpack) lineCol of
86-
[l,c] -> liftIO $ adjust (expectedRange ^. L.start) @=? Position l c
87-
_ -> liftIO $ assertFailure $
88-
"expected: " <> show ("[...]" <> sourceFileName <> ":<LINE>:<COL>**[...]", Just expectedRange) <>
89-
"\n but got: " <> show (msg, rangeInHover)
90-
9150
assertFoundIn :: T.Text -> T.Text -> Assertion
9251
assertFoundIn part whole = assertBool
9352
(T.unpack $ "failed to find: `" <> part <> "` in hover message:\n" <> whole)

0 commit comments

Comments
 (0)