Skip to content

Subsequent tactics test rebased on top of fixed lsp-test #2509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Core/RuleTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ newtype GhcSessionDeps = GhcSessionDeps_
-- Required for interactive evaluation, but leads to more cache invalidations
fullModSummary :: Bool
}
deriving newtype (Eq, Show, Typeable, Hashable, NFData)
deriving (Eq, Show, Typeable, Hashable, NFData)

pattern GhcSessionDeps :: GhcSessionDeps
pattern GhcSessionDeps = GhcSessionDeps_ False
Expand Down
2 changes: 0 additions & 2 deletions plugins/hls-tactics-plugin/hls-tactics-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
test/golden/*.cabal
test/golden/*.hs
test/golden/*.yaml

flag pedantic
description: Enable -Werror
Expand Down
6 changes: 6 additions & 0 deletions plugins/hls-tactics-plugin/test/ProviderSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ spec = do
"T2" 8 8
[ (not, Intros, "")
]

goldenTestMany "SubsequentTactics"
[ InvokeTactic Intros "" 4 5
, InvokeTactic Destruct "du" 4 8
, InvokeTactic Auto "" 4 15
]
60 changes: 35 additions & 25 deletions plugins/hls-tactics-plugin/test/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE RecordWildCards #-}

module Utils where

Expand Down Expand Up @@ -96,39 +97,45 @@ mkTest name fp line col ts = it name $ do
liftIO $
(title `elem` titles) `shouldSatisfy` f

data InvokeTactic = InvokeTactic
{ it_command :: TacticCommand
, it_argument :: Text
, it_line :: Int
, it_col :: Int
}

invokeTactic :: TextDocumentIdentifier -> InvokeTactic -> Session ()
invokeTactic doc InvokeTactic{..} = do
-- wait for the entire build to finish, so that Tactics code actions that
-- use stale data will get uptodate stuff
void waitForDiagnostics
void $ waitForTypecheck doc
actions <- getCodeActions doc $ pointRange it_line it_col
case find ((== Just (tacticTitle it_command it_argument)) . codeActionTitle) actions of
Just (InR CodeAction {_command = Just c}) -> do
executeCommand c
void $ skipManyTill anyMessage $ message SWorkspaceApplyEdit
_ -> error $ show actions


mkGoldenTest
:: (Text -> Text -> Assertion)
-> TacticCommand
-> Text
-> Int
-> Int
-> [InvokeTactic]
-> FilePath
-> SpecWith ()
mkGoldenTest eq tc occ line col input =
mkGoldenTest eq invocations input =
it (input <> " (golden)") $ do
resetGlobalHoleRef
runSessionForTactics $ do
doc <- openDoc (input <.> "hs") "haskell"
-- wait for diagnostics to start coming
void waitForDiagnostics
-- wait for the entire build to finish, so that Tactics code actions that
-- use stale data will get uptodate stuff
void $ waitForTypecheck doc
actions <- getCodeActions doc $ pointRange line col
case find ((== Just (tacticTitle tc occ)) . codeActionTitle) actions of
Just (InR CodeAction {_command = Just c}) -> do
executeCommand c
_resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit)
edited <- documentContents doc
let expected_name = input <.> "expected" <.> "hs"
-- Write golden tests if they don't already exist
liftIO $ (doesFileExist expected_name >>=) $ flip unless $ do
T.writeFile expected_name edited
expected <- liftIO $ T.readFile expected_name
liftIO $ edited `eq` expected
_ -> error $ show actions
traverse_ (invokeTactic doc) invocations
edited <- documentContents doc
let expected_name = input <.> "expected" <.> "hs"
-- Write golden tests if they don't already exist
liftIO $ (doesFileExist expected_name >>=) $ flip unless $ do
T.writeFile expected_name edited
expected <- liftIO $ T.readFile expected_name
liftIO $ edited `eq` expected

mkCodeLensTest
:: FilePath
Expand Down Expand Up @@ -197,10 +204,13 @@ mkShowMessageTest tc occ line col input ufm =


goldenTest :: TacticCommand -> Text -> Int -> Int -> FilePath -> SpecWith ()
goldenTest = mkGoldenTest shouldBe
goldenTest tc occ line col = mkGoldenTest shouldBe [InvokeTactic tc occ line col]

goldenTestMany :: FilePath -> [InvokeTactic] -> SpecWith ()
goldenTestMany = flip $ mkGoldenTest shouldBe

goldenTestNoWhitespace :: TacticCommand -> Text -> Int -> Int -> FilePath -> SpecWith ()
goldenTestNoWhitespace = mkGoldenTest shouldBeIgnoringSpaces
goldenTestNoWhitespace tc occ line col = mkGoldenTest shouldBeIgnoringSpaces [InvokeTactic tc occ line col]


shouldBeIgnoringSpaces :: Text -> Text -> Assertion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data Dummy a = Dummy a

f :: Dummy Int -> Int
f (Dummy n) = n

5 changes: 5 additions & 0 deletions plugins/hls-tactics-plugin/test/golden/SubsequentTactics.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data Dummy a = Dummy a

f :: Dummy Int -> Int
f = _

1 change: 0 additions & 1 deletion plugins/hls-tactics-plugin/test/golden/hie.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions plugins/hls-tactics-plugin/test/golden/test.cabal

This file was deleted.