@@ -6,9 +6,7 @@ import Control.Applicative.Combinators
66import Control.Lens hiding (List )
77import Control.Monad.IO.Class
88import Data.Aeson (toJSON )
9- import qualified Data.Text as T
109import qualified Data.Default
11- import Ide.Logger
1210import Ide.Plugin.Config
1311import Language.Haskell.LSP.Test hiding (message )
1412import Language.Haskell.LSP.Types
@@ -22,72 +20,53 @@ import Test.Tasty.HUnit
2220
2321tests :: TestTree
2422tests = testGroup " diagnostics providers" [
25- saveTests
26- , triggerTests
27- , errorTests
23+ basicTests
24+ , saveTests
2825 , warningTests
2926 ]
3027
31-
32- triggerTests :: TestTree
33- triggerTests = testGroup " diagnostics triggers" [
34- ignoreTestBecause " Broken" $
35- ignoreTestBecause " Broken" $ testCase " runs diagnostics on save" $
36- runSession hlsCommandExamplePlugin codeActionSupportCaps " test/testdata" $ do
37- logm " starting DiagnosticSpec.runs diagnostic on save"
28+ basicTests :: TestTree
29+ basicTests = testGroup " Diagnostics work" [
30+ testCase " hlint produces diagnostics" $
31+ runSession hlsCommand fullCaps " test/testdata/hlint" $ do
3832 doc <- openDoc " ApplyRefact2.hs" " haskell"
39-
40- diags @ ( reduceDiag: _) <- waitForDiagnostics
41-
33+ diags <- waitForDiagnosticsFromSource doc " hlint "
34+ reduceDiag <- liftIO $ inspectDiagnostic diags [ " Eta reduce " ]
35+ redundantID <- liftIO $ inspectDiagnostic diags [ " Redundant id " ]
4236 liftIO $ do
4337 length diags @?= 2
4438 reduceDiag ^. LSP. range @?= Range (Position 1 0 ) (Position 1 12 )
4539 reduceDiag ^. LSP. severity @?= Just DsInfo
46- reduceDiag ^. LSP. code @?= Just (StringValue " Eta reduce" )
47- reduceDiag ^. LSP. source @?= Just " hlint"
48-
49- diags2a <- waitForDiagnostics
50-
51- liftIO $ length diags2a @?= 2
52-
53- sendNotification TextDocumentDidSave (DidSaveTextDocumentParams doc)
54-
55- diags3@ (d: _) <- waitForDiagnosticsSource " eg2"
40+ redundantID ^. LSP. severity @?= Just DsInfo
5641
42+ , testCase " example plugin produces diagnostics" $
43+ runSession hlsCommandExamplePlugin fullCaps " test/testdata/hlint" $ do
44+ doc <- openDoc " ApplyRefact2.hs" " haskell"
45+ diags <- waitForDiagnosticsFromSource doc " example2"
46+ reduceDiag <- liftIO $ inspectDiagnostic diags [" example2 diagnostic, hello world" ]
5747 liftIO $ do
58- length diags3 @?= 1
59- d ^. LSP. range @?= Range (Position 0 0 ) (Position 1 0 )
60- d ^. LSP. severity @?= Nothing
61- d ^. LSP. code @?= Nothing
62- d ^. LSP. message @?= T. pack " Example plugin diagnostic, triggered byDiagnosticOnSave"
63- ]
64-
65- errorTests :: TestTree
66- errorTests = testGroup " typed hole errors" [
67- ignoreTestBecause " Broken" $ testCase " is deferred" $
68- runSession hlsCommand fullCaps " test/testdata" $ do
69- _ <- openDoc " TypedHoles.hs" " haskell"
70- [diag] <- waitForDiagnosticsSource " bios"
71- liftIO $ diag ^. LSP. severity @?= Just DsWarning
48+ length diags @?= 1
49+ reduceDiag ^. LSP. range @?= Range (Position 0 0 ) (Position 1 0 )
50+ reduceDiag ^. LSP. severity @?= Just DsError
7251 ]
7352
7453warningTests :: TestTree
7554warningTests = testGroup " Warnings are warnings" [
76- ignoreTestBecause " Broken " $ testCase " Overrides -Werror" $
55+ testCase " Overrides -Werror" $
7756 runSession hlsCommand fullCaps " test/testdata/wErrorTest" $ do
78- _ <- openDoc " src/WError.hs" " haskell"
79- [diag] <- waitForDiagnosticsSource " bios "
57+ doc <- openDoc " src/WError.hs" " haskell"
58+ [diag] <- waitForDiagnosticsFrom doc
8059 liftIO $ diag ^. LSP. severity @?= Just DsWarning
8160 ]
8261
8362saveTests :: TestTree
8463saveTests = testGroup " only diagnostics on save" [
85- ignoreTestBecause " Broken " $ testCase " Respects diagnosticsOnChange setting" $
64+ ignoreTestBecause " diagnosticsOnChange parameter is not supported right now " $ testCase " Respects diagnosticsOnChange setting" $
8665 runSession hlsCommandExamplePlugin codeActionSupportCaps " test/testdata" $ do
8766 let config = Data.Default. def { diagnosticsOnChange = False } :: Config
8867 sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (toJSON config))
8968 doc <- openDoc " Hover.hs" " haskell"
90- diags <- waitForDiagnostics
69+ diags <- waitForDiagnosticsFrom doc
9170
9271 liftIO $ do
9372 length diags @?= 0
@@ -97,7 +76,7 @@ saveTests = testGroup "only diagnostics on save" [
9776 skipManyTill loggingNotification noDiagnostics
9877
9978 sendNotification TextDocumentDidSave (DidSaveTextDocumentParams doc)
100- diags2 <- waitForDiagnostics
79+ diags2 <- waitForDiagnosticsFrom doc
10180 liftIO $
10281 length diags2 @?= 1
10382 ]
0 commit comments