diff --git a/cabal-testsuite/src/Test/Cabal/Run.hs b/cabal-testsuite/src/Test/Cabal/Run.hs index feb54b8221e..0f828ef3d70 100644 --- a/cabal-testsuite/src/Test/Cabal/Run.hs +++ b/cabal-testsuite/src/Test/Cabal/Run.hs @@ -55,19 +55,13 @@ run _verbosity mb_cwd env_overrides path0 args input = do (readstdout, writestdout) <- Compat.createPipe (readstderr, writestderr) <- Compat.createPipe (readall, writeall) <- Compat.createPipe - traverse_ (`hSetBuffering` LineBuffering) [ readstdout, writestdout, readstderr, writestderr, readall, writeall ] + traverse_ (`hSetBuffering` LineBuffering) [ stdout, readstdout, writestdout, readstderr, writestderr, readall, writeall ] let mkDrain h = do - r <- hGetContents h - length r `seq` hClose h + r <- hGetContents' h hPutStr writeall r return r - let mkDrain' h = do - r <- hGetContents h - length r `seq` hClose h - return r withAsync (mkDrain readstdout) $ \syncstdout -> do withAsync (mkDrain readstderr) $ \syncstderr -> do - withAsync (mkDrain' readall) $ \syncall -> do let prc = (proc path args) { cwd = mb_cwd @@ -90,7 +84,8 @@ run _verbosity mb_cwd env_overrides path0 args input = do rStdout <- wait syncstdout rStderr <- wait syncstderr hClose writeall - rAll <- wait syncall + + rAll <- hGetContents' readall return Result { resultExitCode = exitcode, @@ -99,3 +94,10 @@ run _verbosity mb_cwd env_overrides path0 args input = do resultStdout = rStdout, resultStderr = rStderr } + +-- `hGetContents'` is in since base-4.15.0.0 -- which we don't have. +hGetContents' :: Handle -> IO String +hGetContents' h = do + v <- hGetContents h + length v `seq` hClose h + pure v