Skip to content

Commit d935655

Browse files
committed
Remove unnecessary head usage in ghcide TestUtils
1 parent fdde5b8 commit d935655

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

ghcide/test/exe/TestUtils.hs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ knownIssueFor solution = go . \case
210210
go True = case solution of
211211
Broken -> expectFailBecause
212212
Ignore -> ignoreTestBecause
213-
go False = \_ -> id
213+
go False = const id
214214

215215
data Expect
216216
= ExpectRange Range -- Both gotoDef and hover should report this range
@@ -278,21 +278,22 @@ pattern R x y x' y' = Range (Position x y) (Position x' y')
278278
checkDefs :: Definition |? ([DefinitionLink] |? Null) -> Session [Expect] -> Session ()
279279
checkDefs (defToLocation -> defs) mkExpectations = traverse_ check =<< mkExpectations where
280280
check (ExpectRange expectedRange) = do
281-
assertNDefinitionsFound 1 defs
282-
assertRangeCorrect (head defs) expectedRange
281+
def <- assertOneDefinitionFound defs
282+
assertRangeCorrect def expectedRange
283283
check (ExpectLocation expectedLocation) = do
284-
assertNDefinitionsFound 1 defs
284+
def <- assertOneDefinitionFound defs
285285
liftIO $ do
286-
canonActualLoc <- canonicalizeLocation (head defs)
286+
canonActualLoc <- canonicalizeLocation def
287287
canonExpectedLoc <- canonicalizeLocation expectedLocation
288288
canonActualLoc @?= canonExpectedLoc
289289
check ExpectNoDefinitions = do
290-
assertNDefinitionsFound 0 defs
290+
liftIO $ assertBool "Expecting no definitions" $ null defs
291291
check ExpectExternFail = liftIO $ assertFailure "Expecting to fail to find in external file"
292292
check _ = pure () -- all other expectations not relevant to getDefinition
293293

294-
assertNDefinitionsFound :: Int -> [a] -> Session ()
295-
assertNDefinitionsFound n defs = liftIO $ assertEqual "number of definitions" n (length defs)
294+
assertOneDefinitionFound :: [Location] -> Session Location
295+
assertOneDefinitionFound [def] = pure def
296+
assertOneDefinitionFound _ = liftIO $ assertFailure "Expecting exactly one definition"
296297

297298
assertRangeCorrect Location{_range = foundRange} expectedRange =
298299
liftIO $ expectedRange @=? foundRange

0 commit comments

Comments
 (0)