@@ -13,8 +13,6 @@ import Test.Tasty
1313import Test.Tasty.HUnit
1414import Test.Tasty.ExpectedFailure
1515import Test.Utils
16- import qualified Data.ByteString.Lazy as LBS
17- import qualified Data.ByteString.Lazy.Char8 as LB8
1816import qualified Data.HashMap.Strict as H
1917import qualified Data.Text as T
2018import qualified System.Process as P
@@ -38,21 +36,32 @@ runInTerminal1 :: [String] -> IO ()
3836runInTerminal1 flags = do
3937 withTestDAPServer " test/unit/T44" flags $ \ test_dir server -> do
4038
39+ let out_path = test_dir </> (" runInTerm" <.> " out" )
40+ err_path = test_dir </> (" runInTerm" <.> " err" )
41+
4142 withTestDAPServerClient True server $ do
4243
4344 ctx <- ask
44- (rit_in, rit_out, rit_err, rit_p, invocation ) <- liftIO $ snd <$>
45+ (rit_in, rit_p) <- liftIO $ snd <$>
4546 concurrently
4647 (runTestDAP (defaultHitBreakpoint test_dir 6 ) ctx)
4748 (flip runTestDAP ctx $
4849 handleRunInTerminal $ \ args -> do
4950 (ritEnv, ritArgs) <- liftIO $ wait args
5051 let invocation = T. unpack $ " /usr/bin/env " <> addRITEnv ritEnv <> " " <> T. unwords ritArgs
51- (Just rit_in, Just rit_out, Just rit_err, rit_p)
52+ -- Redirect the child's stdout/stderr to files so logs are
53+ -- persisted incrementally and survive test failures.
54+ out_h <- liftIO $ openFile out_path WriteMode
55+ err_h <- liftIO $ openFile err_path WriteMode
56+ liftIO $ hPutStrLn out_h (" Invocation: " ++ invocation)
57+ liftIO $ hPutStrLn err_h (" Invocation: " ++ invocation)
58+ liftIO $ hFlush out_h
59+ liftIO $ hFlush err_h
60+ (Just rit_in, Nothing , Nothing , rit_p)
5261 <- liftIO $ P. createProcess (P. shell invocation)
53- {P. cwd = Just test_dir, P. std_in = P. CreatePipe , P. std_out = P. CreatePipe , P. std_err = P. CreatePipe }
62+ {P. cwd = Just test_dir, P. std_in = P. CreatePipe , P. std_out = P. UseHandle out_h , P. std_err = P. UseHandle err_h }
5463 Just rit_pid <- liftIO $ P. getPid rit_p
55- pure ((rit_in, rit_out, rit_err, rit_p, invocation ), fromIntegral rit_pid))
64+ pure ((rit_in, rit_p), fromIntegral rit_pid))
5665
5766 -- Continue from "getLine" which will block waiting for input
5867 next
@@ -73,17 +82,11 @@ runInTerminal1 flags = do
7382 disconnect
7483
7584 liftIO $ do
76- -- The contents of the rit_output should contain "hello" plus printing of what we wrote
77- out <- LBS. hGetContents rit_out
78- let out_str = LB8. unpack out
79-
80- -- Disconnect should be handled cleanly (#268)
81- err <- LBS. hGetContents rit_err
82- let err_str = LB8. unpack err
83-
84- -- Write stdout and stderr to file.
85- writeFile (test_dir </> (" runInTerm" <.> " out" )) (invocation ++ " \n " ++ out_str)
86- writeFile (test_dir </> (" runInTerm" <.> " err" )) (invocation ++ " \n " ++ err_str)
85+ -- Wait for the child to exit so all buffered output lands on disk,
86+ -- then read back the logs that were streamed to the files.
87+ _ <- P. waitForProcess rit_p
88+ out_str <- readFile out_path
89+ err_str <- readFile err_path
8790
8891 assertBool
8992 (" Expected output to contain 'hello', got: " ++ out_str)
0 commit comments