Skip to content

Commit 0e52d91

Browse files
authored
[Migrate AsyncTests] part of 4173 Migrate ghcide tests to hls test utils (#4199)
* migrate AsyncTests to hls-test-utils
1 parent a339277 commit 0e52d91

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

ghcide/test/exe/AsyncTests.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ import Language.LSP.Protocol.Types hiding
1515
mkRange)
1616
import Language.LSP.Test
1717
-- import Test.QuickCheck.Instances ()
18+
import Config
1819
import Development.IDE.Plugin.Test (TestRequest (BlockSeconds),
1920
blockCommandId)
2021
import Test.Tasty
2122
import Test.Tasty.HUnit
22-
import TestUtils
2323

2424
-- | Test if ghcide asynchronously handles Commands and user Requests
2525
tests :: TestTree
2626
tests = testGroup "async"
2727
[
28-
testSession "command" $ do
28+
testWithDummyPluginEmpty "command" $ do
2929
-- Execute a command that will block forever
3030
let req = ExecuteCommandParams Nothing blockCommandId Nothing
3131
void $ sendRequest SMethod_WorkspaceExecuteCommand req
@@ -38,7 +38,7 @@ tests = testGroup "async"
3838
codeLenses <- getAndResolveCodeLenses doc
3939
liftIO $ [ _title | CodeLens{_command = Just Command{_title}} <- codeLenses] @=?
4040
[ "foo :: a -> a" ]
41-
, testSession "request" $ do
41+
, testWithDummyPluginEmpty "request" $ do
4242
-- Execute a custom request that will block for 1000 seconds
4343
void $ sendRequest (SMethod_CustomMethod (Proxy @"test")) $ toJSON $ BlockSeconds 1000
4444
-- Load a file and check for code actions. Will only work if the request is run asynchronously

ghcide/test/exe/Config.hs

+9
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,14 @@ testWithDummyPlugin caseName vfs = testCase caseName . runWithDummyPlugin vfs
3131
testWithDummyPlugin' :: String -> FS.VirtualFileTree -> (FileSystem -> Session ()) -> TestTree
3232
testWithDummyPlugin' caseName vfs = testCase caseName . runWithDummyPlugin' vfs
3333

34+
runWithDummyPluginEmpty :: Session a -> IO a
35+
runWithDummyPluginEmpty = runWithDummyPlugin $ mkIdeTestFs []
36+
37+
testWithDummyPluginEmpty :: String -> Session () -> TestTree
38+
testWithDummyPluginEmpty caseName = testWithDummyPlugin caseName $ mkIdeTestFs []
39+
40+
testWithDummyPluginEmpty' :: String -> (FileSystem -> Session ()) -> TestTree
41+
testWithDummyPluginEmpty' caseName = testWithDummyPlugin' caseName $ mkIdeTestFs []
42+
3443
pattern R :: UInt -> UInt -> UInt -> UInt -> Range
3544
pattern R x y x' y' = Range (Position x y) (Position x' y')

ghcide/test/exe/DependentFileTest.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Test.Tasty
2020

2121
tests :: TestTree
2222
tests = testGroup "addDependentFile"
23-
[testGroup "file-changed" [testWithDummyPlugin' "test" (mkIdeTestFs []) test]
23+
[testGroup "file-changed" [testWithDummyPluginEmpty' "test" test]
2424
]
2525
where
2626
test :: FileSystem -> Session ()

ghcide/test/exe/InitializeResponseTests.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import qualified Language.LSP.Protocol.Lens as L
1111
import Language.LSP.Protocol.Message
1212
import Language.LSP.Test
1313

14-
import Config (dummyPlugin, mkIdeTestFs,
15-
runWithDummyPlugin)
14+
import Config
1615
import Control.Lens ((^.))
1716
import Development.IDE.Plugin.Test (blockCommandId)
1817
import Test.Hls
@@ -88,7 +87,7 @@ tests = withResource acquire release tests where
8887
innerCaps (TResponseMessage _ _ (Left _)) = error "Initialization error"
8988

9089
acquire :: IO (TResponseMessage Method_Initialize)
91-
acquire = runWithDummyPlugin (mkIdeTestFs []) initializeResponse
90+
acquire = runWithDummyPluginEmpty initializeResponse
9291

9392
release :: TResponseMessage Method_Initialize -> IO ()
9493
release = mempty

0 commit comments

Comments
 (0)