Skip to content

Commit a16acea

Browse files
committed
find definition test to core-plugin
1 parent 9faa206 commit a16acea

File tree

14 files changed

+317
-114
lines changed

14 files changed

+317
-114
lines changed

ghcide/ghcide.cabal

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,10 @@ test-suite ghcide-tests
361361
DependentFileTest
362362
DiagnosticTests
363363
ExceptionTests
364-
FindDefinitionAndHoverTests
365364
FuzzySearch
366365
GarbageCollectionTests
367366
HaddockTests
368367
HieDbRetry
369-
HighlightTests
370368
IfaceTests
371369
LogType
372370
NonLspCommandLine

ghcide/test/exe/Main.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ import OpenCloseTest
5050
import CPPTests
5151
import DiagnosticTests
5252
import CodeLensTests
53-
import HighlightTests
54-
import FindDefinitionAndHoverTests
5553
import PluginSimpleTests
5654
import PreprocessorTests
5755
import THTests
@@ -93,8 +91,6 @@ main = do
9391
, CPPTests.tests
9492
, DiagnosticTests.tests
9593
, CodeLensTests.tests
96-
, HighlightTests.tests
97-
, FindDefinitionAndHoverTests.tests
9894
, PluginSimpleTests.tests
9995
, PreprocessorTests.tests
10096
, THTests.tests

haskell-language-server.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,9 +1763,11 @@ test-suite hls-core-plugin-tests
17631763
main-is: CoreTest.hs
17641764
other-modules:
17651765
Util
1766+
FindDefinitionAndHoverTests
17661767
InitializeResponseTests
17671768
OutlineTests
17681769
CompletionTests
1770+
HighlightTests
17691771

17701772

17711773
build-depends:
@@ -1790,6 +1792,7 @@ test-suite hls-core-plugin-tests
17901792
, row-types
17911793
, extra
17921794
, hls-test-utils
1795+
, regex-tdfa
17931796

17941797

17951798
-----------------------------

plugins/hls-core-plugin/test/CoreTest.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
{-# LANGUAGE OverloadedStrings #-}
44

55
import qualified CompletionTests
6+
import qualified FindDefinitionAndHoverTests
7+
import qualified HighlightTests
68
import qualified InitializeResponseTests
79
import qualified OutlineTests
8-
import Test.Hls (defaultTestRunner, testGroup)
10+
import Test.Hls (defaultTestRunner, testGroup)
911

1012

1113
main :: IO ()
1214
main =
1315
defaultTestRunner $
1416
testGroup
1517
"core"
16-
[ InitializeResponseTests.tests
18+
[
19+
InitializeResponseTests.tests
1720
, OutlineTests.tests
1821
, CompletionTests.tests
22+
, HighlightTests.tests
23+
, FindDefinitionAndHoverTests.tests
1924
]

plugins/hls-core-plugin/test/exe/CompletionTests.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ import Language.LSP.Protocol.Types hiding
2828
mkRange)
2929
import Language.LSP.Test
3030
import System.FilePath
31-
import Test.Hls (waitForTypecheck)
31+
import Test.Hls (knownBrokenForGhcVersions,
32+
knownBrokenInEnv,
33+
waitForTypecheck)
3234
import qualified Test.Hls.FileSystem as FS
3335
import Test.Hls.FileSystem (file, text)
36+
import Test.Hls.Util (EnvSpec (..), OS (..),
37+
knownBrokenOnWindows)
3438
import Test.Tasty
3539
import Test.Tasty.HUnit
3640
import Util
@@ -272,7 +276,7 @@ nonLocalCompletionTests =
272276
[]
273277
]
274278
where
275-
brokenForWinGhc = knownBrokenFor (BrokenSpecific Windows [GHC92, GHC94, GHC96, GHC98]) "Windows has strange things in scope for some reason"
279+
brokenForWinGhc = knownBrokenOnWindows "Windows has strange things in scope for some reason"
276280

