@@ -27,12 +27,13 @@ import Distribution.TestSuite
27
27
import Distribution.Pretty
28
28
import Distribution.Verbosity
29
29
30
- import Control.Concurrent (forkIO )
31
30
import System.Directory
32
31
( createDirectoryIfMissing , doesDirectoryExist , doesFileExist
33
32
, getCurrentDirectory , removeDirectoryRecursive )
34
33
import System.FilePath ( (</>) , (<.>) )
35
- import System.IO ( hGetContents , stdout , stderr )
34
+ import System.IO ( stdout , stderr )
35
+
36
+ import qualified Data.ByteString.Lazy as LBS
36
37
37
38
runTest :: PD. PackageDescription
38
39
-> LBI. LocalBuildInfo
@@ -66,20 +67,6 @@ runTest pkg_descr lbi clbi flags suite = do
66
67
-- Write summary notices indicating start of test suite
67
68
notice verbosity $ summarizeSuiteStart $ testName'
68
69
69
- (wOut, wErr, logText) <- case details of
70
- Direct -> return (stdout, stderr, " " )
71
- _ -> do
72
- (rOut, wOut) <- createPipe
73
-
74
- -- Read test executable's output lazily (returns immediately)
75
- logText <- hGetContents rOut
76
- -- Force the IO manager to drain the test output pipe
77
- void $ forkIO $ length logText `seq` return ()
78
-
79
- -- '--show-details=streaming': print the log output in another thread
80
- when (details == Streaming ) $ void $ forkIO $ putStr logText
81
-
82
- return (wOut, wOut, logText)
83
70
84
71
-- Run the test executable
85
72
let opts = map (testOption pkg_descr lbi suite)
@@ -97,14 +84,34 @@ runTest pkg_descr lbi clbi flags suite = do
97
84
return (addLibraryPath os paths shellEnv)
98
85
else return shellEnv
99
86
100
- exit <- case testWrapper flags of
101
- Flag path -> rawSystemIOWithEnv verbosity path (cmd: opts) Nothing (Just shellEnv')
102
- -- these handles are automatically closed
103
- Nothing (Just wOut) (Just wErr)
87
+ -- Output logger
88
+ (wOut, wErr, getLogText) <- case details of
89
+ Direct -> return (stdout, stderr, return LBS. empty)
90
+ _ -> do
91
+ (rOut, wOut) <- createPipe
92
+
93
+ return $ (,,) wOut wOut $ do
94
+ -- Read test executables' output
95
+ logText <- LBS. hGetContents rOut
96
+
97
+ -- '--show-details=streaming': print the log output in another thread
98
+ when (details == Streaming ) $ LBS. putStr logText
99
+
100
+ -- drain the output.
101
+ evaluate (force logText)
102
+
103
+ (exit, logText) <- case testWrapper flags of
104
+ Flag path -> rawSystemIOWithEnvAndAction
105
+ verbosity path (cmd: opts) Nothing (Just shellEnv')
106
+ getLogText
107
+ -- these handles are automatically closed
108
+ Nothing (Just wOut) (Just wErr)
104
109
105
- NoFlag -> rawSystemIOWithEnv verbosity cmd opts Nothing (Just shellEnv')
106
- -- these handles are automatically closed
107
- Nothing (Just wOut) (Just wErr)
110
+ NoFlag -> rawSystemIOWithEnvAndAction
111
+ verbosity cmd opts Nothing (Just shellEnv')
112
+ getLogText
113
+ -- these handles are automatically closed
114
+ Nothing (Just wOut) (Just wErr)
108
115
109
116
-- Generate TestSuiteLog from executable exit code and a machine-
110
117
-- readable test log.
@@ -115,7 +122,7 @@ runTest pkg_descr lbi clbi flags suite = do
115
122
116
123
-- Append contents of temporary log file to the final human-
117
124
-- readable log file
118
- appendFile (logFile suiteLog) logText
125
+ LBS. appendFile (logFile suiteLog) logText
119
126
120
127
-- Write end-of-suite summary notice to log file
121
128
appendFile (logFile suiteLog) $ summarizeSuiteFinish suiteLog
@@ -127,7 +134,9 @@ runTest pkg_descr lbi clbi flags suite = do
127
134
details == Failures && not (suitePassed $ testLogs suiteLog))
128
135
-- verbosity overrides show-details
129
136
&& verbosity >= normal
130
- whenPrinting $ putStr $ unlines $ lines logText
137
+ whenPrinting $ do
138
+ LBS. putStr logText
139
+ putChar ' \n '
131
140
132
141
-- Write summary notice to terminal indicating end of test suite
133
142
notice verbosity $ summarizeSuiteFinish suiteLog
0 commit comments