Skip to content

Commit 03e3426

Browse files
committed
Make HLS refactor use the existing ignore test infrastructure
1 parent 2b94f85 commit 03e3426

File tree

2 files changed

+29
-40
lines changed
  • hls-test-utils/src/Test/Hls
  • plugins/hls-refactor-plugin/test

2 files changed

+29
-40
lines changed

hls-test-utils/src/Test/Hls/Util.hs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@ module Test.Hls.Util
2828
, inspectCodeAction
2929
, inspectCommand
3030
, inspectDiagnostic
31+
-- * Mark tests as broken for various reasons.
3132
, knownBrokenOnWindows
3233
, knownBrokenForGhcVersions
34+
, knownIssueInEnv
3335
, knownBrokenInEnv
3436
, onlyWorkForGhcVersions
37+
-- * Setup test-suite state
3538
, setupBuildToolFiles
39+
-- * Diagnostics helpers
3640
, SymbolLocation
3741
, waitForDiagnosticsFrom
3842
, waitForDiagnosticsFromSource
3943
, waitForDiagnosticsFromSourceWithTimeout
44+
-- * Working directory modifications
4045
, withCurrentDirectoryInTmp
4146
, withCurrentDirectoryInTmp'
4247
, withCanonicalTempDir
@@ -115,7 +120,19 @@ files =
115120
-- , "./test/testdata/wErrorTest/"
116121
]
117122

118-
data EnvSpec = HostOS OS | GhcVer GhcVersion
123+
-- | Why is the test broken?
124+
--
125+
-- Are they broken for the given spec or are we just ignoring the test
126+
-- because the test doesn't make sense in the Environment.
127+
data IssueSolution
128+
= Broken
129+
-- ^ Mark a test as known broken, expecting the test to be fixed eventually.
130+
| Ignore
131+
-- ^ Mark a test as ignored, because the test doesn't make sense in the
132+
-- associated environment.
133+
deriving (Show)
134+
135+
data EnvSpec = HostOS OS | GhcVer GhcVersion | Specific OS GhcVersion
119136
deriving (Show, Eq)
120137

121138
matchesCurrentEnv :: EnvSpec -> Bool
@@ -131,11 +148,18 @@ hostOS
131148
| isMac = MacOS
132149
| otherwise = Linux
133150

151+
-- | Mark the given TestTree as having a known issue if /any/ of environmental
152+
-- spec matches the current environment.
153+
knownIssueInEnv :: IssueSolution -> [EnvSpec] -> String -> TestTree -> TestTree
154+
knownIssueInEnv issueSolution envSpecs reason
155+
| any matchesCurrentEnv envSpecs = case issueSolution of
156+
Broken -> expectFailBecause reason
157+
Ignore -> ignoreTestBecause reason
158+
| otherwise = id
159+
134160
-- | Mark as broken if /any/ of environmental spec mathces the current environment.
135161
knownBrokenInEnv :: [EnvSpec] -> String -> TestTree -> TestTree
136-
knownBrokenInEnv envSpecs reason
137-
| any matchesCurrentEnv envSpecs = expectFailBecause reason
138-
| otherwise = id
162+
knownBrokenInEnv = knownIssueInEnv Broken
139163

140164
knownBrokenOnWindows :: String -> TestTree -> TestTree
141165
knownBrokenOnWindows = knownBrokenInEnv [HostOS Windows]

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3719,42 +3719,7 @@ withTempDir f = System.IO.Extra.withTempDir $ \dir -> do
37193719
f dir'
37203720

37213721
ignoreForGHC92 :: String -> TestTree -> TestTree
3722-
ignoreForGHC92 = ignoreFor (BrokenForGHC [GHC92])
3723-
3724-
data BrokenTarget =
3725-
BrokenSpecific OS [GhcVersion]
3726-
-- ^Broken for `BrokenOS` with `GhcVersion`
3727-
| BrokenForOS OS
3728-
-- ^Broken for `BrokenOS`
3729-
| BrokenForGHC [GhcVersion]
3730-
-- ^Broken for `GhcVersion`
3731-
deriving (Show)
3732-
3733-
-- | Ignore test for specific os and ghc with reason.
3734-
ignoreFor :: BrokenTarget -> String -> TestTree -> TestTree
3735-
ignoreFor = knownIssueFor Ignore
3736-
3737-
-- | Deal with `IssueSolution` for specific OS and GHC.
3738-
knownIssueFor :: IssueSolution -> BrokenTarget -> String -> TestTree -> TestTree
3739-
knownIssueFor solution = go . \case
3740-
BrokenSpecific bos vers -> isTargetOS bos && isTargetGhc vers
3741-
BrokenForOS bos -> isTargetOS bos
3742-
BrokenForGHC vers -> isTargetGhc vers
3743-
where
3744-
isTargetOS = \case
3745-
Windows -> isWindows
3746-
MacOS -> isMac
3747-
Linux -> not isWindows && not isMac
3748-
3749-
isTargetGhc = elem ghcVersion
3750-
3751-
go True = case solution of
3752-
Broken -> expectFailBecause
3753-
Ignore -> ignoreTestBecause
3754-
go False = \_ -> id
3755-
3756-
3757-
data IssueSolution = Broken | Ignore deriving (Show)
3722+
ignoreForGHC92 = knownIssueInEnv Ignore [GhcVer GHC92]
37583723

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

0 commit comments

Comments
 (0)