Skip to content

Commit 4f7a0fc

Browse files
authored
Migrate RootUriTests (#4261)
* Migrate RootUriTests
1 parent 57f7b3f commit 4f7a0fc

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

ghcide/test/exe/RootUriTests.hs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,33 @@ import Development.IDE.Test (expectNoMoreDiagnostics)
77
import Language.LSP.Test
88
import System.FilePath
99
-- import Test.QuickCheck.Instances ()
10+
import Config
11+
import Data.Default (def)
12+
import Test.Hls (TestConfig (..),
13+
runSessionWithTestConfig)
14+
import Test.Hls.FileSystem (copyDir)
1015
import Test.Tasty
1116
import Test.Tasty.HUnit
12-
import TestUtils
1317

1418

1519
-- | checks if we use InitializeParams.rootUri for loading session
1620
tests :: TestTree
1721
tests = testCase "use rootUri" . runTest "dirA" "dirB" $ \dir -> do
1822
let bPath = dir </> "dirB/Foo.hs"
19-
liftIO $ copyTestDataFiles dir "rootUri"
2023
bSource <- liftIO $ readFileUtf8 bPath
2124
_ <- createDoc "Foo.hs" "haskell" bSource
2225
expectNoMoreDiagnostics 0.5
2326
where
2427
-- similar to run' except we can configure where to start ghcide and session
2528
runTest :: FilePath -> FilePath -> (FilePath -> Session ()) -> IO ()
26-
runTest dir1 dir2 s = withTempDir $ \dir -> runInDir' dir dir1 dir2 [] (s dir)
29+
runTest dir1 dir2 = runSessionWithTestConfig
30+
def
31+
{
32+
testPluginDescriptor = dummyPlugin
33+
, testDirLocation = Right $ mkIdeTestFs [copyDir "rootUri"]
34+
, testServerRoot = Just dir1
35+
, testClientRoot = Just dir2
36+
, testShiftRoot = True
37+
}
38+
39+

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ runSessionWithServer config plugin fp act =
474474
instance Default (TestConfig b) where
475475
def = TestConfig {
476476
testDirLocation = Right $ VirtualFileTree [] "",
477+
testClientRoot = Nothing,
478+
testServerRoot = Nothing,
477479
testShiftRoot = False,
478480
testDisableKick = False,
479481
testDisableDefaultPlugin = False,
@@ -618,6 +620,7 @@ lockForTempDirs = unsafePerformIO newLock
618620
data TestConfig b = TestConfig
619621
{
620622
testDirLocation :: Either FilePath VirtualFileTree
623+
-- ^ Client capabilities
621624
-- ^ The file tree to use for the test, either a directory or a virtual file tree
622625
-- if using a virtual file tree,
623626
-- Creates a temporary directory, and materializes the VirtualFileTree
@@ -638,6 +641,15 @@ data TestConfig b = TestConfig
638641
-- For plugin test logs, look at the documentation of 'mkPluginTestDescriptor'.
639642
, testShiftRoot :: Bool
640643
-- ^ Whether to shift the current directory to the root of the project
644+
, testClientRoot :: Maybe FilePath
645+
-- ^ Specify the root of (the client or LSP context),
646+
-- if Nothing it is the same as the testDirLocation
647+
-- if Just, it is subdirectory of the testDirLocation
648+
, testServerRoot :: Maybe FilePath
649+
-- ^ Specify root of the server, in exe, it can be specify in command line --cwd,
650+
-- or just the server start directory
651+
-- if Nothing it is the same as the testDirLocation
652+
-- if Just, it is subdirectory of the testDirLocation
641653
, testDisableKick :: Bool
642654
-- ^ Whether to disable the kick action
643655
, testDisableDefaultPlugin :: Bool
@@ -671,6 +683,8 @@ runSessionWithTestConfig TestConfig{..} session =
671683
runSessionInVFS testDirLocation $ \root -> shiftRoot root $ do
672684
(inR, inW) <- createPipe
673685
(outR, outW) <- createPipe
686+
let serverRoot = fromMaybe root testServerRoot
687+
let clientRoot = fromMaybe root testClientRoot
674688

675689
(recorder, cb1) <- wrapClientLogger =<< hlsPluginTestRecorder
676690
(recorderIde, cb2) <- wrapClientLogger =<< hlsHelperTestRecorder
@@ -685,11 +699,11 @@ runSessionWithTestConfig TestConfig{..} session =
685699
let plugins = testPluginDescriptor recorder <> lspRecorderPlugin
686700
timeoutOverride <- fmap read <$> lookupEnv "LSP_TIMEOUT"
687701
let sconf' = testConfigSession { lspConfig = hlsConfigToClientConfig testLspConfig, messageTimeout = fromMaybe (messageTimeout defaultConfig) timeoutOverride}
688-
arguments = testingArgs root recorderIde plugins
702+
arguments = testingArgs serverRoot recorderIde plugins
689703
server <- async $
690704
IDEMain.defaultMain (cmapWithPrio LogIDEMain recorderIde)
691705
arguments { argsHandleIn = pure inR , argsHandleOut = pure outW }
692-
result <- runSessionWithHandles inW outR sconf' testConfigCaps root (session root)
706+
result <- runSessionWithHandles inW outR sconf' testConfigCaps clientRoot (session root)
693707
hClose inW
694708
timeout 3 (wait server) >>= \case
695709
Just () -> pure ()

0 commit comments

Comments
 (0)