277281
otherCompletionTests :: [TestTree]
278282
otherCompletionTests = [
@@ -554,7 +558,7 @@ completionDocTests =
554558
]
555559
where
556560
-- https://gitlab.haskell.org/ghc/ghc/-/issues/20903
557-
brokenForMacGhc9 = knownBrokenFor (BrokenSpecific MacOS [GHC92, GHC94, GHC96]) "Extern doc doesn't support MacOS for ghc9"
561+
brokenForMacGhc9 = knownBrokenInEnv [] "Extern doc doesn't support MacOS for ghc9"
558562
test doc pos label mn expected = do
559563
_ <- waitForDiagnostics
560564
compls <- getCompletions doc pos

ghcide/test/exe/FindDefinitionAndHoverTests.hs renamed to plugins/hls-core-plugin/test/exe/FindDefinitionAndHoverTests.hs

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,70 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE ViewPatterns #-}
13

24
module FindDefinitionAndHoverTests (tests) where
35

46
import Control.Monad
5-
import Control.Monad.IO.Class (liftIO)
7+
import Control.Monad.IO.Class (liftIO)
68
import Data.Foldable
79
import Data.Maybe
8-
import qualified Data.Text as T
9-
import Development.IDE.GHC.Compat (GhcVersion (..), ghcVersion)
10+
import qualified Data.Text as T
11+
import Development.IDE.GHC.Compat (GhcVersion (..), ghcVersion)
1012
import Development.IDE.GHC.Util
11-
import Development.IDE.Test (expectDiagnostics,
12-
standardizeQuotes)
13-
import Development.IDE.Types.Location
14-
import qualified Language.LSP.Protocol.Lens as L
15-
import Language.LSP.Protocol.Types hiding
16-
(SemanticTokenAbsolute (..),
17-
SemanticTokenRelative (..),
18-
SemanticTokensEdit (..),
19-
mkRange)
13+
-- import Development.IDE.Test (expectDiagnostics,
14+
-- standardizeQuotes)
15+
import qualified Language.LSP.Protocol.Lens as L
16+
-- import Language.LSP.Protocol.Types hiding
17+
-- (SemanticTokenAbsolute (..),
18+
-- SemanticTokenRelative (..),
19+
-- SemanticTokensEdit (..),
20+
-- mkRange)
21+
22+
import Language.LSP.Protocol.Types (DiagnosticSeverity (..),
23+
Hover (..), MarkupContent (..),
24+
Position (..), Range,
25+
TextDocumentIdentifier, mkRange,
26+
type (|?) (..))
27+
2028
import Language.LSP.Test
2129
import System.FilePath
22-
import System.Info.Extra (isWindows)
30+
import System.Info.Extra (isWindows)
2331

24-
import Control.Lens ((^.))
32+
import Control.Lens ((^.))
2533
import Test.Tasty
2634
import Test.Tasty.HUnit
27-
import TestUtils
28-
import Text.Regex.TDFA ((=~))
35+
-- import TestUtils
36+
import Test.Hls (knownBrokenForGhcVersions,
37+
waitForProgressDone,
38+
waitForTypecheck)
39+
import Test.Hls.FileSystem (copy, directProjectMulti)
40+
import Text.Regex.TDFA ((=~))
41+
import Util
2942

