Skip to content

Commit e6595bb

Browse files
committed
migrate boot test
1 parent 61fd5c4 commit e6595bb

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

ghcide/test/exe/BootTests.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module BootTests (tests) where
22

3-
import Config (checkDefs, mkR)
3+
import Config (checkDefs, mkR, runInDir,
4+
runWithExtraFiles)
45
import Control.Applicative.Combinators
56
import Control.Monad
67
import Control.Monad.IO.Class (liftIO)
@@ -15,16 +16,15 @@ import Language.LSP.Protocol.Types hiding
1516
SemanticTokensEdit (..),
1617
mkRange)
1718
import Language.LSP.Test
18-
import System.FilePath
19+
import Test.Hls.FileSystem (toAbsFp)
1920
import Test.Tasty
2021
import Test.Tasty.HUnit
21-
import TestUtils
2222

2323

2424
tests :: TestTree
2525
tests = testGroup "boot"
2626
[ testCase "boot-def-test" $ runWithExtraFiles "boot" $ \dir -> do
27-
let cPath = dir </> "C.hs"
27+
let cPath = dir `toAbsFp` "C.hs"
2828
cSource <- liftIO $ readFileUtf8 cPath
2929
-- Dirty the cache
3030
liftIO $ runInDir dir $ do
@@ -51,6 +51,6 @@ tests = testGroup "boot"
5151
let floc = mkR 9 0 9 1
5252
checkDefs locs (pure [floc])
5353
, testCase "graph with boot modules" $ runWithExtraFiles "boot2" $ \dir -> do
54-
_ <- openDoc (dir </> "A.hs") "haskell"
54+
_ <- openDoc (dir `toAbsFp` "A.hs") "haskell"
5555
expectNoMoreDiagnostics 2
5656
]

ghcide/test/exe/Config.hs

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Config(
1313
, testWithDummyPluginEmpty'
1414
, testWithDummyPluginAndCap'
1515
, runWithExtraFiles
16+
, runInDir
1617
, testWithExtraFiles
1718

1819
-- * utilities for testing definition and hover
@@ -36,7 +37,7 @@ import Language.LSP.Protocol.Types (Null (..))
3637
import System.FilePath ((</>))
3738
import Test.Hls
3839
import qualified Test.Hls.FileSystem as FS
39-
import Test.Hls.FileSystem (FileSystem)
40+
import Test.Hls.FileSystem (FileSystem, fsRoot)
4041

4142
testDataDir :: FilePath
4243
testDataDir = "ghcide" </> "test" </> "data"
@@ -80,6 +81,9 @@ runWithExtraFiles dirName action = do
8081
testWithExtraFiles :: String -> String -> (FileSystem -> Session ()) -> TestTree
8182
testWithExtraFiles testName dirName action = testCase testName $ runWithExtraFiles dirName action
8283

84+
runInDir :: FileSystem -> Session a -> IO a
85+
runInDir fs = runSessionWithServerNoRootLock False dummyPlugin def def def (fsRoot fs)
86+
8387
pattern R :: UInt -> UInt -> UInt -> UInt -> Range
8488
pattern R x y x' y' = Range (Position x y) (Position x' y')
8589

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

+22-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module Test.Hls
3131
runSessionWithServerAndCaps,
3232
runSessionWithServerInTmpDir,
3333
runSessionWithServerAndCapsInTmpDir,
34+
runSessionWithServerNoRootLock,
3435
runSessionWithServer',
3536
runSessionWithServerInTmpDir',
3637
-- continuation version that take a FileSystem
@@ -618,7 +619,7 @@ lockForTempDirs = unsafePerformIO newLock
618619

619620
-- | Host a server, and run a test session on it
620621
-- Note: cwd will be shifted into @root@ in @Session a@
621-
runSessionWithServer' ::
622+
runSessionWithServerNoRootLock ::
622623
(Pretty b) =>
623624
-- | whether we disable the kick action or not
624625
Bool ->
@@ -632,7 +633,7 @@ runSessionWithServer' ::
632633
FilePath ->
633634
Session a ->
634635
IO a
635-
runSessionWithServer' disableKick pluginsDp conf sconf caps root s = withLock lock $ keepCurrentDirectory $ do
636+
runSessionWithServerNoRootLock disableKick pluginsDp conf sconf caps root s = do
636637
(inR, inW) <- createPipe
637638
(outR, outW) <- createPipe
638639

@@ -676,6 +677,25 @@ runSessionWithServer' disableKick pluginsDp conf sconf caps root s = withLock l
676677
putStrLn $ "Finishing canceling (took " <> showDuration t <> "s)"
677678
pure x
678679

680+
-- | Host a server, and run a test session on it
681+
-- Note: cwd will be shifted into @root@ in @Session a@
682+
runSessionWithServer' ::
683+
(Pretty b) =>
684+
-- | whether we disable the kick action or not
685+
Bool ->
686+
-- | Plugin to load on the server.
687+
PluginTestDescriptor b ->
688+
-- | lsp config for the server
689+
Config ->
690+
-- | config for the test session
691+
SessionConfig ->
692+
ClientCapabilities ->
693+
FilePath ->
694+
Session a ->
695+
IO a
696+
runSessionWithServer' disableKick pluginsDp conf sconf caps root s =
697+
withLock lock $ keepCurrentDirectory $ runSessionWithServerNoRootLock disableKick pluginsDp conf sconf caps root s
698+
679699
-- | Wait for the next progress begin step
680700
waitForProgressBegin :: Session ()
681701
waitForProgressBegin = skipManyTill anyMessage $ satisfyMaybe $ \case

0 commit comments

Comments
 (0)