Skip to content

Commit c4d5edd

Browse files
committed
Add expected error codes for diagnostics that have them
1 parent 2cd33df commit c4d5edd

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

ghcide/test/exe/DiagnosticTests.hs

Lines changed: 27 additions & 27 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", Nothing)])]
51+
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "parse error", Just "GHC-58481")])]
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", Nothing)])]
70+
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "parse error", Just "GHC-58481")])]
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'", Nothing)])]
74+
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "Not in scope: 'missing'", Just "GHC-76037")])]
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'", Nothing)])]
81+
expectDiagnostics [("Testing.hs", [(DiagnosticSeverity_Error, (0, 15), "Not in scope: 'lissing'", Just "GHC-76037")])]
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", Nothing)
94-
, (DiagnosticSeverity_Error, (4, 11), "Variable not in scope: cd", Nothing)
93+
, [ (DiagnosticSeverity_Error, (2, 15), "Variable not in scope: ab", Just "GHC-88464")
94+
, (DiagnosticSeverity_Error, (4, 11), "Variable not in scope: cd", Just "GHC-88464")
9595
]
9696
)
9797
]
@@ -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", Nothing)]
119+
, [(DiagnosticSeverity_Error, (2, 8), "Found hole: _ :: Int -> String", Just "GHC-88464")]
120120
)
121121
]
122122

@@ -131,17 +131,17 @@ tests = testGroup "diagnostics"
131131
, "b :: Float"
132132
, "b = True"]
133133
bMessage = "Couldn't match expected type 'Float' with actual type 'Bool'"
134-
expectedDs aMessage =
135-
[ ("A.hs", [(DiagnosticSeverity_Error, (2,4), aMessage, Nothing)])
136-
, ("B.hs", [(DiagnosticSeverity_Error, (3,4), bMessage, Nothing)])]
137-
deferralTest title binding msg = testWithDummyPluginEmpty title $ do
134+
expectedDs aMessage aCode =
135+
[ ("A.hs", [(DiagnosticSeverity_Error, (2,4), aMessage, aCode)])
136+
, ("B.hs", [(DiagnosticSeverity_Error, (3,4), bMessage, Just "GHC-83865")])]
137+
deferralTest title binding msg code = testWithDummyPluginEmpty title $ do
138138
_ <- createDoc "A.hs" "haskell" $ sourceA binding
139139
_ <- createDoc "B.hs" "haskell" sourceB
140-
expectDiagnostics $ expectedDs msg
140+
expectDiagnostics $ expectedDs msg code
141141
in
142-
[ deferralTest "type error" "True" "Couldn't match expected type"
143-
, deferralTest "typed hole" "_" "Found hole"
144-
, deferralTest "out of scope var" "unbound" "Variable not in scope"
142+
[ deferralTest "type error" "True" "Couldn't match expected type" (Just "GHC-83865")
143+
, deferralTest "typed hole" "_" "Found hole" (Just "GHC-88464")
144+
, deferralTest "out of scope var" "unbound" "Variable not in scope" (Just "GHC-88464")
145145
]
146146

147147
, testWithDummyPluginEmpty "remove required module" $ do
@@ -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", Nothing)])]
246+
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Warning, (3,0), "Top-level binding", Just "GHC-38417")])]
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", Nothing)])]
271+
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Warning, (3,0), "Top-level binding", Just "GHC-38417")])]
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", Nothing)])]
297+
expectDiagnostics [("ModuleC.hs", [(DiagnosticSeverity_Warning, (3,0), "Top-level binding", Just "GHC-38417")])]
298298
, testWithDummyPluginEmpty "redundant import" $ do
299299
let contentA = T.unlines ["module ModuleA where"]
300300
let contentB = T.unlines
@@ -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", Nothing)])]
323+
expectDiagnostics [("ModuleB.hs", [(DiagnosticSeverity_Warning, (3,0), "Top-level binding", Just "GHC-38417")])]
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", Nothing)
351+
"Not in scope: \8216ThisList.map\8217", Just "GHC-88464")
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", Nothing)
358+
"Not in scope: \8216BaseList.x\8217", Just "GHC-88464")
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", Nothing)
376+
, [(DiagnosticSeverity_Warning, (2, if ghcVersion >= GHC94 then 7 else 0), "Redundant constraint: Ord a", Just "GHC-30606")
377377
]
378378
)
379379
]
@@ -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", Nothing)])] -- So that we know P has been loaded
472+
[("P.hs", [(DiagnosticSeverity_Warning,(4,0), "Top-level binding", Just "GHC-38417")])] -- 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'", Nothing)])
478+
[("A.hs", [(DiagnosticSeverity_Error, (5, 4), "Couldn't match expected type 'Int' with actual type 'Bool'", Just "GHC-83865")])
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'", Nothing),
489-
(DiagnosticSeverity_Warning, (4, 0), "Top-level binding", Nothing)
488+
[ (DiagnosticSeverity_Error, (4, 6), "Couldn't match expected type 'Int' with actual type 'Bool'", Just "GHC-83865"),
489+
(DiagnosticSeverity_Warning, (4, 0), "Top-level binding", Just "GHC-38417")
490490
]
491491
),
492492
("A.hs", [])
@@ -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", Nothing) ]
567+
let missingSigDiags = [(DiagnosticSeverity_Warning, (3, 0), "Top-level binding", Just "GHC-38417") ]
568568
typeCheck doc >> expectCurrentDiagnostics doc missingSigDiags
569569

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

0 commit comments

Comments
 (0)