Skip to content

Commit 2f5ee03

Browse files
committed
Fix testsuite
1 parent acbe401 commit 2f5ee03

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

ghcide/src/Development/IDE/GHC/Compat/Outputable.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ module Development.IDE.GHC.Compat.Outputable (
2020
#if MIN_VERSION_ghc(9,3,0)
2121
DiagnosticReason(..),
2222
renderDiagnosticMessageWithHints,
23+
pprMsgEnvelopeBagWithLoc,
24+
Error.getMessages,
25+
renderWithContext,
26+
defaultSDocContext,
27+
errMsgDiagnostic,
28+
unDecorated,
29+
diagnosticMessage,
2330
#else
2431
pprWarning,
2532
pprError,
@@ -29,6 +36,7 @@ module Development.IDE.GHC.Compat.Outputable (
2936
MsgEnvelope,
3037
ErrMsg,
3138
WarnMsg,
39+
SourceError(..),
3240
errMsgSpan,
3341
errMsgSeverity,
3442
formatErrorWithQual,

plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE NoMonomorphismRestriction #-}
22
{-# LANGUAGE ScopedTypeVariables #-}
3+
{-# LANGUAGE CPP #-}
34
{-# OPTIONS_GHC -Wno-orphans #-}
45

56
-- |Debug utilities
@@ -11,15 +12,16 @@ module Ide.Plugin.Eval.Util (
1112
logWith,
1213
) where
1314

14-
import Control.Exception (SomeException, evaluate)
15+
import Control.Exception (SomeException, evaluate, fromException)
1516
import Control.Monad.IO.Class (MonadIO (liftIO))
1617
import Control.Monad.Trans.Except (ExceptT (..), runExceptT)
1718
import Data.Aeson (Value (Null))
1819
import Data.String (IsString (fromString))
1920
import qualified Data.Text as T
2021
import Development.IDE (IdeState, Priority (..),
2122
ideLogger, logPriority)
22-
import Development.IDE.GHC.Compat.Util (MonadCatch, catch)
23+
import Development.IDE.GHC.Compat.Util (MonadCatch, catch, bagToList)
24+
import Development.IDE.GHC.Compat.Outputable
2325
import GHC.Exts (toList)
2426
import GHC.Stack (HasCallStack, callStack,
2527
srcLocFile, srcLocStartCol,
@@ -79,4 +81,17 @@ gevaluate :: MonadIO m => a -> m a
7981
gevaluate = liftIO . evaluate
8082

8183
showErr :: Monad m => SomeException -> m (Either String b)
82-
showErr = return . Left . show
84+
showErr e =
85+
#if MIN_VERSION_ghc(9,3,0)
86+
case fromException e of
87+
-- On GHC 9.4+, the show instance adds the error message span
88+
-- We don't want this for the plugin
89+
-- So render without the span.
90+
Just (SourceError msgs) -> return $ Left $ renderWithContext defaultSDocContext
91+
$ vcat
92+
$ bagToList
93+
$ fmap (vcat . unDecorated . diagnosticMessage . errMsgDiagnostic)
94+
$ getMessages msgs
95+
_ ->
96+
#endif
97+
return . Left . show $ e

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ tests =
8181
evalInFile "T8.hs" "-- >>> 3 `div` 0" "-- divide by zero" -- The default for marking exceptions is False
8282
, goldenWithEval "Applies file LANGUAGE extensions" "T9" "hs"
8383
, goldenWithEval' "Evaluate a type with :kind!" "T10" "hs" (if ghcVersion >= GHC92 then "ghc92.expected" else "expected")
84-
, goldenWithEval' "Reports an error for an incorrect type with :kind!" "T11" "hs" (if ghcVersion == GHC92 then "ghc92.expected" else "expected")
84+
, goldenWithEval' "Reports an error for an incorrect type with :kind!" "T11" "hs" (if ghcVersion >= GHC92 then "ghc92.expected" else "expected")
8585
, goldenWithEval' "Shows a kind with :kind" "T12" "hs" (if ghcVersion >= GHC92 then "ghc92.expected" else "expected")
86-
, goldenWithEval' "Reports an error for an incorrect type with :kind" "T13" "hs" (if ghcVersion == GHC92 then "ghc92.expected" else "expected")
86+
, goldenWithEval' "Reports an error for an incorrect type with :kind" "T13" "hs" (if ghcVersion >= GHC92 then "ghc92.expected" else "expected")
8787
, goldenWithEval "Returns a fully-instantiated type for :type" "T14" "hs"
88-
, knownBrokenForGhcVersions [GHC92] "type +v does not work anymore with 9.2" $ goldenWithEval "Returns an uninstantiated type for :type +v, admitting multiple whitespaces around arguments" "T15" "hs"
88+
, knownBrokenForGhcVersions [GHC92, GHC94] "type +v does not work anymore with 9.2" $ goldenWithEval "Returns an uninstantiated type for :type +v, admitting multiple whitespaces around arguments" "T15" "hs"
8989
, goldenWithEval "Returns defaulted type for :type +d, admitting multiple whitespaces around arguments" "T16" "hs"
9090
, goldenWithEval' ":type reports an error when given with unknown +x option" "T17" "hs" (if ghcVersion >= GHC92 then "ghc92.expected" else "expected")
9191
, goldenWithEval "Reports an error when given with unknown command" "T18" "hs"
@@ -135,7 +135,7 @@ tests =
135135
, goldenWithEval "The default language extensions for the eval plugin are the same as those for ghci" "TSameDefaultLanguageExtensionsAsGhci" "hs"
136136
, goldenWithEval "IO expressions are supported, stdout/stderr output is ignored" "TIO" "hs"
137137
, goldenWithEval "Property checking" "TProperty" "hs"
138-
, goldenWithEval "Property checking with exception" "TPropertyError" "hs"
138+
, goldenWithEval' "Property checking with exception" "TPropertyError" "hs" (if ghcVersion >= GHC94 then "ghc94.expected" else "expected")
139139
, goldenWithEval "Prelude has no special treatment, it is imported as stated in the module" "TPrelude" "hs"
140140
, goldenWithEval "Don't panic on {-# UNPACK #-} pragma" "TUNPACK" "hs"
141141
, goldenWithEval "Can handle eval inside nested comment properly" "TNested" "hs"

0 commit comments

Comments
 (0)