Skip to content

Commit aa69bda

Browse files
committed
Migrate some plugins to the new test plugin recorder structure
1 parent 1cc3d2f commit aa69bda

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

plugins/hls-alternate-number-format-plugin/test/Main.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import Text.Regex.TDFA ((=~))
1919
main :: IO ()
2020
main = defaultTestRunner test
2121

22-
alternateNumberFormatPlugin :: PluginDescriptor IdeState
23-
alternateNumberFormatPlugin = AlternateNumberFormat.descriptor mempty "alternateNumberFormat"
22+
alternateNumberFormatPlugin :: Recorder (WithPriority AlternateNumberFormat.Log) -> PluginDescriptor IdeState
23+
alternateNumberFormatPlugin recorder = AlternateNumberFormat.descriptor recorder "alternateNumberFormat"
2424

2525
-- NOTE: For whatever reason, this plugin does not play nice with creating Code Actions on time.
2626
-- As a result tests will mostly pass if `import Prelude` is added at the top. We (mostly fendor) surmise this has something
@@ -54,7 +54,7 @@ test = testGroup "alternateNumberFormat" [
5454

5555
codeActionProperties :: TestName -> [(Int, Int)] -> ([CodeAction] -> Session ()) -> TestTree
5656
codeActionProperties fp locs assertions = testCase fp $ do
57-
runSessionWithServer alternateNumberFormatPlugin testDataDir $ do
57+
runSessionWithServerAndRecorder alternateNumberFormatPlugin testDataDir $ do
5858
openDoc (fp <.> ".hs") "haskell" >>= codeActionsFromLocs >>= findAlternateNumberActions >>= assertions
5959
where
6060
-- similar to codeActionTest
@@ -75,7 +75,7 @@ testDataDir :: FilePath
7575
testDataDir = "test" </> "testdata"
7676

7777
goldenAlternateFormat :: FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
78-
goldenAlternateFormat fp = goldenWithHaskellDoc alternateNumberFormatPlugin (fp <> " (golden)") testDataDir fp "expected" "hs"
78+
goldenAlternateFormat fp = goldenWithHaskellDoc (alternateNumberFormatPlugin mempty) (fp <> " (golden)") testDataDir fp "expected" "hs"
7979

8080
codeActionTest :: (Maybe Text -> Bool) -> FilePath -> Int -> Int -> TestTree
8181
codeActionTest filter' fp line col = goldenAlternateFormat fp $ \doc -> do

plugins/hls-cabal-fmt-plugin/test/Main.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ main = do
3030
foundCabalFmt <- isCabalFmtFound
3131
defaultTestRunner (tests foundCabalFmt)
3232

33-
cabalFmtPlugin :: PluginDescriptor IdeState
34-
cabalFmtPlugin = CabalFmt.descriptor mempty "cabal-fmt"
33+
cabalFmtPlugin :: Recorder (WithPriority CabalFmt.Log) -> PluginDescriptor IdeState
34+
cabalFmtPlugin recorder = CabalFmt.descriptor recorder "cabal-fmt"
3535

3636
tests :: CabalFmtFound -> TestTree
3737
tests found = testGroup "cabal-fmt"
@@ -52,7 +52,7 @@ cabalFmtGolden NotFound title _ _ _ =
5252
testCase title $
5353
assertFailure $ "Couldn't find cabal-fmt on PATH or this is not an isolated run. "
5454
<> "Use cabal flag 'isolateTests' to make it isolated or install cabal-fmt locally."
55-
cabalFmtGolden Found title path desc act = goldenWithCabalDocFormatter cabalFmtPlugin "cabal-fmt" conf title testDataDir path desc "cabal" act
55+
cabalFmtGolden Found title path desc act = goldenWithCabalDocFormatter (cabalFmtPlugin mempty) "cabal-fmt" conf title testDataDir path desc "cabal" act
5656
where
5757
conf = def
5858

plugins/hls-class-plugin/test/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import Test.Hls
2525

2626
main :: IO ()
2727
main = do
28-
recorder <- makeDefaultStderrRecorder Nothing Debug
29-
defaultTestRunner . tests $ contramap (fmap pretty) recorder
28+
recorder <- pluginTestRecorder
29+
defaultTestRunner . tests $ recorder
3030

3131
classPlugin :: Recorder (WithPriority Class.Log) -> PluginDescriptor IdeState
3232
classPlugin recorder = Class.descriptor recorder "class"

plugins/hls-code-range-plugin/test/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ plugin recorder = descriptor recorder "codeRange"
2323

2424
main :: IO ()
2525
main = do
26-
recorder <- contramap (fmap pretty) <$> makeDefaultStderrRecorder Nothing Debug
26+
recorder <- pluginTestRecorder
2727
defaultTestRunner $
2828
testGroup "Code Range" [
2929
testGroup "Integration Tests" [

plugins/hls-eval-plugin/test/Main.hs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,34 @@ import Test.Hls
2929
main :: IO ()
3030
main = defaultTestRunner tests
3131

32-
evalPlugin :: PluginDescriptor IdeState
33-
evalPlugin = Eval.descriptor mempty "eval"
32+
evalPlugin :: Recorder (WithPriority Eval.Log) -> PluginDescriptor IdeState
33+
evalPlugin recorder = Eval.descriptor recorder "eval"
3434

3535
tests :: TestTree
3636
tests =
3737
testGroup "eval"
3838
[ testCase "Produces Evaluate code lenses" $
39-
runSessionWithServer evalPlugin testDataDir $ do
39+
runSessionWithServerAndRecorder evalPlugin testDataDir $ do
4040
doc <- openDoc "T1.hs" "haskell"
4141
lenses <- getCodeLenses doc
4242
liftIO $ map (preview $ command . _Just . title) lenses @?= [Just "Evaluate..."]
4343
, testCase "Produces Refresh code lenses" $
44-
runSessionWithServer evalPlugin testDataDir $ do
44+
runSessionWithServerAndRecorder evalPlugin testDataDir $ do
4545
doc <- openDoc "T2.hs" "haskell"
4646
lenses <- getCodeLenses doc
4747
liftIO $ map (preview $ command . _Just . title) lenses @?= [Just "Refresh..."]
4848
, testCase "Code lenses have ranges" $
49-
runSessionWithServer evalPlugin testDataDir $ do
49+
runSessionWithServerAndRecorder evalPlugin testDataDir $ do
5050
doc <- openDoc "T1.hs" "haskell"
5151
lenses <- getCodeLenses doc
5252
liftIO $ map (view range) lenses @?= [Range (Position 4 0) (Position 5 0)]
5353
, testCase "Multi-line expressions have a multi-line range" $ do
54-
runSessionWithServer evalPlugin testDataDir $ do
54+
runSessionWithServerAndRecorder evalPlugin testDataDir $ do
5555
doc <- openDoc "T3.hs" "haskell"
5656
lenses <- getCodeLenses doc
5757
liftIO $ map (view range) lenses @?= [Range (Position 3 0) (Position 5 0)]
5858
, testCase "Executed expressions range covers only the expression" $ do
59-
runSessionWithServer evalPlugin testDataDir $ do
59+
runSessionWithServerAndRecorder evalPlugin testDataDir $ do
6060
doc <- openDoc "T2.hs" "haskell"
6161
lenses <- getCodeLenses doc
6262
liftIO $ map (view range) lenses @?= [Range (Position 4 0) (Position 5 0)]
@@ -194,7 +194,7 @@ tests =
194194
not ("Baz Foo" `isInfixOf` output) @? "Output includes instance Baz Foo"
195195
]
196196
, testCase "Interfaces are reused after Eval" $ do
197-
runSessionWithServer evalPlugin testDataDir $ do
197+
runSessionWithServerAndRecorder evalPlugin testDataDir $ do
198198
doc <- openDoc "TLocalImport.hs" "haskell"
199199
waitForTypecheck doc
200200
lenses <- getCodeLenses doc
@@ -213,13 +213,13 @@ tests =
213213

214214
goldenWithEval :: TestName -> FilePath -> FilePath -> TestTree
215215
goldenWithEval title path ext =
216-
goldenWithHaskellDoc evalPlugin title testDataDir path "expected" ext executeLensesBackwards
216+
goldenWithHaskellDocAndRecorder evalPlugin title testDataDir path "expected" ext executeLensesBackwards
217217

218218
-- | Similar function as 'goldenWithEval' with an alternate reference file
219219
-- naming. Useful when reference file may change because of GHC version.
220220
goldenWithEval' :: TestName -> FilePath -> FilePath -> FilePath -> TestTree
221221
goldenWithEval' title path ext expected =
222-
goldenWithHaskellDoc evalPlugin title testDataDir path expected ext executeLensesBackwards
222+
goldenWithHaskellDocAndRecorder evalPlugin title testDataDir path expected ext executeLensesBackwards
223223

224224
-- | Execute lenses backwards, to avoid affecting their position in the source file
225225
executeLensesBackwards :: TextDocumentIdentifier -> Session ()
@@ -246,7 +246,7 @@ executeCmd cmd = do
246246
pure ()
247247

248248
evalLenses :: FilePath -> IO [CodeLens]
249-
evalLenses path = runSessionWithServer evalPlugin testDataDir $ do
249+
evalLenses path = runSessionWithServerAndRecorder evalPlugin testDataDir $ do
250250
doc <- openDoc path "haskell"
251251
executeLensesBackwards doc
252252
getCodeLenses doc
@@ -280,12 +280,12 @@ exceptionConfig exCfg = changeConfig ["exception" .= exCfg]
280280

281281
goldenWithEvalConfig' :: TestName -> FilePath -> FilePath -> FilePath -> Config -> TestTree
282282
goldenWithEvalConfig' title path ext expected cfg =
283-
goldenWithHaskellDoc evalPlugin title testDataDir path expected ext $ \doc -> do
283+
goldenWithHaskellDocAndRecorder evalPlugin title testDataDir path expected ext $ \doc -> do
284284
sendConfigurationChanged (toJSON cfg)
285285
executeLensesBackwards doc
286286

287287
evalInFile :: HasCallStack => FilePath -> T.Text -> T.Text -> IO ()
288-
evalInFile fp e expected = runSessionWithServer evalPlugin testDataDir $ do
288+
evalInFile fp e expected = runSessionWithServerAndRecorder evalPlugin testDataDir $ do
289289
doc <- openDoc fp "haskell"
290290
origin <- documentContents doc
291291
let withEval = origin <> e

0 commit comments

Comments
 (0)