Skip to content

Commit 8b3232b

Browse files
committed
ghcide-tests: Show errors where they are caused
instead of deep inside some generic helper function
1 parent 746ec29 commit 8b3232b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

ghcide/test/exe/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5129,7 +5129,7 @@ testSessionWithExtraFiles prefix name = testCase name . runWithExtraFiles prefix
51295129
testSession' :: String -> (FilePath -> Session ()) -> TestTree
51305130
testSession' name = testCase name . run'
51315131

5132-
testSessionWait :: String -> Session () -> TestTree
5132+
testSessionWait :: HasCallStack => String -> Session () -> TestTree
51335133
testSessionWait name = testSession name .
51345134
-- Check that any diagnostics produced were already consumed by the test case.
51355135
--

ghcide/test/src/Development/IDE/Test.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Cursor = (Int, Int)
4747
cursorPosition :: Cursor -> Position
4848
cursorPosition (line, col) = Position line col
4949

50-
requireDiagnostic :: List Diagnostic -> (DiagnosticSeverity, Cursor, T.Text, Maybe DiagnosticTag) -> Assertion
50+
requireDiagnostic :: HasCallStack => List Diagnostic -> (DiagnosticSeverity, Cursor, T.Text, Maybe DiagnosticTag) -> Assertion
5151
requireDiagnostic actuals expected@(severity, cursor, expectedMsg, expectedTag) = do
5252
unless (any match actuals) $
5353
assertFailure $
@@ -69,7 +69,7 @@ requireDiagnostic actuals expected@(severity, cursor, expectedMsg, expectedTag)
6969

7070
-- |wait for @timeout@ seconds and report an assertion failure
7171
-- if any diagnostic messages arrive in that period
72-
expectNoMoreDiagnostics :: Seconds -> Session ()
72+
expectNoMoreDiagnostics :: HasCallStack => Seconds -> Session ()
7373
expectNoMoreDiagnostics timeout =
7474
expectMessages STextDocumentPublishDiagnostics timeout $ \diagsNot -> do
7575
let fileUri = diagsNot ^. params . uri
@@ -109,23 +109,23 @@ flushMessages = do
109109
--
110110
-- Rather than trying to assert the absence of diagnostics, introduce an
111111
-- expected diagnostic (e.g. a redundant import) and assert the singleton diagnostic.
112-
expectDiagnostics :: [(FilePath, [(DiagnosticSeverity, Cursor, T.Text)])] -> Session ()
112+
expectDiagnostics :: HasCallStack => [(FilePath, [(DiagnosticSeverity, Cursor, T.Text)])] -> Session ()
113113
expectDiagnostics
114114
= expectDiagnosticsWithTags
115115
. map (second (map (\(ds, c, t) -> (ds, c, t, Nothing))))
116116

117117
unwrapDiagnostic :: NotificationMessage TextDocumentPublishDiagnostics -> (Uri, List Diagnostic)
118118
unwrapDiagnostic diagsNot = (diagsNot^.params.uri, diagsNot^.params.diagnostics)
119119

120-
expectDiagnosticsWithTags :: [(String, [(DiagnosticSeverity, Cursor, T.Text, Maybe DiagnosticTag)])] -> Session ()
120+
expectDiagnosticsWithTags :: HasCallStack => [(String, [(DiagnosticSeverity, Cursor, T.Text, Maybe DiagnosticTag)])] -> Session ()
121121
expectDiagnosticsWithTags expected = do
122122
let f = getDocUri >=> liftIO . canonicalizeUri >=> pure . toNormalizedUri
123123
next = unwrapDiagnostic <$> skipManyTill anyMessage diagnostic
124124
expected' <- Map.fromListWith (<>) <$> traverseOf (traverse . _1) f expected
125125
expectDiagnosticsWithTags' next expected'
126126

127127
expectDiagnosticsWithTags' ::
128-
MonadIO m =>
128+
(HasCallStack, MonadIO m) =>
129129
m (Uri, List Diagnostic) ->
130130
Map.Map NormalizedUri [(DiagnosticSeverity, Cursor, T.Text, Maybe DiagnosticTag)] ->
131131
m ()
@@ -165,12 +165,12 @@ expectDiagnosticsWithTags' next expected = go expected
165165
<> show actual
166166
go $ Map.delete canonUri m
167167

168-
expectCurrentDiagnostics :: TextDocumentIdentifier -> [(DiagnosticSeverity, Cursor, T.Text)] -> Session ()
168+
expectCurrentDiagnostics :: HasCallStack => TextDocumentIdentifier -> [(DiagnosticSeverity, Cursor, T.Text)] -> Session ()
169169
expectCurrentDiagnostics doc expected = do
170170
diags <- getCurrentDiagnostics doc
171171
checkDiagnosticsForDoc doc expected diags
172172

173-
checkDiagnosticsForDoc :: TextDocumentIdentifier -> [(DiagnosticSeverity, Cursor, T.Text)] -> [Diagnostic] -> Session ()
173+
checkDiagnosticsForDoc :: HasCallStack => TextDocumentIdentifier -> [(DiagnosticSeverity, Cursor, T.Text)] -> [Diagnostic] -> Session ()
174174
checkDiagnosticsForDoc TextDocumentIdentifier {_uri} expected obtained = do
175175
let expected' = Map.fromList [(nuri, map (\(ds, c, t) -> (ds, c, t, Nothing)) expected)]
176176
nuri = toNormalizedUri _uri

0 commit comments

Comments
 (0)