Skip to content

Commit 609205c

Browse files
committed
fix: resolve a TODO about unexpected exit code 1
runRepl was missing the `hClose rStdin` call -- causing the ghci subprocess to terminate abnormally with EPIPE on its stdin read.
1 parent a123a28 commit 609205c

File tree

1 file changed

+12
-8
lines changed
  • tests/integration/lib/StackTest

1 file changed

+12
-8
lines changed

tests/integration/lib/StackTest/Repl.hs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import GHC.Stack (HasCallStack)
1919
import System.Environment (lookupEnv)
2020
import System.Exit (ExitCode (..))
2121
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
2424
, withFile
2525
)
2626
import System.IO.Error (isEOFError)
@@ -67,7 +67,7 @@ runRepl
6767
:: HasCallStack
6868
=> FilePath
6969
-> [String]
70-
-> ReaderT ReplConnection IO ()
70+
-> Repl ()
7171
-> IO ExitCode
7272
runRepl cmd args actions = do
7373
logInfo $ "Running: " ++ cmd ++ " " ++ unwords (map showProcessArgDebug args)
@@ -77,7 +77,7 @@ runRepl cmd args actions = do
7777
, std_out = CreatePipe
7878
, std_err = CreatePipe
7979
}
80-
hSetBuffering rStdin NoBuffering
80+
hSetBuffering rStdin LineBuffering
8181
hSetBuffering rStdout NoBuffering
8282
hSetBuffering rStderr NoBuffering
8383
-- Log stack repl's standard error output
@@ -91,14 +91,18 @@ runRepl cmd args actions = do
9191
catch
9292
(hGetChar rStderr >>= hPutChar logFileHandle)
9393
(\e -> unless (isEOFError e) $ throw e)
94+
95+
-- run the test script which is to talk to the GHCi subprocess.
9496
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
95101
waitForProcess ph
96102

97103
repl :: HasCallStack => [String] -> Repl () -> IO ()
98104
repl args action = do
99105
stackExe' <- stackExe
100106
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

Comments
 (0)