Skip to content

Commit 4f33387

Browse files
committed
do ReferenceTests
1 parent 1cdf1fc commit 4f33387

File tree

19 files changed

+230
-229
lines changed

19 files changed

+230
-229
lines changed

ghcide/ghcide.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ test-suite ghcide-tests
388388
PositionMappingTests
389389
PreprocessorTests
390390
Progress
391-
ReferenceTests
392391
RootUriTests
393392
SafeTests
394393
SymlinkTests

ghcide/test/data/hover/Bar.hs

Lines changed: 0 additions & 4 deletions
This file was deleted.

ghcide/test/data/hover/Foo.hs

Lines changed: 0 additions & 6 deletions
This file was deleted.

ghcide/test/data/hover/GotoHover.hs

Lines changed: 0 additions & 70 deletions
This file was deleted.

ghcide/test/data/hover/RecordDotSyntax.hs

Lines changed: 0 additions & 18 deletions
This file was deleted.

ghcide/test/data/hover/hie.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

ghcide/test/exe/Main.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import BootTests
6767
import RootUriTests
6868
import AsyncTests
6969
import ClientSettingsTests
70-
import ReferenceTests
7170
import GarbageCollectionTests
7271
import ExceptionTests
7372

@@ -108,7 +107,6 @@ main = do
108107
, RootUriTests.tests
109108
, AsyncTests.tests
110109
, ClientSettingsTests.tests
111-
, ReferenceTests.tests
112110
, GarbageCollectionTests.tests
113111
, HieDbRetry.tests
114112
, ExceptionTests.tests recorder logger

haskell-language-server.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,7 @@ test-suite hls-core-plugin-tests
16651665
OutlineTests
16661666
CompletionTests
16671667
HighlightTests
1668+
ReferenceTests
16681669

16691670

16701671
build-depends:
@@ -1690,6 +1691,8 @@ test-suite hls-core-plugin-tests
16901691
, extra
16911692
, hls-test-utils
16921693
, regex-tdfa
1694+
, directory
1695+
, tasty-expected-failure
16931696

16941697

16951698
-----------------------------

hls-test-utils/src/Test/Hls.hs

Lines changed: 81 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module Test.Hls
2929
-- * Running HLS for integration tests
3030
runSessionWithServer,
3131
runSessionWithServerAndCaps,
32+
TestRunner,
3233
runSessionWithServerInTmpDir,
3334
runSessionWithServerAndCapsInTmpDir,
3435
runSessionWithServer',
@@ -368,6 +369,86 @@ initialiseTestRecorder envVars = do
368369
-- ------------------------------------------------------------
369370
-- Run an HLS server testing a specific plugin
370371
-- ------------------------------------------------------------
372+
class TestRunner cont res where
373+
runSessionWithServerInTmpDir :: Pretty b => Config -> PluginTestDescriptor b -> VirtualFileTree -> cont -> IO res
374+
runSessionWithServerInTmpDir config plugin tree act = do
375+
recorder <- pluginTestRecorder
376+
runSessionWithServerInTmpDir' (plugin recorder) config def fullCaps tree act
377+
runSessionWithServerAndCapsInTmpDir :: Pretty b => Config -> PluginTestDescriptor b -> ClientCapabilities -> VirtualFileTree -> cont -> IO res
378+
runSessionWithServerAndCapsInTmpDir config plugin caps tree act = do
379+
recorder <- pluginTestRecorder
380+
runSessionWithServerInTmpDir' (plugin recorder) config def caps tree act
381+
382+
-- | Host a server, and run a test session on it.
383+
--
384+
-- Creates a temporary directory, and materializes the VirtualFileTree
385+
-- in the temporary directory.
386+
--
387+
-- To debug test cases and verify the file system is correctly set up,
388+
-- you should set the environment variable 'HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP=1'.
389+
-- Further, we log the temporary directory location on startup. To view
390+
-- the logs, set the environment variable 'HLS_TEST_HARNESS_STDERR=1'.
391+
--
392+
-- Example invocation to debug test cases:
393+
--
394+
-- @
395+
-- HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP=1 HLS_TEST_HARNESS_STDERR=1 cabal test <plugin-name>
396+
-- @
397+
--
398+
-- Don't forget to use 'TASTY_PATTERN' to debug only a subset of tests.
399+
--
400+
-- For plugin test logs, look at the documentation of 'mkPluginTestDescriptor'.
401+
--
402+
-- Note: cwd will be shifted into a temporary directory in @Session a@
403+
runSessionWithServerInTmpDir' ::
404+
-- | Plugins to load on the server.
405+
--
406+
-- For improved logging, make sure these plugins have been initalised with
407+
-- the recorder produced by @pluginTestRecorder@.
408+
IdePlugins IdeState ->
409+
-- | lsp config for the server
410+
Config ->
411+
-- | config for the test session
412+
SessionConfig ->
413+
ClientCapabilities ->
414+
VirtualFileTree ->
415+
cont -> IO res
416+
runSessionWithServerInTmpDir' plugins conf sessConf caps tree act = withLock lockForTempDirs $ do
417+
testRoot <- setupTestEnvironment
418+
(recorder, _) <- initialiseTestRecorder
419+
["LSP_TEST_LOG_STDERR", "HLS_TEST_HARNESS_STDERR", "HLS_TEST_LOG_STDERR"]
420+
421+
-- Do not clean up the temporary directory if this variable is set to anything but '0'.
422+
-- Aids debugging.
423+
cleanupTempDir <- lookupEnv "HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP"
424+
let runTestInDir action = case cleanupTempDir of
425+
Just val | val /= "0" -> do
426+
(tempDir, _) <- newTempDirWithin testRoot
427+
a <- action tempDir
428+
logWith recorder Debug LogNoCleanup
429+
pure a
430+
431+
_ -> do
432+
(tempDir, cleanup) <- newTempDirWithin testRoot
433+
a <- action tempDir `finally` cleanup
434+
logWith recorder Debug LogCleanup
435+
pure a
436+
437+
runTestInDir $ \tmpDir -> do
438+
logWith recorder Info $ LogTestDir tmpDir
439+
fs <- FS.materialiseVFT tmpDir tree
440+
runSessionWithServer' plugins conf sessConf caps tmpDir (contToSessionRes fs act)
441+
contToSessionRes :: FileSystem -> cont -> Session res
442+
443+
444+
instance TestRunner (Session a) a where
445+
contToSessionRes _ act = act
446+
447+
448+
instance TestRunner (FileSystem -> Session a) a where
449+
contToSessionRes fs act = act fs
450+
451+
371452

