@@ -55,7 +55,8 @@ import Development.IDE.Test (Cursor,
55
55
import Development.IDE.Test.Runfiles
56
56
import qualified Development.IDE.Types.Diagnostics as Diagnostics
57
57
import Development.IDE.Types.Location
58
- import Development.Shake (getDirectoryFilesIO )
58
+ import Development.IDE.Types.Options
59
+ import Development.Shake (getDirectoryFilesIO , shakeThreads )
59
60
import qualified Experiments as Bench
60
61
import Ide.Plugin.Config
61
62
import Language.LSP.Test
@@ -100,7 +101,9 @@ import Ide.Types
100
101
import Data.String (IsString (fromString ))
101
102
import qualified Language.LSP.Types as LSP
102
103
import Data.IORef.Extra (atomicModifyIORef_ )
104
+ import Development.IDE.Core.Rules (mainRule )
103
105
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
106
+ import qualified Development.IDE.Plugin.Test as Test
104
107
import Text.Regex.TDFA ((=~) )
105
108
106
109
waitForProgressBegin :: Session ()
@@ -706,7 +709,8 @@ cancellationTemplate (edit, undoEdit) mbKey = testCase (maybe "-" fst mbKey) $ r
706
709
expectNoMoreDiagnostics 0.5
707
710
where
708
711
-- similar to run except it disables kick
709
- runTestNoKick s = withTempDir $ \ dir -> runInDir' dir " ." " ." [" --test-no-kick" ] s
712
+ runTestNoKick s = withTempDir $ \ dir -> runInDir' argsNoKick dir " ." " ." s
713
+ argsNoKick = def { IDE. argsRules = mainRule }
710
714
711
715
typeCheck doc = do
712
716
Right WaitForIdeRuleResult {.. } <- waitForAction " TypeCheck" doc
@@ -4940,7 +4944,7 @@ rootUriTests = testCase "use rootUri" . runTest "dirA" "dirB" $ \dir -> do
4940
4944
where
4941
4945
-- similar to run' except we can configure where to start ghcide and session
4942
4946
runTest :: FilePath -> FilePath -> (FilePath -> Session () ) -> IO ()
4943
- runTest dir1 dir2 s = withTempDir $ \ dir -> runInDir' dir dir1 dir2 [] (s dir)
4947
+ runTest dir1 dir2 s = withTempDir $ \ dir -> runInDir' def dir dir1 dir2 (s dir)
4944
4948
4945
4949
-- | Test if ghcide asynchronously handles Commands and user Requests
4946
4950
asyncTests :: TestTree
@@ -5224,15 +5228,14 @@ run' :: (FilePath -> Session a) -> IO a
5224
5228
run' s = withTempDir $ \ dir -> runInDir dir (s dir)
5225
5229
5226
5230
runInDir :: FilePath -> Session a -> IO a
5227
- runInDir dir = runInDir' dir " ." " ." []
5231
+ runInDir dir = runInDir' def dir " ." " ."
5228
5232
5229
5233
withLongTimeout :: IO a -> IO a
5230
5234
withLongTimeout = bracket_ (setEnv " LSP_TIMEOUT" " 120" True ) (unsetEnv " LSP_TIMEOUT" )
5231
5235
5232
5236
-- | Takes a directory as well as relative paths to where we should launch the executable as well as the session root.
5233
- runInDir' :: FilePath -> FilePath -> FilePath -> [String ] -> Session a -> IO a
5234
- runInDir' dir startExeIn startSessionIn extraOptions s = do
5235
- ghcideExe <- locateGhcideExecutable
5237
+ runInDir' :: IDE. Arguments -> FilePath -> FilePath -> FilePath -> Session a -> IO a
5238
+ runInDir' args dir startExeIn startSessionIn s = do
5236
5239
let startDir = dir </> startExeIn
5237
5240
let projDir = dir </> startSessionIn
5238
5241
@@ -5241,19 +5244,13 @@ runInDir' dir startExeIn startSessionIn extraOptions s = do
5241
5244
-- Temporarily hack around https://github.com/mpickering/hie-bios/pull/56
5242
5245
-- since the package import test creates "Data/List.hs", which otherwise has no physical home
5243
5246
createDirectoryIfMissing True $ projDir ++ " /Data"
5244
-
5245
- shakeProfiling <- getEnv " SHAKE_PROFILING"
5246
- let cmd = unwords $
5247
- [ghcideExe, " --lsp" , " --test" , " --verbose" , " -j2" , " --cwd" , startDir
5248
- ] ++ [" --shake-profiling=" <> dir | Just dir <- [shakeProfiling]
5249
- ] ++ extraOptions
5250
5247
-- HIE calls getXgdDirectory which assumes that HOME is set.
5251
5248
-- Only sets HOME if it wasn't already set.
5252
5249
setEnv " HOME" " /homeless-shelter" False
5253
- conf <- getConfigFromEnv
5254
- runSessionWithConfig conf cmd lspTestCaps projDir s
5255
5250
5256
- getConfigFromEnv :: IO SessionConfig
5251
+ testIde dir args s
5252
+
5253
+ getConfigFromEnv :: IO SessionConfig
5257
5254
getConfigFromEnv = do
5258
5255
logColor <- fromMaybe True <$> checkEnv " LSP_TEST_LOG_COLOR"
5259
5256
timeoutOverride <- fmap read <$> getEnv " LSP_TIMEOUT"
@@ -5349,37 +5346,50 @@ unitTests = do
5349
5346
| i <- [(1 :: Int ).. 20 ]
5350
5347
] ++ Ghcide. descriptors
5351
5348
5352
- testIde def{IDE. argsHlsPlugins = plugins} $ do
5349
+ testIde " . " def{IDE. argsHlsPlugins = plugins} $ do
5353
5350
_ <- createDoc " haskell" " A.hs" " module A where"
5354
5351
waitForProgressDone
5355
5352
actualOrder <- liftIO $ readIORef orderRef
5356
5353
5357
5354
liftIO $ actualOrder @?= reverse [(1 :: Int ).. 20 ]
5358
5355
]
5359
5356
5360
- testIde :: IDE. Arguments -> Session () -> IO ()
5361
- testIde arguments session = do
5357
+ testIde :: FilePath -> IDE. Arguments -> Session a -> IO a
5358
+ testIde rootDir arguments session = do
5362
5359
config <- getConfigFromEnv
5360
+ shakeProfiling <- getEnv " SHAKE_PROFILING"
5363
5361
(hInRead, hInWrite) <- createPipe
5364
5362
(hOutRead, hOutWrite) <- createPipe
5365
5363
server <- async $ IDE. defaultMain arguments
5366
- { IDE. argsHandleIn = pure hInRead
5367
- , IDE. argsHandleOut = pure hOutWrite
5368
- , IDE. argsIdeOptions = \ config sessionLoader ->
5369
- let ideOptions = (argsIdeOptions def config sessionLoader) {optTesting = IdeTesting True }
5370
- in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2 }}
5371
- }
5364
+ -- TODO install a logger that logs to the LSP stream, otherwise it's hard to debug test failures
5365
+ { IDE. argsHandleIn = pure hInRead
5366
+ , IDE. argsHandleOut = pure hOutWrite
5367
+ , IDE. argsHlsPlugins =
5368
+ pluginDescToIdePlugins $
5369
+ Ghcide. descriptors
5370
+ ++ [Test. blockCommandDescriptor " block-command" ]
5371
+ , IDE. argsGhcidePlugin = Test. plugin
5372
+ , IDE. argsIdeOptions = \ config sessionLoader ->
5373
+ let ideOptions = (IDE. argsIdeOptions def config sessionLoader)
5374
+ {optTesting = IdeTesting True
5375
+ ,optShakeProfiling = shakeProfiling
5376
+ }
5377
+ in ideOptions
5378
+ { optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2 }}
5379
+ }
5372
5380
5373
- runSessionWithHandles hInWrite hOutRead config lspTestCaps " . " session
5381
+ res <- runSessionWithHandles hInWrite hOutRead config lspTestCaps rootDir session
5374
5382
5375
- hClose inw
5383
+ hClose hInWrite
5376
5384
timeout 3 (wait server) >>= \ case
5377
5385
Just () -> pure ()
5378
5386
Nothing -> do
5379
5387
putStrLn " Server does not exit in 3s, canceling the async task..."
5380
5388
(t, _) <- duration $ cancel server
5381
5389
putStrLn $ " Finishing canceling (took " <> showDuration t <> " s)"
5382
5390
5391
+ return res
5392
+
5383
5393
positionMappingTests :: TestTree
5384
5394
positionMappingTests =
5385
5395
testGroup " position mapping"
0 commit comments