@@ -35,6 +35,8 @@ import Development.IDE.Core.PositionMapping (PositionResult (..),
3535 positionResultToMaybe ,
3636 toCurrent )
3737import Development.IDE.Core.Shake (Q (.. ))
38+ import Development.IDE.GHC.Compat (GhcVersion (.. ),
39+ ghcVersion )
3840import Development.IDE.GHC.Util
3941import qualified Development.IDE.Main as IDE
4042import Development.IDE.Plugin.Completions.Types (extendImportCommandId )
@@ -538,17 +540,15 @@ diagnosticTests = testGroup "diagnostics"
538540 , " foo = 1 {-|-}"
539541 ]
540542 _ <- createDoc " Foo.hs" " haskell" fooContent
541- #if MIN_VERSION_ghc(9,0,1)
542- -- Haddock parse errors are ignored on ghc-9.0.1
543- pure ()
544- #else
545- expectDiagnostics
546- [ ( " Foo.hs"
547- , [(DsWarning , (2 , 8 ), " Haddock parse error on input" )
543+ if ghcVersion >= GHC90 then
544+ -- Haddock parse errors are ignored on ghc-9.0.1
545+ pure ()
546+ else
547+ expectDiagnostics
548+ [ ( " Foo.hs"
549+ , [(DsWarning , (2 , 8 ), " Haddock parse error on input" )]
550+ )
548551 ]
549- )
550- ]
551- #endif
552552 , testSessionWait " strip file path" $ do
553553 let
554554 name = " Testing"
@@ -3629,12 +3629,11 @@ findDefinitionAndHoverTests = let
36293629 mkFindTests
36303630 -- def hover look expect
36313631 [
3632- #if MIN_VERSION_ghc(9,0,0)
3633- -- It suggests either going to the constructor or to the field
3634- test broken yes fffL4 fff " field in record definition"
3635- #else
3636- test yes yes fffL4 fff " field in record definition"
3637- #endif
3632+ if ghcVersion >= GHC90 then
3633+ -- It suggests either going to the constructor or to the field
3634+ test broken yes fffL4 fff " field in record definition"
3635+ else
3636+ test yes yes fffL4 fff " field in record definition"
36383637 , test yes yes fffL8 fff " field in record construction #1102"
36393638 , test yes yes fffL14 fff " field name used as accessor" -- https://github.com/haskell/ghcide/pull/120 in Calculate.hs
36403639 , test yes yes aaaL14 aaa " top-level name" -- https://github.com/haskell/ghcide/pull/120
@@ -3657,11 +3656,10 @@ findDefinitionAndHoverTests = let
36573656 , test yes yes lclL33 lcb " listcomp lookup"
36583657 , test yes yes mclL36 mcl " top-level fn 1st clause"
36593658 , test yes yes mclL37 mcl " top-level fn 2nd clause #1030"
3660- #if MIN_VERSION_ghc(8,10,0)
3661- , test yes yes spaceL37 space " top-level fn on space #1002"
3662- #else
3663- , test yes broken spaceL37 space " top-level fn on space #1002"
3664- #endif
3659+ , if ghcVersion >= GHC810 then
3660+ test yes yes spaceL37 space " top-level fn on space #1002"
3661+ else
3662+ test yes broken spaceL37 space " top-level fn on space #1002"
36653663 , test no yes docL41 doc " documentation #1129"
36663664 , test no yes eitL40 kindE " kind of Either #1017"
36673665 , test no yes intL40 kindI " kind of Int #1017"
@@ -3670,18 +3668,20 @@ findDefinitionAndHoverTests = let
36703668 , test no broken chrL36 litC " literal Char in hover info #1016"
36713669 , test no broken txtL8 litT " literal Text in hover info #1016"
36723670 , test no broken lstL43 litL " literal List in hover info #1016"
3673- #if MIN_VERSION_ghc(9,0,0)
3674- , test no yes docL41 constr " type constraint in hover info #1012"
3675- #else
3676- , test no broken docL41 constr " type constraint in hover info #1012"
3677- #endif
3671+ , if ghcVersion >= GHC90 then
3672+ test no yes docL41 constr " type constraint in hover info #1012"
3673+ else
3674+ test no broken docL41 constr " type constraint in hover info #1012"
36783675 , test broken broken outL45 outSig " top-level signature #767"
36793676 , test broken broken innL48 innSig " inner signature #767"
36803677 , test no yes holeL60 hleInfo " hole without internal name #831"
36813678 , test no skip cccL17 docLink " Haddock html links"
36823679 , testM yes yes imported importedSig " Imported symbol"
36833680 , testM yes yes reexported reexportedSig " Imported symbol (reexported)"
3684- , test no yes thLocL57 thLoc " TH Splice Hover"
3681+ , if ghcVersion == GHC90 && isWindows then
3682+ test no broken thLocL57 thLoc " TH Splice Hover"
3683+ else
3684+ test no yes thLocL57 thLoc " TH Splice Hover"
36853685 ]
36863686 where yes, broken :: (TestTree -> Maybe TestTree )
36873687 yes = Just -- test should run and pass
@@ -3699,7 +3699,7 @@ pluginSimpleTests :: TestTree
36993699pluginSimpleTests =
37003700 ignoreInWindowsForGHC88And810 $
37013701#if __GLASGOW_HASKELL__ == 810 && __GLASGOW_HASKELL_PATCHLEVEL1__ == 5
3702- expectFailBecause " known broken (see GHC #19763)" $
3702+ expectFailBecause " known broken for ghc 8.10.5 (see GHC #19763)" $
37033703#endif
37043704 testSessionWithExtraFiles " plugin-knownnat" " simple plugin" $ \ dir -> do
37053705 _ <- openDoc (dir </> " KnownNat.hs" ) " haskell"
@@ -4404,34 +4404,26 @@ highlightTests = testGroup "highlight"
44044404 , DocumentHighlight (R 6 10 6 13 ) (Just HkRead )
44054405 , DocumentHighlight (R 7 12 7 15 ) (Just HkRead )
44064406 ]
4407- ,
4408- #if MIN_VERSION_ghc(9,0,0)
4409- expectFailBecause " Ghc9 highlights the constructor and not just this field" $
4410- #endif
4411- testSessionWait " record" $ do
4412- doc <- createDoc " A.hs" " haskell" recsource
4413- _ <- waitForDiagnostics
4414- highlights <- getHighlights doc (Position 4 15 )
4415- liftIO $ highlights @?= List
4416- -- Span is just the .. on 8.10, but Rec{..} before
4417- [
4418- #if MIN_VERSION_ghc(8,10,0)
4419- DocumentHighlight (R 4 8 4 10 ) (Just HkWrite )
4420- #else
4421- DocumentHighlight (R 4 4 4 11 ) (Just HkWrite )
4422- #endif
4423- , DocumentHighlight (R 4 14 4 20 ) (Just HkRead )
4424- ]
4425- highlights <- getHighlights doc (Position 3 17 )
4426- liftIO $ highlights @?= List
4427- [ DocumentHighlight (R 3 17 3 23 ) (Just HkWrite )
4428- -- Span is just the .. on 8.10, but Rec{..} before
4429- #if MIN_VERSION_ghc(8,10,0)
4430- , DocumentHighlight (R 4 8 4 10 ) (Just HkRead )
4431- #else
4432- , DocumentHighlight (R 4 4 4 11 ) (Just HkRead )
4433- #endif
4434- ]
4407+ , knownBrokenForGhcVersions [GHC90 ] " Ghc9 highlights the constructor and not just this field" $
4408+ testSessionWait " record" $ do
4409+ doc <- createDoc " A.hs" " haskell" recsource
4410+ _ <- waitForDiagnostics
4411+ highlights <- getHighlights doc (Position 4 15 )
4412+ liftIO $ highlights @?= List
4413+ -- Span is just the .. on 8.10, but Rec{..} before
4414+ [ if ghcVersion >= GHC810
4415+ then DocumentHighlight (R 4 8 4 10 ) (Just HkWrite )
4416+ else DocumentHighlight (R 4 4 4 11 ) (Just HkWrite )
4417+ , DocumentHighlight (R 4 14 4 20 ) (Just HkRead )
4418+ ]
4419+ highlights <- getHighlights doc (Position 3 17 )
4420+ liftIO $ highlights @?= List
4421+ [ DocumentHighlight (R 3 17 3 23 ) (Just HkWrite )
4422+ -- Span is just the .. on 8.10, but Rec{..} before
4423+ , if ghcVersion >= GHC810
4424+ then DocumentHighlight (R 4 8 4 10 ) (Just HkRead )
4425+ else DocumentHighlight (R 4 4 4 11 ) (Just HkRead )
4426+ ]
44354427 ]
44364428 where
44374429 source = T. unlines
@@ -4636,23 +4628,27 @@ xfail :: TestTree -> String -> TestTree
46364628xfail = flip expectFailBecause
46374629
46384630ignoreInWindowsBecause :: String -> TestTree -> TestTree
4639- ignoreInWindowsBecause = if isWindows then ignoreTestBecause else (\ _ x -> x)
4631+ ignoreInWindowsBecause
4632+ | isWindows = ignoreTestBecause
4633+ | otherwise = \ _ x -> x
46404634
46414635ignoreInWindowsForGHC88And810 :: TestTree -> TestTree
4642- #if MIN_VERSION_ghc(8,8,1) && !MIN_VERSION_ghc(9,0,0)
4643- ignoreInWindowsForGHC88And810 =
4644- ignoreInWindowsBecause " tests are unreliable in windows for ghc 8.8 and 8.10"
4645- #else
4646- ignoreInWindowsForGHC88And810 = id
4647- #endif
4636+ ignoreInWindowsForGHC88And810
4637+ | ghcVersion `elem` [GHC88 , GHC810 ] =
4638+ ignoreInWindowsBecause " tests are unreliable in windows for ghc 8.8 and 8.10"
4639+ | otherwise = id
46484640
46494641ignoreInWindowsForGHC88 :: TestTree -> TestTree
4650- #if MIN_VERSION_ghc(8,8,1) && !MIN_VERSION_ghc(8,10,1)
4651- ignoreInWindowsForGHC88 =
4652- ignoreInWindowsBecause " tests are unreliable in windows for ghc 8.8"
4653- #else
4654- ignoreInWindowsForGHC88 = id
4655- #endif
4642+ ignoreInWindowsForGHC88
4643+ | ghcVersion == GHC88 =
4644+ ignoreInWindowsBecause " tests are unreliable in windows for ghc 8.8"
4645+ | otherwise = id
4646+
4647+ knownBrokenForGhcVersions :: [GhcVersion ] -> String -> TestTree -> TestTree
4648+ knownBrokenForGhcVersions ghcVers
4649+ | ghcVersion `elem` ghcVers = expectFailBecause
4650+ | otherwise = \ _ x -> x
4651+
46564652
46574653data Expect
46584654 = ExpectRange Range -- Both gotoDef and hover should report this range
@@ -4811,13 +4807,11 @@ dependentFileTest = testGroup "addDependentFile"
48114807 let bazContent = T. unlines [" module Baz where" , " import Foo ()" ]
48124808 _ <- createDoc " Foo.hs" " haskell" fooContent
48134809 doc <- createDoc " Baz.hs" " haskell" bazContent
4814- expectDiagnostics
4815- #if MIN_VERSION_ghc(9,0,0)
4816- -- String vs [Char] causes this change in error message
4817- [(" Foo.hs" , [(DsError , (4 , 6 ), " Couldn't match type" )])]
4818- #else
4819- [(" Foo.hs" , [(DsError , (4 , 6 ), " Couldn't match expected type" )])]
4820- #endif
4810+ expectDiagnostics $
4811+ if ghcVersion >= GHC90
4812+ -- String vs [Char] causes this change in error message
4813+ then [(" Foo.hs" , [(DsError , (4 , 6 ), " Couldn't match type" )])]
4814+ else [(" Foo.hs" , [(DsError , (4 , 6 ), " Couldn't match expected type" )])]
48214815 -- Now modify the dependent file
48224816 liftIO $ writeFile depFilePath " B"
48234817 sendNotification SWorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams $
@@ -5083,13 +5077,11 @@ sessionDepsArePickedUp = testSession'
50835077 " cradle: {direct: {arguments: []}}"
50845078 -- Open without OverloadedStrings and expect an error.
50855079 doc <- createDoc " Foo.hs" " haskell" fooContent
5086- expectDiagnostics
5087- #if MIN_VERSION_ghc(9,0,0)
5088- -- String vs [Char] causes this change in error message
5089- [(" Foo.hs" , [(DsError , (3 , 6 ), " Couldn't match type" )])]
5090- #else
5091- [(" Foo.hs" , [(DsError , (3 , 6 ), " Couldn't match expected type" )])]
5092- #endif
5080+ expectDiagnostics $
5081+ if ghcVersion >= GHC90
5082+ -- String vs [Char] causes this change in error message
5083+ then [(" Foo.hs" , [(DsError , (3 , 6 ), " Couldn't match type" )])]
5084+ else [(" Foo.hs" , [(DsError , (3 , 6 ), " Couldn't match expected type" )])]
50935085 -- Update hie.yaml to enable OverloadedStrings.
50945086 liftIO $
50955087 writeFileUTF8
@@ -5799,16 +5791,10 @@ assertJust s = \case
57995791
58005792-- | Before ghc9, lists of Char is displayed as [Char], but with ghc9 and up, it's displayed as String
58015793listOfChar :: T. Text
5802- #if MIN_VERSION_ghc(9,0,1)
5803- listOfChar = " String"
5804- #else
5805- listOfChar = " [Char]"
5806- #endif
5794+ listOfChar | ghcVersion >= GHC90 = " String"
5795+ | otherwise = " [Char]"
58075796
58085797-- | Ghc 9 doesn't include the $-sign in TH warnings like earlier versions did
58095798thDollarIdx :: Int
5810- #if MIN_VERSION_ghc(9,0,1)
5811- thDollarIdx = 1
5812- #else
5813- thDollarIdx = 0
5814- #endif
5799+ thDollarIdx | ghcVersion >= GHC90 = 1
5800+ | otherwise = 0
0 commit comments