Skip to content

Commit 4d2f3f0

Browse files
committed
Add field for expected error codes in ghcide tests
1 parent 465ee2b commit 4d2f3f0

14 files changed

+88
-81
lines changed

ghcide/test/exe/CPPTests.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ tests =
4242
," failed"
4343
,"#endif"
4444
]
45-
expectDiagnostics [("A.hs", [(DiagnosticSeverity_Error, (3, 2), "Variable not in scope: worked")])]
45+
expectDiagnostics [("A.hs", [(DiagnosticSeverity_Error, (3, 2), "Variable not in scope: worked", Nothing)])]
4646
]
4747
where
4848
expectError :: T.Text -> Cursor -> Session ()
4949
expectError content cursor = do
5050
_ <- createDoc "Testing.hs" "haskell" content
5151
expectDiagnostics
5252
[ ( "Testing.hs",
53-
[(DiagnosticSeverity_Error, cursor, "error: unterminated")]
53+
[(DiagnosticSeverity_Error, cursor, "error: unterminated", Nothing)]
5454
)
5555
]
5656
expectNoMoreDiagnostics 0.5

ghcide/test/exe/CradleTests.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ simpleSubDirectoryTest =
112112
mainSource <- liftIO $ readFileUtf8 mainPath
113113
_mdoc <- createDoc mainPath "haskell" mainSource
114114
expectDiagnosticsWithTags
115-
[("a/src/Main.hs", [(DiagnosticSeverity_Warning,(2,0), "Top-level binding", Nothing)]) -- So that we know P has been loaded
115+
[("a/src/Main.hs", [(DiagnosticSeverity_Warning,(2,0), "Top-level binding", Nothing, Nothing)]) -- So that we know P has been loaded
116116
]
117117
expectNoMoreDiagnostics 0.5
118118

@@ -210,7 +210,7 @@ sessionDepsArePickedUp = testWithDummyPluginEmpty'
210210
"cradle: {direct: {arguments: []}}"
211211
-- Open without OverloadedStrings and expect an error.
212212
doc <- createDoc "Foo.hs" "haskell" fooContent
213-
expectDiagnostics [("Foo.hs", [(DiagnosticSeverity_Error, (3, 6), "Couldn't match type")])]
213+
expectDiagnostics [("Foo.hs", [(DiagnosticSeverity_Error, (3, 6), "Couldn't match type", Nothing)])]
214214

215215
-- Update hie.yaml to enable OverloadedStrings.
216216
liftIO $

ghcide/test/exe/DependentFileTest.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ tests = testGroup "addDependentFile"
4646
_fooDoc <- createDoc "Foo.hs" "haskell" fooContent
4747
doc <- createDoc "Baz.hs" "haskell" bazContent
4848
expectDiagnostics
49-
[("Foo.hs", [(DiagnosticSeverity_Error, (4,11), "Couldn't match type")])]
49+
[("Foo.hs", [(DiagnosticSeverity_Error, (4,11), "Couldn't match type", Nothing)])]
5050
-- Now modify the dependent file
5151
liftIO $ writeFile depFilePath "B"
5252
sendNotification SMethod_WorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams

ghcide/test/exe/DiagnosticTests.hs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ tests = testGroup "diagnostics"
4848
[ testWithDummyPluginEmpty "fix syntax error" $ do
4949
let content = T.unlines [ "module Testing wher" ]
5050
doc <- createDoc "Testing.hs" "haskell" content
51-
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "parse error")])]
51+
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "parse error", Nothing)])]
5252
let change = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
5353
{ _range = Range (Position 0 15) (Position 0 19)
5454
, _rangeLength = Nothing
@@ -67,18 +67,18 @@ tests = testGroup "diagnostics"
6767
, _text = "wher"
6868
}
6969
changeDoc doc [change]
70-
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "parse error")])]
70+
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "parse error", Nothing)])]
7171
, testWithDummyPluginEmpty "update syntax error" $ do
7272
let content = T.unlines [ "module Testing(missing) where" ]
7373
doc <- createDoc "Testing.hs" "haskell" content
74-
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "Not in scope: 'missing'")])]
74+
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "Not in scope: 'missing'", Nothing)])]
7575
let change = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
7676
{ _range = Range (Position 0 15) (Position 0 16)
7777
, _rangeLength = Nothing
7878
, _text = "l"
7979
}
8080
changeDoc doc [change]
81-
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "Not in scope: 'lissing'")])]
81+
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "Not in scope: 'lissing'", Nothing)])]
8282
, testWithDummyPluginEmpty "variable not in scope" $ do
8383
let content = T.unlines
8484
[ "module Testing where"
@@ -90,8 +90,8 @@ tests = testGroup "diagnostics"
9090
_ <- createDoc "Testing.hs" "haskell" content
9191
expectDiagnostics
9292
[ ( "Testing.hs"
93-
, [ (DiagnosticSeverity_Error, (2, 15), "Variable not in scope: ab")
94-
, (DiagnosticSeverity_Error, (4, 11), "Variable not in scope: cd")
93+
, [ (DiagnosticSeverity_Error, (2, 15), "Variable not in scope: ab", Nothing)
94+
, (DiagnosticSeverity_Error, (4, 11), "Variable not in scope: cd", Nothing)
9595
]
9696
)
9797
]
@@ -104,7 +104,7 @@ tests = testGroup "diagnostics"
104104
_ <- createDoc "Testing.hs" "haskell" content
105105
expectDiagnostics
106106
[ ( "Testing.hs"
107-
, [(DiagnosticSeverity_Error, (2, 14), "Couldn't match type '[Char]' with 'Int'")]
107+
, [(DiagnosticSeverity_Error, (2, 14), "Couldn't match type '[Char]' with 'Int'", Nothing)]
108108
)
109109
]
110110
, testWithDummyPluginEmpty "typed hole" $ do
@@ -116,7 +116,7 @@ tests = testGroup "diagnostics"
116116
_ <- createDoc "Testing.hs" "haskell" content
117117
expectDiagnostics
118118
[ ( "Testing.hs"
119-
, [(DiagnosticSeverity_Error, (2, 8), "Found hole: _ :: Int -> String")]
119+
, [(DiagnosticSeverity_Error, (2, 8), "Found hole: _ :: Int -> String", Nothing)]
120120
)
121121
]
122122

@@ -132,8 +132,8 @@ tests = testGroup "diagnostics"
132132
, "b = True"]
133133
bMessage = "Couldn't match expected type 'Float' with actual type 'Bool'"
134134
expectedDs aMessage =
135-
[ ("A.hs", [(DiagnosticSeverity_Error, (2,4), aMessage)])
136-
, ("B.hs", [(DiagnosticSeverity_Error, (3,4), bMessage)])]
135+
[ ("A.hs", [(DiagnosticSeverity_Error, (2,4), aMessage, Nothing)])
136+
, ("B.hs", [(DiagnosticSeverity_Error, (3,4), bMessage, Nothing)])]
137137
deferralTest title binding msg = testWithDummyPluginEmpty title $ do
138138
_ <- createDoc "A.hs" "haskell" $ sourceA binding
139139
_ <- createDoc "B.hs" "haskell" sourceB
@@ -158,14 +158,14 @@ tests = testGroup "diagnostics"
158158
, _text = ""
159159
}
160160
changeDoc docA [change]
161-
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Error, (1, 0), "Could not find module")])]
161+
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Error, (1, 0), "Could not find module", Nothing)])]
162162
, testWithDummyPluginEmpty "add missing module" $ do
163163
let contentB = T.unlines
164164
[ "module ModuleB where"
165165
, "import ModuleA ()"
166166
]
167167
_ <- createDoc "ModuleB.hs" "haskell" contentB
168-
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Error, (1, 7), "Could not find module")])]
168+
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Error, (1, 7), "Could not find module", Nothing)])]
169169
let contentA = T.unlines [ "module ModuleA where" ]
170170
_ <- createDoc "ModuleA.hs" "haskell" contentA
171171
expectDiagnostics [("ModuleB.hs", [])]
@@ -185,7 +185,7 @@ tests = testGroup "diagnostics"
185185
, "import ModuleA ()"
186186
]
187187
_ <- createDoc (tmpDir </> "ModuleB.hs") "haskell" contentB
188-
expectDiagnostics [(tmpDir </> "ModuleB.hs", [(DiagnosticSeverity_Error, (1, 7), "Could not find module")])]
188+
expectDiagnostics [(tmpDir </> "ModuleB.hs", [(DiagnosticSeverity_Error, (1, 7), "Could not find module", Nothing)])]
189189
let contentA = T.unlines [ "module ModuleA where" ]
190190
_ <- createDoc (tmpDir </> "ModuleA.hs") "haskell" contentA
191191
expectDiagnostics [(tmpDir </> "ModuleB.hs", [])]
@@ -202,10 +202,10 @@ tests = testGroup "diagnostics"
202202
_ <- createDoc "ModuleB.hs" "haskell" contentB
203203
expectDiagnostics
204204
[ ( "ModuleA.hs"
205-
, [(DiagnosticSeverity_Error, (1, 7), "Cyclic module dependency between ModuleA, ModuleB")]
205+
, [(DiagnosticSeverity_Error, (1, 7), "Cyclic module dependency between ModuleA, ModuleB", Nothing)]
206206
)
207207
, ( "ModuleB.hs"
208-
, [(DiagnosticSeverity_Error, (1, 7), "Cyclic module dependency between ModuleA, ModuleB")]
208+
, [(DiagnosticSeverity_Error, (1, 7), "Cyclic module dependency between ModuleA, ModuleB", Nothing)]
209209
)
210210
]
211211
, let contentA = T.unlines [ "module ModuleA where" , "import ModuleB" ]
@@ -222,8 +222,8 @@ tests = testGroup "diagnostics"
222222
]) $ do
223223
_ <- createDoc "ModuleD.hs" "haskell" contentD
224224
expectDiagnostics
225-
[ ( "ModuleB.hs" , [(DiagnosticSeverity_Error, (1, 7), "Cyclic module dependency between ModuleA, ModuleB")])
226-
, ( "ModuleA.hs" , [(DiagnosticSeverity_Error, (1, 7), "Cyclic module dependency between ModuleA, ModuleB")])
225+
[ ( "ModuleB.hs" , [(DiagnosticSeverity_Error, (1, 7), "Cyclic module dependency between ModuleA, ModuleB", Nothing)])
226+
, ( "ModuleA.hs" , [(DiagnosticSeverity_Error, (1, 7), "Cyclic module dependency between ModuleA, ModuleB", Nothing)])
227227
]
228228
, testWithDummyPluginEmpty "cyclic module dependency with hs-boot" $ do
229229
let contentA = T.unlines
@@ -243,7 +243,7 @@ tests = testGroup "diagnostics"
243243
_ <- createDoc "ModuleA.hs" "haskell" contentA
244244
_ <- createDoc "ModuleB.hs" "haskell" contentB
245245
_ <- createDoc "ModuleB.hs-boot" "haskell" contentBboot
246-
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Warning, (3,0), "Top-level binding")])]
246+
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Warning, (3,0), "Top-level binding", Nothing)])]
247247
, testWithDummyPlugin "bidirectional module dependency with hs-boot"
248248
(mkIdeTestFs [directCradle ["ModuleA", "ModuleB"]])
249249
$ do
@@ -268,7 +268,7 @@ tests = testGroup "diagnostics"
268268
_ <- createDoc "ModuleA.hs-boot" "haskell" contentAboot
269269
_ <- createDoc "ModuleB.hs" "haskell" contentB
270270
_ <- createDoc "ModuleB.hs-boot" "haskell" contentBboot
271-
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Warning, (3,0), "Top-level binding")])]
271+
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Warning, (3,0), "Top-level binding", Nothing)])]
272272
, testWithDummyPluginEmpty "correct reference used with hs-boot" $ do
273273
let contentB = T.unlines
274274
[ "module ModuleB where"
@@ -294,7 +294,7 @@ tests = testGroup "diagnostics"
294294
_ <- createDoc "ModuleA.hs" "haskell" contentA
295295
_ <- createDoc "ModuleA.hs-boot" "haskell" contentAboot
296296
_ <- createDoc "ModuleC.hs" "haskell" contentC
297-
expectDiagnostics [("ModuleC.hs", [(DiagnosticSeverity_Warning, (3,0), "Top-level binding")])]
297+
expectDiagnostics [("ModuleC.hs", [(DiagnosticSeverity_Warning, (3,0), "Top-level binding", Nothing)])]
298298
, testWithDummyPluginEmpty "redundant import" $ do
299299
let contentA = T.unlines ["module ModuleA where"]
300300
let contentB = T.unlines
@@ -306,7 +306,7 @@ tests = testGroup "diagnostics"
306306
_ <- createDoc "ModuleB.hs" "haskell" contentB
307307
expectDiagnosticsWithTags
308308
[ ( "ModuleB.hs"
309-
, [(DiagnosticSeverity_Warning, (2, 0), "The import of 'ModuleA' is redundant", Just DiagnosticTag_Unnecessary)]
309+
, [(DiagnosticSeverity_Warning, (2, 0), "The import of 'ModuleA' is redundant", Nothing, Just DiagnosticTag_Unnecessary)]
310310
)
311311
]
312312
, testWithDummyPluginEmpty "redundant import even without warning" $ do
@@ -320,7 +320,7 @@ tests = testGroup "diagnostics"
320320
]
321321
_ <- createDoc "ModuleA.hs" "haskell" contentA
322322
_ <- createDoc "ModuleB.hs" "haskell" contentB
323-
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Warning, (3,0), "Top-level binding")])]
323+
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Warning, (3,0), "Top-level binding", Nothing)])]
324324
, testWithDummyPluginEmpty "package imports" $ do
325325
let thisDataListContent = T.unlines
326326
[ "module Data.List where"
@@ -348,14 +348,14 @@ tests = testGroup "diagnostics"
348348
else if ghcVersion >= GHC94 then
349349
"Variable not in scope: map" -- See https://gitlab.haskell.org/ghc/ghc/-/issues/22130
350350
else
351-
"Not in scope: \8216ThisList.map\8217")
351+
"Not in scope: \8216ThisList.map\8217", Nothing)
352352
,(DiagnosticSeverity_Error, (7, 9),
353353
if ghcVersion >= GHC96 then
354354
"Variable not in scope: BaseList.x"
355355
else if ghcVersion >= GHC94 then
356356
"Variable not in scope: x" -- See https://gitlab.haskell.org/ghc/ghc/-/issues/22130
357357
else
358-
"Not in scope: \8216BaseList.x\8217")
358+
"Not in scope: \8216BaseList.x\8217", Nothing)
359359
]
360360
)
361361
]
@@ -373,7 +373,7 @@ tests = testGroup "diagnostics"
373373
-- where appropriate. The warning should use an unqualified name 'Ord', not
374374
-- something like 'GHC.Classes.Ord'. The choice of redundant-constraints to
375375
-- test this is fairly arbitrary.
376-
, [(DiagnosticSeverity_Warning, (2, if ghcVersion >= GHC94 then 7 else 0), "Redundant constraint: Ord a")
376+
, [(DiagnosticSeverity_Warning, (2, if ghcVersion >= GHC94 then 7 else 0), "Redundant constraint: Ord a", Nothing)
377377
]
378378
)
379379
]
@@ -439,7 +439,7 @@ tests = testGroup "diagnostics"
439439
_ <- createDoc "Foo.hs" "haskell" fooContent
440440
expectDiagnostics
441441
[ ( "Foo.hs"
442-
, [(DiagnosticSeverity_Warning, (1, 0), "Top-level binding with no type signature:")
442+
, [(DiagnosticSeverity_Warning, (1, 0), "Top-level binding with no type signature:", Nothing)
443443
]
444444
)
445445
]
@@ -453,7 +453,7 @@ tests = testGroup "diagnostics"
453453
_ <- createDoc "Foo.hs" "haskell" fooContent
454454
expectDiagnostics
455455
[ ( "Foo.hs"
456-
, [(DiagnosticSeverity_Warning, (3, 0), "Defined but not used:")
456+
, [(DiagnosticSeverity_Warning, (3, 0), "Defined but not used:", Nothing)
457457
]
458458
)
459459
]
@@ -469,13 +469,13 @@ tests = testGroup "diagnostics"
469469
bdoc <- createDoc bPath "haskell" bSource
470470
_pdoc <- createDoc pPath "haskell" pSource
471471
expectDiagnostics
472-
[("P.hs", [(DiagnosticSeverity_Warning,(4,0), "Top-level binding")])] -- So that we know P has been loaded
472+
[("P.hs", [(DiagnosticSeverity_Warning,(4,0), "Top-level binding", Nothing)])] -- So that we know P has been loaded
473473

474474
-- Change y from Int to B which introduces a type error in A (imported from P)
475475
changeDoc bdoc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $
476476
T.unlines ["module B where", "y :: Bool", "y = undefined"]]
477477
expectDiagnostics
478-
[("A.hs", [(DiagnosticSeverity_Error, (5, 4), "Couldn't match expected type 'Int' with actual type 'Bool'")])
478+
[("A.hs", [(DiagnosticSeverity_Error, (5, 4), "Couldn't match expected type 'Int' with actual type 'Bool'", Nothing)])
479479
]
480480

481481
-- Open A and edit to fix the type error
@@ -485,8 +485,8 @@ tests = testGroup "diagnostics"
485485

486486
expectDiagnostics
487487
[ ( "P.hs",
488-
[ (DiagnosticSeverity_Error, (4, 6), "Couldn't match expected type 'Int' with actual type 'Bool'"),
489-
(DiagnosticSeverity_Warning, (4, 0), "Top-level binding")
488+
[ (DiagnosticSeverity_Error, (4, 6), "Couldn't match expected type 'Int' with actual type 'Bool'", Nothing),
489+
(DiagnosticSeverity_Warning, (4, 0), "Top-level binding", Nothing)
490490
]
491491
),
492492
("A.hs", [])
@@ -496,14 +496,14 @@ tests = testGroup "diagnostics"
496496
, testWithDummyPluginEmpty "deduplicate missing module diagnostics" $ do
497497
let fooContent = T.unlines [ "module Foo() where" , "import MissingModule" ]
498498
doc <- createDoc "Foo.hs" "haskell" fooContent
499-
expectDiagnostics [("Foo.hs", [(DiagnosticSeverity_Error, (1,7), "Could not find module 'MissingModule'")])]
499+
expectDiagnostics [("Foo.hs", [(DiagnosticSeverity_Error, (1,7), "Could not find module 'MissingModule'", Nothing)])]
500500

501501
changeDoc doc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $ "module Foo() where" ]
502502
expectDiagnostics []
503503

504504
changeDoc doc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $ T.unlines
505505
[ "module Foo() where" , "import MissingModule" ] ]
506-
expectDiagnostics [("Foo.hs", [(DiagnosticSeverity_Error, (1,7), "Could not find module 'MissingModule'")])]
506+
expectDiagnostics [("Foo.hs", [(DiagnosticSeverity_Error, (1,7), "Could not find module 'MissingModule'", Nothing)])]
507507

508508
, testGroup "Cancellation"
509509
[ cancellationTestGroup "edit header" editHeader yesSession noParse noTc
@@ -564,7 +564,7 @@ cancellationTemplate (edit, undoEdit) mbKey = testCase (maybe "-" fst mbKey) $ r
564564
]
565565

566566
-- for the example above we expect one warning
567-
let missingSigDiags = [(DiagnosticSeverity_Warning, (3, 0), "Top-level binding") ]
567+
let missingSigDiags = [(DiagnosticSeverity_Warning, (3, 0), "Top-level binding", Nothing) ]
568568
typeCheck doc >> expectCurrentDiagnostics doc missingSigDiags
569569

570570
-- Now we edit the document and wait for the given key (if any)

ghcide/test/exe/FindDefinitionAndHoverTests.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ tests = let
8888
, testGroup "hover" $ mapMaybe snd tests
8989
, testGroup "hover compile" [checkFileCompiles sourceFilePath $
9090
expectDiagnostics
91-
[ ( "GotoHover.hs", [(DiagnosticSeverity_Error, (62, 7), "Found hole: _")])
92-
, ( "GotoHover.hs", [(DiagnosticSeverity_Error, (65, 8), "Found hole: _")])
91+
[ ( "GotoHover.hs", [(DiagnosticSeverity_Error, (62, 7), "Found hole: _", Nothing)])
92+
, ( "GotoHover.hs", [(DiagnosticSeverity_Error, (65, 8), "Found hole: _", Nothing)])
9393
]]
9494
, testGroup "type-definition" typeDefinitionTests
9595
, testGroup "hover-record-dot-syntax" recordDotSyntaxTests ]

ghcide/test/exe/GarbageCollectionTests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ tests = testGroup "garbage collection"
7272
changeDoc doc [TextDocumentContentChangeEvent . InR $ TextDocumentContentChangeWholeDocument edit]
7373
builds <- waitForTypecheck doc
7474
liftIO $ assertBool "it still builds" builds
75-
expectCurrentDiagnostics doc [(DiagnosticSeverity_Error, (2,4), "Couldn't match expected type")]
75+
expectCurrentDiagnostics doc [(DiagnosticSeverity_Error, (2,4), "Couldn't match expected type", Nothing)]
7676
]
7777
]
7878
where

0 commit comments

Comments
 (0)