@@ -6,6 +6,7 @@ module Development.IDE.Test
66 , cursorPosition
77 , requireDiagnostic
88 , expectDiagnostics
9+ , expectNoMoreDiagnostics
910 ) where
1011
1112import Control.Applicative.Combinators
@@ -18,6 +19,7 @@ import Language.Haskell.LSP.Test hiding (message, openDoc')
1819import qualified Language.Haskell.LSP.Test as LspTest
1920import Language.Haskell.LSP.Types
2021import Language.Haskell.LSP.Types.Lens as Lsp
22+import System.Time.Extra
2123import Test.Tasty.HUnit
2224
2325
@@ -41,6 +43,32 @@ requireDiagnostic actuals expected@(severity, cursor, expectedMsg) = do
4143 && standardizeQuotes (T.toLower expectedMsg) `T.isInfixOf`
4244 standardizeQuotes (T.toLower $ d ^. message)
4345
46+-- |wait for @timeout@ seconds and report an assertion failure
47+-- if any diagnostic messages arrive in that period
48+expectNoMoreDiagnostics :: Seconds -> Session ()
49+expectNoMoreDiagnostics timeout = do
50+ -- Give any further diagnostic messages time to arrive.
51+ liftIO $ sleep timeout
52+ -- Send a dummy message to provoke a response from the server.
53+ -- This guarantees that we have at least one message to
54+ -- process, so message won't block or timeout.
55+ void $ sendRequest (CustomClientMethod "non-existent-method") ()
56+ handleMessages
57+ where
58+ handleMessages = handleDiagnostic <|> handleCustomMethodResponse <|> ignoreOthers
59+ handleDiagnostic = do
60+ diagsNot <- LspTest.message :: Session PublishDiagnosticsNotification
61+ let fileUri = diagsNot ^. params . uri
62+ actual = diagsNot ^. params . diagnostics
63+ liftIO $ assertFailure $
64+ "Got unexpected diagnostics for " <> show fileUri <>
65+ " got " <> show actual
66+ handleCustomMethodResponse =
67+ -- the CustomClientMethod triggers a log message about ignoring it
68+ -- handle that and then exit
69+ void (LspTest.message :: Session LogMessageNotification)
70+ ignoreOthers = void anyMessage >> handleMessages
71+
4472expectDiagnostics :: [(FilePath, [(DiagnosticSeverity, Cursor, T.Text)])] -> Session ()
4573expectDiagnostics expected = do
4674 expected' <- Map.fromListWith (<>) <$> traverseOf (traverse . _1) (fmap toNormalizedUri . getDocUri) expected