@@ -35,6 +35,8 @@ import Development.IDE.Core.PositionMapping (PositionResult (..),
35
35
positionResultToMaybe ,
36
36
toCurrent )
37
37
import Development.IDE.Core.Shake (Q (.. ))
38
+ import Development.IDE.GHC.Compat (GhcVersion (.. ),
39
+ ghcVersion )
38
40
import Development.IDE.GHC.Util
39
41
import qualified Development.IDE.Main as IDE
40
42
import Development.IDE.Plugin.Completions.Types (extendImportCommandId )
@@ -538,17 +540,15 @@ diagnosticTests = testGroup "diagnostics"
538
540
, " foo = 1 {-|-}"
539
541
]
540
542
_ <- 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
+ )
548
551
]
549
- )
550
- ]
551
- #endif
552
552
, testSessionWait " strip file path" $ do
553
553
let
554
554
name = " Testing"
@@ -3629,12 +3629,11 @@ findDefinitionAndHoverTests = let
3629
3629
mkFindTests
3630
3630
-- def hover look expect
3631
3631
[
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"
3638
3637
, test yes yes fffL8 fff " field in record construction #1102"
3639
3638
, test yes yes fffL14 fff " field name used as accessor" -- https://github.com/haskell/ghcide/pull/120 in Calculate.hs
3640
3639
, test yes yes aaaL14 aaa " top-level name" -- https://github.com/haskell/ghcide/pull/120
@@ -3657,11 +3656,10 @@ findDefinitionAndHoverTests = let
3657
3656
, test yes yes lclL33 lcb " listcomp lookup"
3658
3657
, test yes yes mclL36 mcl " top-level fn 1st clause"
3659
3658
, 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"
3665
3663
, test no yes docL41 doc " documentation #1129"
3666
3664
, test no yes eitL40 kindE " kind of Either #1017"
3667
3665
, test no yes intL40 kindI " kind of Int #1017"
@@ -3670,18 +3668,20 @@ findDefinitionAndHoverTests = let
3670
3668
, test no broken chrL36 litC " literal Char in hover info #1016"
3671
3669
, test no broken txtL8 litT " literal Text in hover info #1016"
3672
3670
, 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"
3678
3675
, test broken broken outL45 outSig " top-level signature #767"
3679
3676
, test broken broken innL48 innSig " inner signature #767"
3680
3677
, test no yes holeL60 hleInfo " hole without internal name #831"
3681
3678
, test no skip cccL17 docLink " Haddock html links"
3682
3679
, testM yes yes imported importedSig " Imported symbol"
3683
3680
, 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"
3685
3685
]
3686
3686
where yes, broken :: (TestTree -> Maybe TestTree )
3687
3687
yes = Just -- test should run and pass
@@ -3699,7 +3699,7 @@ pluginSimpleTests :: TestTree
3699
3699
pluginSimpleTests =
3700
3700
ignoreInWindowsForGHC88And810 $
3701
3701
#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)" $
3703
3703
#endif
3704
3704
testSessionWithExtraFiles " plugin-knownnat" " simple plugin" $ \ dir -> do
3705
3705
_ <- openDoc (dir </> " KnownNat.hs" ) " haskell"
@@ -4404,34 +4404,26 @@ highlightTests = testGroup "highlight"
4404
4404
, DocumentHighlight (R 6 10 6 13 ) (Just HkRead )
4405
4405
, DocumentHighlight (R 7 12 7 15 ) (Just HkRead )
4406
4406
]
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
+ ]
4435
4427
]
4436
4428
where
4437
4429
source = T. unlines
@@ -4636,23 +4628,27 @@ xfail :: TestTree -> String -> TestTree
4636
4628
xfail = flip expectFailBecause
4637
4629
4638
4630
ignoreInWindowsBecause :: String -> TestTree -> TestTree
4639
- ignoreInWindowsBecause = if isWindows then ignoreTestBecause else (\ _ x -> x)
4631
+ ignoreInWindowsBecause
4632
+ | isWindows = ignoreTestBecause
4633
+ | otherwise = \ _ x -> x
4640
4634
4641
4635
ignoreInWindowsForGHC88And810 :: 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
4648
4640
4649
4641
ignoreInWindowsForGHC88 :: 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
+
4656
4652
4657
4653
data Expect
4658
4654
= ExpectRange Range -- Both gotoDef and hover should report this range
@@ -4811,13 +4807,11 @@ dependentFileTest = testGroup "addDependentFile"
4811
4807
let bazContent = T. unlines [" module Baz where" , " import Foo ()" ]
4812
4808
_ <- createDoc " Foo.hs" " haskell" fooContent
4813
4809
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" )])]
4821
4815
-- Now modify the dependent file
4822
4816
liftIO $ writeFile depFilePath " B"
4823
4817
sendNotification SWorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams $
@@ -5083,13 +5077,11 @@ sessionDepsArePickedUp = testSession'
5083
5077
" cradle: {direct: {arguments: []}}"
5084
5078
-- Open without OverloadedStrings and expect an error.
5085
5079
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" )])]
5093
5085
-- Update hie.yaml to enable OverloadedStrings.
5094
5086
liftIO $
5095
5087
writeFileUTF8
@@ -5799,16 +5791,10 @@ assertJust s = \case
5799
5791
5800
5792
-- | Before ghc9, lists of Char is displayed as [Char], but with ghc9 and up, it's displayed as String
5801
5793
listOfChar :: 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]"
5807
5796
5808
5797
-- | Ghc 9 doesn't include the $-sign in TH warnings like earlier versions did
5809
5798
thDollarIdx :: 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