372453
runSessionWithServer :: Pretty b => Config -> PluginTestDescriptor b -> FilePath -> Session a -> IO a
373454
runSessionWithServer config plugin fp act = do
@@ -379,77 +460,6 @@ runSessionWithServerAndCaps config plugin caps fp act = do
379460
recorder <- pluginTestRecorder
380461
runSessionWithServer' (plugin recorder) config def caps fp act
381462

382-
runSessionWithServerInTmpDir :: Pretty b => Config -> PluginTestDescriptor b -> VirtualFileTree -> Session a -> IO a
383-
runSessionWithServerInTmpDir config plugin tree act = do
384-
recorder <- pluginTestRecorder
385-
runSessionWithServerInTmpDir' (plugin recorder) config def fullCaps tree act
386-
387-
runSessionWithServerAndCapsInTmpDir :: Pretty b => Config -> PluginTestDescriptor b -> ClientCapabilities -> VirtualFileTree -> Session a -> IO a
388-
runSessionWithServerAndCapsInTmpDir config plugin caps tree act = do
389-
recorder <- pluginTestRecorder
390-
runSessionWithServerInTmpDir' (plugin recorder) config def caps tree act
391-
392-
-- | Host a server, and run a test session on it.
393-
--
394-
-- Creates a temporary directory, and materializes the VirtualFileTree
395-
-- in the temporary directory.
396-
--
397-
-- To debug test cases and verify the file system is correctly set up,
398-
-- you should set the environment variable 'HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP=1'.
399-
-- Further, we log the temporary directory location on startup. To view
400-
-- the logs, set the environment variable 'HLS_TEST_HARNESS_STDERR=1'.
401-
--
402-
-- Example invocation to debug test cases:
403-
--
404-
-- @
405-
-- HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP=1 HLS_TEST_HARNESS_STDERR=1 cabal test <plugin-name>
406-
-- @
407-
--
408-
-- Don't forget to use 'TASTY_PATTERN' to debug only a subset of tests.
409-
--
410-
-- For plugin test logs, look at the documentation of 'mkPluginTestDescriptor'.
411-
--
412-
-- Note: cwd will be shifted into a temporary directory in @Session a@
413-
runSessionWithServerInTmpDir' ::
414-
-- | Plugins to load on the server.
415-
--
416-
-- For improved logging, make sure these plugins have been initalised with
417-
-- the recorder produced by @pluginTestRecorder@.
418-
IdePlugins IdeState ->
419-
-- | lsp config for the server
420-
Config ->
421-
-- | config for the test session
422-
SessionConfig ->
423-
ClientCapabilities ->
424-
VirtualFileTree ->
425-
Session a ->
426-
IO a
427-
runSessionWithServerInTmpDir' plugins conf sessConf caps tree act = withLock lockForTempDirs $ do
428-
testRoot <- setupTestEnvironment
429-
(recorder, _) <- initialiseTestRecorder
430-
["LSP_TEST_LOG_STDERR", "HLS_TEST_HARNESS_STDERR", "HLS_TEST_LOG_STDERR"]
431-
432-
-- Do not clean up the temporary directory if this variable is set to anything but '0'.
433-
-- Aids debugging.
434-
cleanupTempDir <- lookupEnv "HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP"
435-
let runTestInDir action = case cleanupTempDir of
436-
Just val
437-
| val /= "0" -> do
438-
(tempDir, _) <- newTempDirWithin testRoot
439-
a <- action tempDir
440-
logWith recorder Debug LogNoCleanup
441-
pure a
442-
443-
_ -> do
444-
(tempDir, cleanup) <- newTempDirWithin testRoot
445-
a <- action tempDir `finally` cleanup
446-
logWith recorder Debug LogCleanup
447-
pure a
448-
449-
runTestInDir $ \tmpDir -> do
450-
logWith recorder Info $ LogTestDir tmpDir
451-
_fs <- FS.materialiseVFT tmpDir tree
452-
runSessionWithServer' plugins conf sessConf caps tmpDir act
453463

