Skip to content
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

Prefer hls-test-utils functions over code duplication #3870

Merged
merged 3 commits into from
Nov 16, 2023
Merged
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
50 changes: 7 additions & 43 deletions plugins/hls-refactor-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import Language.LSP.Protocol.Types hiding
import Language.LSP.Test
import System.Directory
import System.FilePath
import System.Info.Extra (isMac, isWindows)
import qualified System.IO.Extra
import System.IO.Extra hiding (withTempDir)
import System.Time.Extra
Expand Down Expand Up @@ -1313,7 +1312,7 @@ extendImportTests = testGroup "extend import actions"
, "b :: A"
, "b = ConstructorFoo"
])
, ignoreForGHC94 "On GHC 9.4, the error messages with -fdefer-type-errors don't have necessary imported target srcspan info." $
, brokenForGHC94 "On GHC 9.4, the error messages with -fdefer-type-errors don't have necessary imported target srcspan info." $
testSession "extend single line qualified import with value" $ template
[("ModuleA.hs", T.unlines
[ "module ModuleA where"
Expand Down Expand Up @@ -1485,7 +1484,7 @@ extendImportTests = testGroup "extend import actions"
, "import A (pattern Some)"
, "k (Some x) = x"
])
, ignoreFor (BrokenForGHC [GHC92, GHC94]) "Diagnostic message has no suggestions" $
, ignoreForGhcVersions [GHC92, GHC94] "Diagnostic message has no suggestions" $
testSession "type constructor name same as data constructor name" $ template
[("ModuleA.hs", T.unlines
[ "module ModuleA where"
Expand Down Expand Up @@ -1751,7 +1750,7 @@ suggestImportTests = testGroup "suggest import actions"
suggestAddRecordFieldImportTests :: TestTree
suggestAddRecordFieldImportTests = testGroup "suggest imports of record fields when using OverloadedRecordDot"
[ testGroup "The field is suggested when an instance resolution failure occurs"
[ ignoreFor (BrokenForGHC [GHC90, GHC94, GHC96]) "Extension not present <9.2, and the assist is derived from the help message in >=9.4" theTest
[ ignoreForGhcVersions [GHC90, GHC94, GHC96] "Extension not present <9.2, and the assist is derived from the help message in >=9.4" theTest
]
]
where
Expand Down Expand Up @@ -3190,7 +3189,7 @@ exportUnusedTests = testGroup "export unused actions"
(R 2 0 2 11)
"Export ‘bar’"
Nothing
, ignoreFor (BrokenForGHC [GHC92, GHC94]) "Diagnostic message has no suggestions" $
, ignoreForGhcVersions [GHC92, GHC94] "Diagnostic message has no suggestions" $
testSession "type is exported but not the constructor of same name" $ template
(T.unlines
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
Expand Down Expand Up @@ -3840,45 +3839,10 @@ withTempDir f = System.IO.Extra.withTempDir $ \dir -> do
f dir'

ignoreForGHC92 :: String -> TestTree -> TestTree
ignoreForGHC92 = ignoreFor (BrokenForGHC [GHC92])

ignoreForGHC94 :: String -> TestTree -> TestTree
ignoreForGHC94 = knownIssueFor Broken (BrokenForGHC [GHC94])

data BrokenTarget =
BrokenSpecific OS [GhcVersion]
-- ^Broken for `BrokenOS` with `GhcVersion`
| BrokenForOS OS
-- ^Broken for `BrokenOS`
| BrokenForGHC [GhcVersion]
-- ^Broken for `GhcVersion`
deriving (Show)

-- | Ignore test for specific os and ghc with reason.
ignoreFor :: BrokenTarget -> String -> TestTree -> TestTree
ignoreFor = knownIssueFor Ignore

-- | Deal with `IssueSolution` for specific OS and GHC.
knownIssueFor :: IssueSolution -> BrokenTarget -> String -> TestTree -> TestTree
knownIssueFor solution = go . \case
BrokenSpecific bos vers -> isTargetOS bos && isTargetGhc vers
BrokenForOS bos -> isTargetOS bos
BrokenForGHC vers -> isTargetGhc vers
where
isTargetOS = \case
Windows -> isWindows
MacOS -> isMac
Linux -> not isWindows && not isMac

isTargetGhc = elem ghcVersion

go True = case solution of
Broken -> expectFailBecause
Ignore -> ignoreTestBecause
go False = \_ -> id

ignoreForGHC92 = ignoreForGhcVersions [GHC92]

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

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