Skip to content

Commit f8ac7a5

Browse files
committed
Tests for cradle retry
1 parent b013409 commit f8ac7a5

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

ghcide/test/exe/Main.hs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3385,7 +3385,7 @@ cradleTests :: TestTree
33853385
cradleTests = testGroup "cradle"
33863386
[testGroup "dependencies" [sessionDepsArePickedUp]
33873387
,testGroup "ignore-fatal" [ignoreFatalWarning]
3388-
,testGroup "loading" [loadCradleOnlyonce]
3388+
,testGroup "loading" [loadCradleOnlyonce, retryFailedCradle]
33893389
,testGroup "multi" [simpleMultiTest, simpleMultiTest2]
33903390
,testGroup "sub-directory" [simpleSubDirectoryTest]
33913391
]
@@ -3412,6 +3412,43 @@ loadCradleOnlyonce = testGroup "load cradle only once"
34123412
msgs <- manyTill (skipManyTill anyMessage cradleLoadedMessage) (skipManyTill anyMessage (message @PublishDiagnosticsNotification))
34133413
liftIO $ length msgs @?= 0
34143414

3415+
retryFailedCradle :: TestTree
3416+
retryFailedCradle = testSession' "retry failed" $ \dir -> do
3417+
-- The false cradle always fails
3418+
let hieContents = "cradle: {bios: {shell: \"false\"}}"
3419+
hiePath = dir </> "hie.yaml"
3420+
liftIO $ writeFile hiePath hieContents
3421+
hieDoc <- createDoc hiePath "yaml" $ T.pack hieContents
3422+
let aPath = dir </> "A.hs"
3423+
doc <- createDoc aPath "haskell" "main = return ()"
3424+
Right WaitForIdeRuleResult {..} <- waitForAction "TypeCheck" doc
3425+
liftIO $ "Test assumption failed: cradle should error out" `assertBool` not ideResultSuccess
3426+
3427+
-- Fix the cradle and typecheck again
3428+
let validCradle = "cradle: {bios: {shell: \"echo A.hs\"}}"
3429+
liftIO $ writeFileUTF8 hiePath $ T.unpack validCradle
3430+
changeDoc
3431+
hieDoc
3432+
[ TextDocumentContentChangeEvent
3433+
{ _range = Nothing,
3434+
_rangeLength = Nothing,
3435+
_text = validCradle
3436+
}
3437+
]
3438+
3439+
-- Force a session restart by making an edit, just to dirty the typecheck node
3440+
changeDoc
3441+
doc
3442+
[ TextDocumentContentChangeEvent
3443+
{ _range = Just Range {_start = Position 0 0, _end = Position 0 0},
3444+
_rangeLength = Nothing,
3445+
_text = "\n"
3446+
}
3447+
]
3448+
3449+
Right WaitForIdeRuleResult {..} <- waitForAction "TypeCheck" doc
3450+
liftIO $ "No joy after fixing the cradle" `assertBool` ideResultSuccess
3451+
34153452

34163453
dependentFileTest :: TestTree
34173454
dependentFileTest = testGroup "addDependentFile"

0 commit comments

Comments
 (0)