Skip to content

Commit 2b4074e

Browse files
committed
Use tasty's TestName, remove pre ghc 9.0 workaround
1 parent 42be329 commit 2b4074e

File tree

1 file changed

+33
-40
lines changed
  • plugins/hls-refactor-plugin/test

1 file changed

+33
-40
lines changed

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

+33-40
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ initializeTests = withResource acquire release tests
103103
acquire :: IO (TResponseMessage Method_Initialize)
104104
acquire = run initializeResponse
105105

106-
107106
release :: TResponseMessage Method_Initialize -> IO ()
108107
release = const $ pure ()
109108

@@ -262,7 +261,7 @@ completionTests =
262261
]
263262
]
264263

265-
completionCommandTest :: String -> [T.Text] -> Position -> T.Text -> [T.Text] -> TestTree
264+
completionCommandTest :: TestName -> [T.Text] -> Position -> T.Text -> [T.Text] -> TestTree
266265
completionCommandTest name src pos wanted expected = testSession name $ do
267266
docId <- createDoc "A.hs" "haskell" (T.unlines src)
268267
_ <- waitForDiagnostics
@@ -286,7 +285,7 @@ completionCommandTest name src pos wanted expected = testSession name $ do
286285
expectMessages SMethod_WorkspaceApplyEdit 1 $ \edit ->
287286
liftIO $ assertFailure $ "Expected no edit but got: " <> show edit
288287

289-
completionNoCommandTest :: String -> [T.Text] -> Position -> T.Text -> TestTree
288+
completionNoCommandTest :: TestName -> [T.Text] -> Position -> T.Text -> TestTree
290289
completionNoCommandTest name src pos wanted = testSession name $ do
291290
docId <- createDoc "A.hs" "haskell" (T.unlines src)
292291
_ <- waitForDiagnostics
@@ -544,13 +543,13 @@ importQualifiedTests = testGroup "import qualified prefix suggestions"
544543
["import qualified Control.Monad as Control", "import Control.Monad (when)"]
545544
]
546545

547-
checkImport :: String -> FilePath -> FilePath -> T.Text -> TestTree
548-
checkImport testComment originalPath expectedPath action =
549-
checkImport' testComment originalPath expectedPath action []
546+
checkImport :: TestName -> FilePath -> FilePath -> T.Text -> TestTree
547+
checkImport testName originalPath expectedPath action =
548+
checkImport' testName originalPath expectedPath action []
550549

551-
checkImport' :: String -> FilePath -> FilePath -> T.Text -> [T.Text] -> TestTree
552-
checkImport' testComment originalPath expectedPath action excludedActions =
553-
testSessionWithExtraFiles "import-placement" testComment $ \dir ->
550+
checkImport' :: TestName -> FilePath -> FilePath -> T.Text -> [T.Text] -> TestTree
551+
checkImport' testName originalPath expectedPath action excludedActions =
552+
testSessionWithExtraFiles "import-placement" testName $ \dir ->
554553
check (dir </> originalPath) (dir </> expectedPath) action
555554
where
556555
check :: FilePath -> FilePath -> T.Text -> Session ()
@@ -631,7 +630,7 @@ renameActionTests = testGroup "rename actions"
631630
]
632631
]
633632
where
634-
check :: String -> [T.Text] -> (T.Text, Range) -> [T.Text] -> TestTree
633+
check :: TestName -> [T.Text] -> (T.Text, Range) -> [T.Text] -> TestTree
635634
check testName linesOrig (actionTitle, actionRange) linesExpected =
636635
testSession testName $ do
637636
let contentBefore = T.unlines linesOrig
@@ -2402,14 +2401,14 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
24022401
[ (DiagnosticSeverity_Warning, (6, 8), "Defaulting the following constraint")
24032402
, (DiagnosticSeverity_Warning, (6, 16), "Defaulting the following constraint")
24042403
])
2405-
("Add type annotation ‘" <> listOfChar <> "’ to ‘\"debug\"")
2404+
"Add type annotation ‘String’ to ‘\"debug\""
24062405
[ "{-# OPTIONS_GHC -Wtype-defaults #-}"
24072406
, "{-# LANGUAGE OverloadedStrings #-}"
24082407
, "module A (f) where"
24092408
, ""
24102409
, "import Debug.Trace"
24112410
, ""
2412-
, "f = seq (\"debug\" :: " <> listOfChar <> ") traceShow \"debug\""
2411+
, "f = seq (\"debug\" :: String) traceShow \"debug\""
24132412
]
24142413
, testSession "add default type to satisfy two constraints" $
24152414
testFor
@@ -2424,14 +2423,14 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
24242423
(if ghcVersion >= GHC94
24252424
then [ (DiagnosticSeverity_Warning, (6, 6), "Defaulting the type variable") ]
24262425
else [ (DiagnosticSeverity_Warning, (6, 6), "Defaulting the following constraint") ])
2427-
("Add type annotation ‘" <> listOfChar <> "’ to ‘\"debug\"")
2426+
"Add type annotation ‘String’ to ‘\"debug\""
24282427
[ "{-# OPTIONS_GHC -Wtype-defaults #-}"
24292428
, "{-# LANGUAGE OverloadedStrings #-}"
24302429
, "module A (f) where"
24312430
, ""
24322431
, "import Debug.Trace"
24332432
, ""
2434-
, "f a = traceShow (\"debug\" :: " <> listOfChar <> ") a"
2433+
, "f a = traceShow (\"debug\" :: String) a"
24352434
]
24362435
, testSession "add default type to satisfy two constraints with duplicate literals" $
24372436
testFor
@@ -2446,14 +2445,14 @@ addTypeAnnotationsToLiteralsTest = testGroup "add type annotations to literals t
24462445
(if ghcVersion >= GHC94
24472446
then [ (DiagnosticSeverity_Warning, (6, 54), "Defaulting the type variable") ]
24482447
else [ (DiagnosticSeverity_Warning, (6, 54), "Defaulting the following constraint") ])
2449-
("Add type annotation ‘" <> listOfChar <> "’ to ‘\"debug\"")
2448+
"Add type annotation ‘String’ to ‘\"debug\""
24502449
[ "{-# OPTIONS_GHC -Wtype-defaults #-}"
24512450
, "{-# LANGUAGE OverloadedStrings #-}"
24522451
, "module A (f) where"
24532452
, ""
24542453
, "import Debug.Trace"
24552454
, ""
2456-
, "f = seq (\"debug\" :: [Char]) (seq (\"debug\" :: [Char]) (traceShow (\"debug\" :: " <> listOfChar <> ")))"
2455+
, "f = seq (\"debug\" :: [Char]) (seq (\"debug\" :: [Char]) (traceShow (\"debug\" :: String)))"
24572456
]
24582457
]
24592458
where
@@ -2520,20 +2519,19 @@ fillTypedHoleTests = let
25202519
sourceCode :: T.Text -> T.Text -> T.Text -> T.Text
25212520
sourceCode a b c = T.unlines
25222521
[ "module Testing where"
2523-
, ""
2524-
, "globalConvert :: Int -> String"
2525-
, "globalConvert = undefined"
2526-
, ""
2527-
, "globalInt :: Int"
2528-
, "globalInt = 3"
2529-
, ""
2530-
, "bar :: Int -> Int -> String"
2531-
, "bar n parameterInt = " <> a <> " (n + " <> b <> " + " <> c <> ") where"
2532-
, " localConvert = (flip replicate) 'x'"
2533-
, ""
2534-
, "foo :: () -> Int -> String"
2535-
, "foo = undefined"
2536-
2522+
, ""
2523+
, "globalConvert :: Int -> String"
2524+
, "globalConvert = undefined"
2525+
, ""
2526+
, "globalInt :: Int"
2527+
, "globalInt = 3"
2528+
, ""
2529+
, "bar :: Int -> Int -> String"
2530+
, "bar n parameterInt = " <> a <> " (n + " <> b <> " + " <> c <> ") where"
2531+
, " localConvert = (flip replicate) 'x'"
2532+
, ""
2533+
, "foo :: () -> Int -> String"
2534+
, "foo = undefined"
25372535
]
25382536

