Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Oct 23, 2024
1 parent 0e565d3 commit d9afbcc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
18 changes: 11 additions & 7 deletions src/Language/Haskell/GhciWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module Language.Haskell.GhciWrapper (
#ifdef TEST
, sensei_ghc_version
, lookupGhc
, getGhcVersion
, lookupGhcVersion
, numericVersion
, extractReloadDiagnostics
, extractDiagnostics
#endif
Expand All @@ -37,20 +38,23 @@ import qualified ReadHandle
import GHC.Diagnostic (Diagnostic)
import qualified GHC.Diagnostic as Diagnostic

sensei_ghc :: String
sensei_ghc = "SENSEI_GHC"

sensei_ghc_version :: String
sensei_ghc_version = "SENSEI_GHC_VERSION"

lookupGhc :: [(String, String)] -> FilePath
lookupGhc = fromMaybe "ghc" . lookup sensei_ghc
lookupGhc = fromMaybe "ghc" . lookup "SENSEI_GHC"

lookupGhcVersion :: [(String, String)] -> Maybe String
lookupGhcVersion = lookup sensei_ghc_version

getGhcVersion :: FilePath -> [(String, String)] -> IO String
getGhcVersion ghc env = case lookup sensei_ghc_version env of
Nothing -> strip <$> readProcess ghc ["--numeric-version"] ""
getGhcVersion ghc env = case lookupGhcVersion env of
Nothing -> numericVersion ghc
Just version -> return version

numericVersion :: [Char] -> IO [Char]
numericVersion ghc = strip <$> readProcess ghc ["--numeric-version"] ""

data Config = Config {
configIgnoreDotGhci :: Bool
, configWorkingDirectory :: Maybe FilePath
Expand Down
1 change: 0 additions & 1 deletion test/GHC/DiagnosticSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ test name = it name $ do
translate = map \ case
'' -> '`'
'' -> '\''
-- '•' -> '*'
c -> c

ftest :: HasCallStack => FilePath -> Spec
Expand Down
6 changes: 3 additions & 3 deletions test/Helper.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
module Helper (
module Imports
, silent
Expand Down Expand Up @@ -124,6 +125,5 @@ to_json = toStrict . encode
requireGhc :: [Int] -> IO ()
requireGhc (makeVersion -> required) = do
env <- getEnvironment
let ghc = lookupGhc env
ghcVersion <- parseVersion <$> getGhcVersion ghc env
when (ghcVersion < Just required) pending
let Just ghcVersion = lookupGhcVersion env >>= parseVersion
when (ghcVersion < required) pending
2 changes: 1 addition & 1 deletion test/Language/Haskell/GhciWrapperSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ spec = do

context "with -fno-diagnostics-as-json" $ do
it "does not extract diagnostics" do
requireGhc [9, 10]
requireGhc [9,10]
withModule \ file -> do
withInterpreter ["-fno-diagnostics-as-json", file] \ ghci -> do
failingModule file
Expand Down
8 changes: 4 additions & 4 deletions test/SpecHook.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ ensurePackageEnvironment ghc file = doesFileExist file >>= \ case
False -> installPackageEnvironment ghc file
True -> pass

getGhcVersion :: FilePath -> [(FilePath, FilePath)] -> IO FilePath
getGhcVersion ghc env = do
ghcVersion <- Interpreter.getGhcVersion ghc env
getGhcVersion :: FilePath -> IO String
getGhcVersion ghc = do
ghcVersion <- Interpreter.numericVersion ghc
setEnv Interpreter.sensei_ghc_version ghcVersion
return ghcVersion

Expand All @@ -25,7 +25,7 @@ setPackageEnvironment = do
dir <- getCurrentDirectory
env <- getEnvironment
let ghc = Interpreter.lookupGhc env
ghcVersion <- getGhcVersion ghc env
ghcVersion <- getGhcVersion ghc
let file = dir </> "dist-newstyle" </> "test-env" </> ghcVersion
ensurePackageEnvironment ghc file
setEnv "GHC_ENVIRONMENT" file
Expand Down

0 comments on commit d9afbcc

Please sign in to comment.