454464
-- | Setup the test environment for isolated tests.
455465
--

hls-test-utils/src/Test/Hls/FileSystem.hs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Test.Hls.FileSystem
2020
, directory
2121
, text
2222
, ref
23+
, copyDir
2324
-- * Cradle helpers
2425
, directCradle
2526
, simpleCabalCradle
@@ -66,6 +67,7 @@ data VirtualFileTree =
6667
data FileTree
6768
= File FilePath Content
6869
| Directory FilePath [FileTree]
70+
| CopiedDirectory FilePath
6971
deriving (Show, Eq, Ord)
7072

7173
data Content
@@ -99,12 +101,15 @@ materialise rootDir' fileTree testDataDir' = do
99101
rootDir = FP.normalise rootDir'
100102

101103
persist :: FilePath -> FileTree -> IO ()
102-
persist fp (File name cts) = case cts of
103-
Inline txt -> T.writeFile (fp </> name) txt
104-
Ref path -> copyFile (testDataDir </> FP.normalise path) (fp </> takeFileName name)
105-
persist fp (Directory name nodes) = do
106-
createDirectory (fp </> name)
107-
mapM_ (persist (fp </> name)) nodes
104+
persist root (File name cts) = case cts of
105+
Inline txt -> T.writeFile (root </> name) txt
106+
Ref path -> copyFile (testDataDir </> FP.normalise path) (root </> takeFileName name)
107+
persist root (Directory name nodes) = do
108+
createDirectory (root </> name)
109+
mapM_ (persist (root </> name)) nodes
110+
persist root (CopiedDirectory name) = do
111+
nodes <- copyDir' testDataDir' name
112+
mapM_ (persist root) nodes
108113

109114
traverse_ (persist rootDir) fileTree
110115
pure $ FileSystem rootDir fileTree testDataDir
@@ -154,6 +159,15 @@ file fp cts = File fp cts
154159
copy :: FilePath -> FileTree
155160
copy fp = File fp (Ref fp)
156161

162+
copyDir :: FilePath -> FileTree
163+
copyDir dir = CopiedDirectory dir
164+
165+
-- | Copy a directory into a test project.
166+
copyDir' :: FilePath -> FilePath -> IO [FileTree]
167+
copyDir' root dir = do
168+
files <- listDirectory (root </> dir)
169+
traverse (\f -> pure $ copy (dir </> f)) files
170+
157171
directory :: FilePath -> [FileTree] -> FileTree
158172
directory name nodes = Directory name nodes
159173

0 commit comments

Comments
 (0)