@@ -19,8 +19,8 @@ import GHC.Stack (HasCallStack)
19
19
import System.Environment (lookupEnv )
20
20
import System.Exit (ExitCode (.. ))
21
21
import System.IO
22
- ( BufferMode (NoBuffering ), Handle , IOMode (WriteMode )
23
- , hGetChar , hGetLine , hPutChar , hPutStrLn , hSetBuffering
22
+ ( BufferMode (NoBuffering , LineBuffering ), Handle , IOMode (WriteMode )
23
+ , hClose , hGetChar , hGetLine , hPutChar , hPutStrLn , hSetBuffering
24
24
, withFile
25
25
)
26
26
import System.IO.Error (isEOFError )
@@ -67,7 +67,7 @@ runRepl
67
67
:: HasCallStack
68
68
=> FilePath
69
69
-> [String ]
70
- -> ReaderT ReplConnection IO ()
70
+ -> Repl ()
71
71
-> IO ExitCode
72
72
runRepl cmd args actions = do
73
73
logInfo $ " Running: " ++ cmd ++ " " ++ unwords (map showProcessArgDebug args)
@@ -77,7 +77,7 @@ runRepl cmd args actions = do
77
77
, std_out = CreatePipe
78
78
, std_err = CreatePipe
79
79
}
80
- hSetBuffering rStdin NoBuffering
80
+ hSetBuffering rStdin LineBuffering
81
81
hSetBuffering rStdout NoBuffering
82
82
hSetBuffering rStderr NoBuffering
83
83
-- Log stack repl's standard error output
@@ -91,14 +91,18 @@ runRepl cmd args actions = do
91
91
catch
92
92
(hGetChar rStderr >>= hPutChar logFileHandle)
93
93
(\ e -> unless (isEOFError e) $ throw e)
94
+
95
+ -- run the test script which is to talk to the GHCi subprocess.
94
96
runReaderT actions (ReplConnection rStdin rStdout)
97
+
98
+ -- once done with the test, signal EOF on stdin for clean termination of ghci
99
+ hClose rStdin
100
+ -- read out the exit-code
95
101
waitForProcess ph
96
102
97
103
repl :: HasCallStack => [String ] -> Repl () -> IO ()
98
104
repl args action = do
99
105
stackExe' <- stackExe
100
106
ec <- runRepl stackExe' (" repl" : " --ghci-options=-ignore-dot-ghci" : args) action
101
- unless (ec == ExitSuccess ) $ pure ()
102
- -- TODO: Understand why the exit code is 1 despite running GHCi tests
103
- -- successfully.
104
- -- else error $ "Exited with exit code: " ++ show ec
107
+ unless (ec == ExitSuccess ) $
108
+ error $ " GHCi exited with " <> show ec
0 commit comments