1
1
2
2
module ExceptionTests (tests ) where
3
3
4
- import Control.Exception (ArithException (DivideByZero ),
5
- throwIO )
4
+ import Config
5
+ import Control.Exception (ArithException (DivideByZero ),
6
+ throwIO )
6
7
import Control.Lens
7
- import Control.Monad.Error.Class (MonadError (throwError ))
8
- import Control.Monad.IO.Class (liftIO )
9
- import qualified Data.Aeson as A
10
- import Data.Text as T
11
- import Development.IDE.Core.Shake (IdeState (.. ))
12
- import qualified Development.IDE.LSP.Notifications as Notifications
13
- import qualified Development.IDE.Main as IDE
14
- import Development.IDE.Plugin.HLS (toResponseError )
15
- import Development.IDE.Plugin.Test as Test
16
- import Development.IDE.Types.Options
17
- import GHC.Base (coerce )
18
- import Ide.Logger (Recorder , WithPriority ,
19
- cmapWithPrio )
8
+ import Control.Monad.Error.Class (MonadError (throwError ))
9
+ import Control.Monad.IO.Class (liftIO )
10
+ import qualified Data.Aeson as A
11
+ import Data.Default (Default (.. ))
12
+ import Data.Text as T
13
+ import Development.IDE.Core.Shake (IdeState (.. ))
14
+ import Development.IDE.Plugin.HLS (toResponseError )
15
+ import GHC.Base (coerce )
16
+ import Ide.Logger (Recorder , WithPriority )
20
17
import Ide.Plugin.Error
21
- import Ide.Plugin.HandleRequestTypes (RejectionReason (DisabledGlobally ))
22
- import Ide.PluginUtils (idePluginsToPluginDesc ,
23
- pluginDescToIdePlugins )
18
+ import Ide.Plugin.HandleRequestTypes (RejectionReason (DisabledGlobally ))
19
+ import Ide.PluginUtils (pluginDescToIdePlugins )
24
20
import Ide.Types
25
- import qualified Language.LSP.Protocol.Lens as L
21
+ import qualified Language.LSP.Protocol.Lens as L
26
22
import Language.LSP.Protocol.Message
27
- import Language.LSP.Protocol.Types hiding
28
- (SemanticTokenAbsolute (.. ),
29
- SemanticTokenRelative (.. ),
30
- SemanticTokensEdit (.. ),
31
- mkRange )
23
+ import Language.LSP.Protocol.Types hiding
24
+ (SemanticTokenAbsolute (.. ),
25
+ SemanticTokenRelative (.. ),
26
+ SemanticTokensEdit (.. ),
27
+ mkRange )
32
28
import Language.LSP.Test
33
- import LogType (Log (.. ))
34
- import Test.Hls (waitForProgressDone )
29
+ import LogType (Log (.. ))
30
+ import Test.Hls (runSessionWithServerInTmpDir ,
31
+ waitForProgressDone )
35
32
import Test.Tasty
36
33
import Test.Tasty.HUnit
37
- import TestUtils
38
34
39
- tests :: Recorder ( WithPriority Log ) -> TestTree
40
- tests recorder = do
35
+ tests :: TestTree
36
+ tests = do
41
37
testGroup " Exceptions and PluginError" [
42
38
testGroup " Testing that IO Exceptions are caught in..."
43
39
[ testCase " PluginHandlers" $ do
44
40
let pluginId = " plugin-handler-exception"
45
- plugins = pluginDescToIdePlugins $
41
+ plugins :: Recorder (WithPriority Log ) -> IdePlugins IdeState
42
+ plugins _ = pluginDescToIdePlugins $
46
43
[ (defaultPluginDescriptor pluginId " " )
47
44
{ pluginHandlers = mconcat
48
45
[ mkPluginHandler SMethod_TextDocumentCodeLens $ \ _ _ _-> do
49
46
_ <- liftIO $ throwIO DivideByZero
50
47
pure (InL [] )
51
48
]
52
49
}]
53
- testIde recorder (testingLite recorder plugins ) $ do
50
+ runSessionWithServerInTmpDir def plugins (mkIdeTestFs [] ) $ do
54
51
doc <- createDoc " A.hs" " haskell" " module A where"
55
52
waitForProgressDone
56
53
(view L. result -> lens) <- request SMethod_TextDocumentCodeLens (CodeLensParams Nothing Nothing doc)
@@ -63,15 +60,16 @@ tests recorder = do
63
60
, testCase " Commands" $ do
64
61
let pluginId = " command-exception"
65
62
commandId = CommandId " exception"
66
- plugins = pluginDescToIdePlugins $
63
+ plugins :: Recorder (WithPriority Log ) -> IdePlugins IdeState
64
+ plugins _ = pluginDescToIdePlugins $
67
65
[ (defaultPluginDescriptor pluginId " " )
68
66
{ pluginCommands =
69
67
[ PluginCommand commandId " Causes an exception" $ \ _ _ (_:: Int ) -> do
70
68
_ <- liftIO $ throwIO DivideByZero
71
69
pure (InR Null )
72
70
]
73
71
}]
74
- testIde recorder (testingLite recorder plugins ) $ do
72
+ runSessionWithServerInTmpDir def plugins (mkIdeTestFs [] ) $ do
75
73
_ <- createDoc " A.hs" " haskell" " module A where"
76
74
waitForProgressDone
77
75
let cmd = mkLspCommand (coerce pluginId) commandId " " (Just [A. toJSON (1 :: Int )])
@@ -85,7 +83,8 @@ tests recorder = do
85
83
86
84
, testCase " Notification Handlers" $ do
87
85
let pluginId = " notification-exception"
88
- plugins = pluginDescToIdePlugins $
86
+ plugins :: Recorder (WithPriority Log ) -> IdePlugins IdeState
87
+ plugins _ = pluginDescToIdePlugins $
89
88
[ (defaultPluginDescriptor pluginId " " )
90
89
{ pluginNotificationHandlers = mconcat
91
90
[ mkPluginNotificationHandler SMethod_TextDocumentDidOpen $ \ _ _ _ _ ->
@@ -96,7 +95,7 @@ tests recorder = do
96
95
pure (InL [] )
97
96
]
98
97
}]
99
- testIde recorder (testingLite recorder plugins ) $ do
98
+ runSessionWithServerInTmpDir def plugins (mkIdeTestFs [] ) $ do
100
99
doc <- createDoc " A.hs" " haskell" " module A where"
101
100
waitForProgressDone
102
101
(view L. result -> lens) <- request SMethod_TextDocumentCodeLens (CodeLensParams Nothing Nothing doc)
@@ -108,37 +107,18 @@ tests recorder = do
108
107
_ -> liftIO $ assertFailure $ " We should have had an empty list" <> show lens]
109
108
110
109
, testGroup " Testing PluginError order..."
111
- [ pluginOrderTestCase recorder " InternalError over InvalidParams" (PluginInternalError " error test" ) (PluginInvalidParams " error test" )
112
- , pluginOrderTestCase recorder " InvalidParams over InvalidUserState" (PluginInvalidParams " error test" ) (PluginInvalidUserState " error test" )
113
- , pluginOrderTestCase recorder " InvalidUserState over RequestRefused" (PluginInvalidUserState " error test" ) (PluginRequestRefused DisabledGlobally )
110
+ [ pluginOrderTestCase " InternalError over InvalidParams" (PluginInternalError " error test" ) (PluginInvalidParams " error test" )
111
+ , pluginOrderTestCase " InvalidParams over InvalidUserState" (PluginInvalidParams " error test" ) (PluginInvalidUserState " error test" )
112
+ , pluginOrderTestCase " InvalidUserState over RequestRefused" (PluginInvalidUserState " error test" ) (PluginRequestRefused DisabledGlobally )
114
113
]
115
114
]
116
115
117
- testingLite :: Recorder (WithPriority Log ) -> IdePlugins IdeState -> IDE. Arguments
118
- testingLite recorder plugins =
119
- let
120
- arguments@ IDE. Arguments { argsIdeOptions } =
121
- IDE. defaultArguments (cmapWithPrio LogIDEMain recorder) plugins
122
- hlsPlugins = pluginDescToIdePlugins $
123
- idePluginsToPluginDesc plugins
124
- ++ [Notifications. descriptor (cmapWithPrio LogNotifications recorder) " ghcide-core" ]
125
- ++ [Test. blockCommandDescriptor " block-command" , Test. plugin]
126
- ideOptions config sessionLoader =
127
- let
128
- defOptions = argsIdeOptions config sessionLoader
129
- in
130
- defOptions{ optTesting = IdeTesting True }
131
- in
132
- arguments
133
- { IDE. argsHlsPlugins = hlsPlugins
134
- , IDE. argsIdeOptions = ideOptions
135
- }
136
-
137
- pluginOrderTestCase :: Recorder (WithPriority Log ) -> TestName -> PluginError -> PluginError -> TestTree
138
- pluginOrderTestCase recorder msg err1 err2 =
116
+ pluginOrderTestCase :: TestName -> PluginError -> PluginError -> TestTree
117
+ pluginOrderTestCase msg err1 err2 =
139
118
testCase msg $ do
140
119
let pluginId = " error-order-test"
141
- plugins = pluginDescToIdePlugins $
120
+ plugins :: Recorder (WithPriority Log ) -> IdePlugins IdeState
121
+ plugins _ = pluginDescToIdePlugins $
142
122
[ (defaultPluginDescriptor pluginId " " )
143
123
{ pluginHandlers = mconcat
144
124
[ mkPluginHandler SMethod_TextDocumentCodeLens $ \ _ _ _-> do
@@ -147,7 +127,7 @@ pluginOrderTestCase recorder msg err1 err2 =
147
127
throwError err2
148
128
]
149
129
}]
150
- testIde recorder (testingLite recorder plugins ) $ do
130
+ runSessionWithServerInTmpDir def plugins (mkIdeTestFs [] ) $ do
151
131
doc <- createDoc " A.hs" " haskell" " module A where"
152
132
waitForProgressDone
153
133
(view L. result -> lens) <- request SMethod_TextDocumentCodeLens (CodeLensParams Nothing Nothing doc)
0 commit comments