Skip to content

Commit 3faecfa

Browse files
fendormichaelpj
andauthored
Prefer hls-test-utils functions over code duplication (#3870)
Co-authored-by: Michael Peyton Jones <[email protected]>
1 parent 5a923ce commit 3faecfa

File tree

1 file changed

+7
-43
lines changed
  • plugins/hls-refactor-plugin/test

1 file changed

+7
-43
lines changed

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

+7-43
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import Language.LSP.Protocol.Types hiding
4343
import Language.LSP.Test
4444
import System.Directory
4545
import System.FilePath
46-
import System.Info.Extra (isMac, isWindows)
4746
import qualified System.IO.Extra
4847
import System.IO.Extra hiding (withTempDir)
4948
import System.Time.Extra
@@ -1313,7 +1312,7 @@ extendImportTests = testGroup "extend import actions"
13131312
, "b :: A"
13141313
, "b = ConstructorFoo"
13151314
])
1316-
, ignoreForGHC94 "On GHC 9.4, the error messages with -fdefer-type-errors don't have necessary imported target srcspan info." $
1315+
, brokenForGHC94 "On GHC 9.4, the error messages with -fdefer-type-errors don't have necessary imported target srcspan info." $
13171316
testSession "extend single line qualified import with value" $ template
13181317
[("ModuleA.hs", T.unlines
13191318
[ "module ModuleA where"
@@ -1485,7 +1484,7 @@ extendImportTests = testGroup "extend import actions"
14851484
, "import A (pattern Some)"
14861485
, "k (Some x) = x"
14871486
])
1488-
, ignoreFor (BrokenForGHC [GHC92, GHC94]) "Diagnostic message has no suggestions" $
1487+
, ignoreForGhcVersions [GHC92, GHC94] "Diagnostic message has no suggestions" $
14891488
testSession "type constructor name same as data constructor name" $ template
14901489
[("ModuleA.hs", T.unlines
14911490
[ "module ModuleA where"
@@ -1751,7 +1750,7 @@ suggestImportTests = testGroup "suggest import actions"
17511750
suggestAddRecordFieldImportTests :: TestTree
17521751
suggestAddRecordFieldImportTests = testGroup "suggest imports of record fields when using OverloadedRecordDot"
17531752
[ testGroup "The field is suggested when an instance resolution failure occurs"
1754-
[ ignoreFor (BrokenForGHC [GHC90, GHC94, GHC96]) "Extension not present <9.2, and the assist is derived from the help message in >=9.4" theTest
1753+
[ ignoreForGhcVersions [GHC90, GHC94, GHC96] "Extension not present <9.2, and the assist is derived from the help message in >=9.4" theTest
17551754
]
17561755
]
17571756
where
@@ -3190,7 +3189,7 @@ exportUnusedTests = testGroup "export unused actions"
31903189
(R 2 0 2 11)
31913190
"Export ‘bar’"
31923191
Nothing
3193-
, ignoreFor (BrokenForGHC [GHC92, GHC94]) "Diagnostic message has no suggestions" $
3192+
, ignoreForGhcVersions [GHC92, GHC94] "Diagnostic message has no suggestions" $
31943193
testSession "type is exported but not the constructor of same name" $ template
31953194
(T.unlines
31963195
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
@@ -3840,45 +3839,10 @@ withTempDir f = System.IO.Extra.withTempDir $ \dir -> do
38403839
f dir'
38413840

38423841
ignoreForGHC92 :: String -> TestTree -> TestTree
3843-
ignoreForGHC92 = ignoreFor (BrokenForGHC [GHC92])
3844-
3845-
ignoreForGHC94 :: String -> TestTree -> TestTree
3846-
ignoreForGHC94 = knownIssueFor Broken (BrokenForGHC [GHC94])
3847-
3848-
data BrokenTarget =
3849-
BrokenSpecific OS [GhcVersion]
3850-
-- ^Broken for `BrokenOS` with `GhcVersion`
3851-
| BrokenForOS OS
3852-
-- ^Broken for `BrokenOS`
3853-
| BrokenForGHC [GhcVersion]
3854-
-- ^Broken for `GhcVersion`
3855-
deriving (Show)
3856-
3857-
-- | Ignore test for specific os and ghc with reason.
3858-
ignoreFor :: BrokenTarget -> String -> TestTree -> TestTree
3859-
ignoreFor = knownIssueFor Ignore
3860-
3861-
-- | Deal with `IssueSolution` for specific OS and GHC.
3862-
knownIssueFor :: IssueSolution -> BrokenTarget -> String -> TestTree -> TestTree
3863-
knownIssueFor solution = go . \case
3864-
BrokenSpecific bos vers -> isTargetOS bos && isTargetGhc vers
3865-
BrokenForOS bos -> isTargetOS bos
3866-
BrokenForGHC vers -> isTargetGhc vers
3867-
where
3868-
isTargetOS = \case
3869-
Windows -> isWindows
3870-
MacOS -> isMac
3871-
Linux -> not isWindows && not isMac
3872-
3873-
isTargetGhc = elem ghcVersion
3874-
3875-
go True = case solution of
3876-
Broken -> expectFailBecause
3877-
Ignore -> ignoreTestBecause
3878-
go False = \_ -> id
3879-
3842+
ignoreForGHC92 = ignoreForGhcVersions [GHC92]
38803843

3881-
data IssueSolution = Broken | Ignore deriving (Show)
3844+
brokenForGHC94 :: String -> TestTree -> TestTree
3845+
brokenForGHC94 = knownBrokenForGhcVersions [GHC94]
38823846

38833847
-- | Assert that a value is not 'Nothing', and extract the value.
38843848
assertJust :: MonadIO m => String -> Maybe a -> m a

0 commit comments

Comments
 (0)