Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a test that ensures that ghc --info contains "Have interpreter"

  • Loading branch information...
commit 334e2c9ab135eafc51682b7439942bfaa4dc43df 1 parent ac2d60d
Simon Hengel authored
Showing with 21 additions and 5 deletions.
  1. +13 −4 src/Interpreter.hs
  2. +8 −1 test/InterpreterSpec.hs
17 src/Interpreter.hs
View
@@ -5,6 +5,10 @@ module Interpreter (
, withInterpreter
, ghc
, interpreterSupported
+
+-- exported for testing
+, ghcInfo
+, haveInterpreterKey
) where
import System.IO
@@ -12,6 +16,7 @@ import System.Process
import System.Exit
import System.Directory (getPermissions, executable)
import Control.Monad (when, unless)
+import Control.Applicative
import Control.Exception hiding (handle)
import Data.Char
import Data.List
@@ -32,6 +37,12 @@ data Interpreter = Interpreter {
, process :: ProcessHandle
}
+haveInterpreterKey :: String
+haveInterpreterKey = "Have interpreter"
+
+ghcInfo :: IO [(String, String)]
+ghcInfo = read <$> readProcess ghc ["--info"] []
+
interpreterSupported :: IO Bool
interpreterSupported = do
-- in a perfect world this permission check should never fail, but I know of
@@ -39,10 +50,8 @@ interpreterSupported = do
x <- getPermissions ghc
unless (executable x) $ do
fail $ ghc ++ " is not executable!"
-
- info <- readProcess ghc ["--info"] []
- return $ maybe False (=="YES") $ lookup "Have interpreter" (read info)
+ maybe False (== "YES") . lookup haveInterpreterKey <$> ghcInfo
newInterpreter :: [String] -> IO Interpreter
newInterpreter flags = do
@@ -94,7 +103,7 @@ closeInterpreter repl = do
e <- waitForProcess $ process repl
hClose $ hOut repl
- when (e /= ExitSuccess) $ error $ "Interpreter exited with an error: " ++ show e
+ when (e /= ExitSuccess) $ error $ "Interpreter exited with an error: " ++ show e
return ()
putExpression :: Interpreter -> String -> IO ()
9 test/InterpreterSpec.hs
View
@@ -4,13 +4,14 @@ module InterpreterSpec (main, spec) where
import Test.Hspec
import Data.List (isSuffixOf)
+import Control.Applicative
#ifndef mingw32_HOST_OS
import System.Process (readProcess)
#endif
import qualified Interpreter
-import Interpreter (safeEval)
+import Interpreter (safeEval, haveInterpreterKey, ghcInfo)
main :: IO ()
main = hspec spec
@@ -35,6 +36,12 @@ spec = do
s `shouldBe` "success\n"
#endif
+ describe "ghcInfo" $ do
+ it ("includes " ++ show haveInterpreterKey) $ do
+ info <- ghcInfo
+ lookup haveInterpreterKey info `shouldSatisfy`
+ (||) <$> (== Just "YES") <*> (== Just "NO")
+
describe "eval" $ do
it "shows literals" $ withInterpreter $ \ghci -> do
ghci "23" `shouldEvaluateTo` "23\n"
Please sign in to comment.
Something went wrong with that request. Please try again.