3043
tests :: TestTree
3144
tests = let
32-
3345
tst :: (TextDocumentIdentifier -> Position -> Session a, a -> Session [Expect] -> Session ()) -> Position -> String -> Session [Expect] -> String -> TestTree
34-
tst (get, check) pos sfp targetRange title = testSessionWithExtraFiles "hover" title $ \dir -> do
35-
46+
tst (get, check) pos sfp targetRange title = testSessionWithCorePlugin title (mkFs $ fmap (copy . ("hover" </>)) ["Bar.hs", "Foo.hs", "GotoHover.hs", "hie.yaml", "RecordDotSyntax.hs"]) $ do
3647
-- Dirty the cache to check that definitions work even in the presence of iface files
37-
liftIO $ runInDir dir $ do
38-
let fooPath = dir </> "Foo.hs"
39-
fooSource <- liftIO $ readFileUtf8 fooPath
40-
fooDoc <- createDoc fooPath "haskell" fooSource
41-
_ <- getHover fooDoc $ Position 4 3
42-
closeDoc fooDoc
43-
44-
doc <- openTestDataDoc (dir </> sfp)
48+
-- let fooPath = "Foo.hs"
49+
-- fooSource <- liftIO $ readFileUtf8 fooPath
50+
-- fooDoc <- createDoc fooPath "haskell" fooSource
51+
-- _ <- getHover fooDoc $ Position 4 3
52+
-- closeDoc fooDoc
53+
54+
doc <- openDoc sfp "haskell"
4555
waitForProgressDone
56+
x <- waitForTypecheck doc
57+
58+
4659
found <- get doc pos
4760
check found targetRange
4861

4962

5063

51-
checkHover :: Maybe Hover -> Session [Expect] -> Session ()
64+
checkHover :: (HasCallStack) => Maybe Hover -> Session [Expect] -> Session ()
5265
checkHover hover expectations = traverse_ check =<< expectations where
5366

67+
check :: (HasCallStack) => Expect -> Session ()
5468
check expected =
5569
case hover of
5670
Nothing -> unless (expected == ExpectNoHover) $ liftIO $ assertFailure "no hover found"
@@ -100,11 +114,11 @@ tests = let
100114
mkFindTests tests = testGroup "get"
101115
[ testGroup "definition" $ mapMaybe fst tests
102116
, testGroup "hover" $ mapMaybe snd tests
103-
, checkFileCompiles sourceFilePath $
104-
expectDiagnostics
105-
[ ( "GotoHover.hs", [(DiagnosticSeverity_Error, (62, 7), "Found hole: _")])
106-
, ( "GotoHover.hs", [(DiagnosticSeverity_Error, (65, 8), "Found hole: _")])
107-
]
117+
-- , checkFileCompiles sourceFilePath $
118+
-- expectDiagnostics
119+
-- [ ( "GotoHover.hs", [(DiagnosticSeverity_Error, (62, 7), "Found hole: _")])
120+
-- , ( "GotoHover.hs", [(DiagnosticSeverity_Error, (65, 8), "Found hole: _")])
121+
-- ]
108122
, testGroup "type-definition" typeDefinitionTests
109123
, testGroup "hover-record-dot-syntax" recordDotSyntaxTests ]
110124

@@ -117,8 +131,15 @@ tests = let
117131
, tst (getHover, checkHover) (Position 17 26) (T.unpack "RecordDotSyntax.hs") (pure [ExpectHoverText ["_ :: MyChild"]]) "hover over child"
118132
]
119133

134+
test :: (HasCallStack) => (TestTree -> a) -> (TestTree -> b) -> Position -> [Expect] -> String -> (a, b)
120135
test runDef runHover look expect = testM runDef runHover look (return expect)
121136

137+
testM :: (HasCallStack) => (TestTree -> a)
138+
-> (TestTree -> b)
139+
-> Position
140+
-> Session [Expect]
141+
-> String
142+
-> (a, b)
122143
testM runDef runHover look expect title =
123144
( runDef $ tst def look sourceFilePath expect title
124145
, runHover $ tst hover look sourceFilePath expect title ) where
@@ -228,8 +249,8 @@ tests = let
228249
no = const Nothing -- don't run this test at all
229250
--skip = const Nothing -- unreliable, don't run
230251

231-
checkFileCompiles :: FilePath -> Session () -> TestTree
232-
checkFileCompiles fp diag =
233-
testSessionWithExtraFiles "hover" ("Does " ++ fp ++ " compile") $ \dir -> do
234-
void (openTestDataDoc (dir </> fp))
235-
diag
252+
-- checkFileCompiles :: FilePath -> Session () -> TestTree
253+
-- checkFileCompiles fp diag =
254+
-- testSessionWithCorePluginSingleFile ("hover: Does " ++ fp ++ " compile") $ \dir -> do
255+
-- void (openTestDataDoc fp)
256+
-- diag