25392537
check :: T.Text -> T.Text -> T.Text -> T.Text -> T.Text -> T.Text -> T.Text -> TestTree
@@ -2818,7 +2816,7 @@ addFunctionConstraintTests = let
28182816
(missingMonadConstraint "Monad m => ")
28192817
]
28202818

2821-
checkCodeAction :: String -> T.Text -> T.Text -> T.Text -> TestTree
2819+
checkCodeAction :: TestName -> T.Text -> T.Text -> T.Text -> TestTree
28222820
checkCodeAction testName actionTitle originalCode expectedCode = testSession testName $ do
28232821
doc <- createDoc "Testing.hs" "haskell" originalCode
28242822
_ <- waitForDiagnostics
@@ -3659,7 +3657,7 @@ extendImportTestsRegEx = testGroup "regex parsing"
36593657
pickActionWithTitle :: T.Text -> [Command |? CodeAction] -> Session CodeAction
36603658
pickActionWithTitle title actions =
36613659
case matches of
3662-
[] -> liftIO . assertFailure $ "CodeAction with title '" <> show title <> "' not found in " <> show titles
3660+
[] -> liftIO . assertFailure $ "CodeAction with title " <> show title <> " not found in " <> show titles
36633661
a:_ -> pure a
36643662
where
36653663
titles =
@@ -3686,18 +3684,18 @@ assertNoActionWithTitle title actions =
36863684
assertActionWithTitle :: [Command |? CodeAction] -> T.Text -> Session ()
36873685
assertActionWithTitle actions title =
36883686
liftIO $ assertBool
3689-
("CodeAction with title '" <> show title <>"' not found in " <> show titles)
3687+
("CodeAction with title " <> show title <>" not found in " <> show titles)
36903688
(title `elem` titles)
36913689
where
36923690
titles =
36933691
[ actionTitle
36943692
| InR CodeAction { _title = actionTitle } <- actions
36953693
]
36963694

3697-
testSession :: String -> Session () -> TestTree
3695+
testSession :: TestName -> Session () -> TestTree
36983696
testSession name = testCase name . run
36993697

3700-
testSessionWithExtraFiles :: HasCallStack => FilePath -> String -> (FilePath -> Session ()) -> TestTree
3698+
testSessionWithExtraFiles :: HasCallStack => FilePath -> TestName -> (FilePath -> Session ()) -> TestTree
37013699
testSessionWithExtraFiles prefix name = testCase name . runWithExtraFiles prefix
37023700

37033701
runWithExtraFiles :: HasCallStack => FilePath -> (FilePath -> Session a) -> IO a
@@ -3745,8 +3743,3 @@ assertJust :: MonadIO m => String -> Maybe a -> m a
37453743
assertJust s = \case
37463744
Nothing -> liftIO $ assertFailure s
37473745
Just x -> pure x
3748-
3749-
-- | Before ghc9, lists of Char is displayed as [Char], but with ghc9 and up, it's displayed as String
3750-
listOfChar :: T.Text
3751-
listOfChar | ghcVersion >= GHC90 = "String"
3752-
| otherwise = "[Char]"

0 commit comments

Comments
 (0)