@@ -88,6 +88,7 @@ main = do
88
88
, benchmarkTests
89
89
, ifaceTests
90
90
, bootTests
91
+ , rootUriTests
91
92
]
92
93
93
94
initializeResponseTests :: TestTree
@@ -3113,9 +3114,22 @@ benchmarkTests =
3113
3114
, Bench. name e /= " edit" -- the edit experiment does not ever fail
3114
3115
]
3115
3116
3117
+ -- | checks if we use InitializeParams.rootUri for loading session
3118
+ rootUriTests :: TestTree
3119
+ rootUriTests = testCase " use rootUri" . withoutStackEnv . runTest " dirA" " dirB" $ \ dir -> do
3120
+ let bPath = dir </> " dirB/Foo.hs"
3121
+ liftIO $ copyTestDataFiles dir " rootUri"
3122
+ bSource <- liftIO $ readFileUtf8 bPath
3123
+ _ <- createDoc " Foo.hs" " haskell" bSource
3124
+ expectNoMoreDiagnostics 0.5
3125
+ where
3126
+ -- similar to run' except we can configure where to start ghcide and session
3127
+ runTest :: FilePath -> FilePath -> (FilePath -> Session () ) -> IO ()
3128
+ runTest dir1 dir2 s = withTempDir $ \ dir -> runInDir' dir dir1 dir2 (s dir)
3129
+
3116
3130
----------------------------------------------------------------------
3117
3131
-- Utils
3118
-
3132
+ ----------------------------------------------------------------------
3119
3133
3120
3134
testSession :: String -> Session () -> TestTree
3121
3135
testSession name = testCase name . run
@@ -3174,20 +3188,27 @@ run' :: (FilePath -> Session a) -> IO a
3174
3188
run' s = withTempDir $ \ dir -> runInDir dir (s dir)
3175
3189
3176
3190
runInDir :: FilePath -> Session a -> IO a
3177
- runInDir dir s = do
3191
+ runInDir dir = runInDir' dir " ." " ."
3192
+
3193
+ -- | Takes a directory as well as relative paths to where we should launch the executable as well as the session root.
3194
+ runInDir' :: FilePath -> FilePath -> FilePath -> Session a -> IO a
3195
+ runInDir' dir startExeIn startSessionIn s = do
3178
3196
ghcideExe <- locateGhcideExecutable
3197
+ let startDir = dir </> startExeIn
3198
+ let projDir = dir </> startSessionIn
3179
3199
3200
+ createDirectoryIfMissing True startDir
3201
+ createDirectoryIfMissing True projDir
3180
3202
-- Temporarily hack around https://github.com/mpickering/hie-bios/pull/56
3181
3203
-- since the package import test creates "Data/List.hs", which otherwise has no physical home
3182
- createDirectoryIfMissing True $ dir ++ " /Data"
3183
-
3204
+ createDirectoryIfMissing True $ projDir ++ " /Data"
3184
3205
3185
- let cmd = unwords [ghcideExe, " --lsp" , " --test" , " --cwd" , dir ]
3206
+ let cmd = unwords [ghcideExe, " --lsp" , " --test" , " --cwd" , startDir ]
3186
3207
-- HIE calls getXgdDirectory which assumes that HOME is set.
3187
3208
-- Only sets HOME if it wasn't already set.
3188
3209
setEnv " HOME" " /homeless-shelter" False
3189
3210
let lspTestCaps = fullCaps { _window = Just $ WindowClientCapabilities $ Just True }
3190
- runSessionWithConfig conf cmd lspTestCaps dir s
3211
+ runSessionWithConfig conf cmd lspTestCaps projDir s
3191
3212
where
3192
3213
conf = defaultConfig
3193
3214
-- If you uncomment this you can see all logging
0 commit comments