ghcide/test/exe/HighlightTests.hs renamed to plugins/hls-core-plugin/test/exe/HighlightTests.hs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE OverloadedStrings #-}
12

23
module HighlightTests (tests) where
34

@@ -11,14 +12,17 @@ import Language.LSP.Protocol.Types hiding
1112
SemanticTokensEdit (..),
1213
mkRange)
1314
import Language.LSP.Test
15+
import Test.Hls (knownBrokenForGhcVersions)
1416
import Test.Tasty
1517
import Test.Tasty.HUnit
16-
import TestUtils
18+
import Util
19+
20+
1721

1822
tests :: TestTree
1923
tests = testGroup "highlight"
20-
[ testSessionWait "value" $ do
21-
doc <- createDoc "A.hs" "haskell" source
24+
[ testSessionWait "value" source $ do
25+
doc <- openDoc "A.hs" "haskell"
2226
_ <- waitForDiagnostics
2327
highlights <- getHighlights doc (Position 3 2)
2428
liftIO $ highlights @?=
@@ -27,16 +31,16 @@ tests = testGroup "highlight"
2731
, DocumentHighlight (R 4 6 4 9) (Just DocumentHighlightKind_Read)
2832
, DocumentHighlight (R 5 22 5 25) (Just DocumentHighlightKind_Read)
2933
]
30-
, testSessionWait "type" $ do
31-
doc <- createDoc "A.hs" "haskell" source
34+
, testSessionWait "type" source $ do
35+
doc <- openDoc "A.hs" "haskell"
3236
_ <- waitForDiagnostics
3337
highlights <- getHighlights doc (Position 2 8)
3438
liftIO $ highlights @?=
3539
[ DocumentHighlight (R 2 7 2 10) (Just DocumentHighlightKind_Read)
3640
, DocumentHighlight (R 3 11 3 14) (Just DocumentHighlightKind_Read)
3741
]
38-
, testSessionWait "local" $ do
39-
doc <- createDoc "A.hs" "haskell" source
42+
, testSessionWait "local" source $ do
43+
doc <- openDoc "A.hs" "haskell"
4044
_ <- waitForDiagnostics
4145
highlights <- getHighlights doc (Position 6 5)
4246
liftIO $ highlights @?=
@@ -45,8 +49,8 @@ tests = testGroup "highlight"
4549
, DocumentHighlight (R 7 12 7 15) (Just DocumentHighlightKind_Read)
4650
]
4751
, knownBrokenForGhcVersions [GHC92, GHC94, GHC96, GHC98] "Ghc9 highlights the constructor and not just this field" $
48-
testSessionWait "record" $ do
49-
doc <- createDoc "A.hs" "haskell" recsource
52+
testSessionWait "record" recsource $ do
53+
doc <- openDoc "A.hs" "haskell"
5054
_ <- waitForDiagnostics
5155
highlights <- getHighlights doc (Position 4 15)
5256
liftIO $ highlights @?=
@@ -77,3 +81,4 @@ tests = testGroup "highlight"
7781
,"data Rec = Rec { field1 :: Int, field2 :: Char }"
7882
,"foo Rec{..} = field2 + field1"
7983
]
84+
testSessionWait name ct = testSessionWithCorePluginSingleFile name "A.hs" ct

plugins/hls-core-plugin/test/exe/OutlineTests.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import Test.Tasty.HUnit
1717
import Util
1818
-- import TestUtils
1919

20-
pattern R :: UInt -> UInt -> UInt -> UInt -> Range
21-
pattern R x y x' y' = Range (Position x y) (Position x' y')
2220

2321
testSymbols :: (HasCallStack) => TestName -> FilePath -> [Text] -> [DocumentSymbol] -> TestTree
2422
testSymbols testName path content expectedSymbols =

0 commit comments

Comments
 (0)