@@ -41,7 +41,8 @@ import System.Directory
41
41
, setCurrentDirectory )
42
42
import System.FilePath ( (</>) , (<.>) )
43
43
import System.IO ( hClose , hPutStr )
44
- import System.Process (StdStream (.. ), createPipe , waitForProcess )
44
+ import Distribution.Compat.Process (proc )
45
+ import qualified System.Process as Process
45
46
46
47
runTest :: PD. PackageDescription
47
48
-> LBI. LocalBuildInfo
@@ -78,49 +79,48 @@ runTest pkg_descr lbi clbi flags suite = do
78
79
79
80
suiteLog <- CE. bracket openCabalTemp deleteIfExists $ \ tempLog -> do
80
81
82
+ -- Run test executable
83
+ let opts = map (testOption pkg_descr lbi suite) $ testOptions flags
84
+ dataDirPath = pwd </> PD. dataDir pkg_descr
85
+ tixFile = pwd </> tixFilePath distPref way testName'
86
+ pkgPathEnv = (pkgPathEnvVar pkg_descr " datadir" , dataDirPath)
87
+ : existingEnv
88
+ shellEnv = [(" HPCTIXFILE" , tixFile) | isCoverageEnabled]
89
+ ++ pkgPathEnv
90
+ -- Add (DY)LD_LIBRARY_PATH if needed
91
+ shellEnv' <-
92
+ if LBI. withDynExe lbi
93
+ then do
94
+ let (Platform _ os) = LBI. hostPlatform lbi
95
+ paths <- LBI. depLibraryPaths True False lbi clbi
96
+ cpath <- canonicalizePath $ LBI. componentBuildDir lbi clbi
97
+ return (addLibraryPath os (cpath : paths) shellEnv)
98
+ else return shellEnv
99
+ let (cmd', opts') = case testWrapper flags of
100
+ Flag path -> (path, cmd: opts)
101
+ NoFlag -> (cmd, opts)
102
+
81
103
-- TODO: this setup is broken,
82
104
-- if the test output is too big, we will deadlock.
83
- (rOut, wOut) <- createPipe
84
-
85
- -- Run test executable
86
- (Just wIn, _, _, process) <- do
87
- let opts = map (testOption pkg_descr lbi suite) $ testOptions flags
88
- dataDirPath = pwd </> PD. dataDir pkg_descr
89
- tixFile = pwd </> tixFilePath distPref way testName'
90
- pkgPathEnv = (pkgPathEnvVar pkg_descr " datadir" , dataDirPath)
91
- : existingEnv
92
- shellEnv = [(" HPCTIXFILE" , tixFile) | isCoverageEnabled]
93
- ++ pkgPathEnv
94
- -- Add (DY)LD_LIBRARY_PATH if needed
95
- shellEnv' <-
96
- if LBI. withDynExe lbi
97
- then do
98
- let (Platform _ os) = LBI. hostPlatform lbi
99
- paths <- LBI. depLibraryPaths True False lbi clbi
100
- cpath <- canonicalizePath $ LBI. componentBuildDir lbi clbi
101
- return (addLibraryPath os (cpath : paths) shellEnv)
102
- else return shellEnv
103
- case testWrapper flags of
104
- Flag path -> createProcessWithEnv verbosity path (cmd: opts) Nothing (Just shellEnv')
105
- -- these handles are closed automatically
106
- CreatePipe (UseHandle wOut) (UseHandle wOut)
107
-
108
- NoFlag -> createProcessWithEnv verbosity cmd opts Nothing (Just shellEnv')
109
- -- these handles are closed automatically
110
- CreatePipe (UseHandle wOut) (UseHandle wOut)
111
-
112
- hPutStr wIn $ show (tempLog, PD. testName suite)
113
- hClose wIn
114
-
115
- -- Append contents of temporary log file to the final human-
116
- -- readable log file
117
- logText <- LBS. hGetContents rOut
118
- -- Force the IO manager to drain the test output pipe
119
- _ <- evaluate (force logText)
120
-
121
- exitcode <- waitForProcess process
122
- unless (exitcode == ExitSuccess ) $ do
123
- debug verbosity $ cmd ++ " returned " ++ show exitcode
105
+ (rOut, wOut) <- Process. createPipe
106
+ (exitcode, logText) <- rawSystemProcAction verbosity
107
+ (proc cmd' opts') { Process. env = Just shellEnv'
108
+ , Process. std_in = Process. CreatePipe
109
+ , Process. std_out = Process. UseHandle wOut
110
+ , Process. std_err = Process. UseHandle wOut
111
+ } $ \ mIn _ _ -> do
112
+ let wIn = fromCreatePipe mIn
113
+ hPutStr wIn $ show (tempLog, PD. testName suite)
114
+ hClose wIn
115
+
116
+ -- Append contents of temporary log file to the final human-
117
+ -- readable log file
118
+ logText <- LBS. hGetContents rOut
119
+ -- Force the IO manager to drain the test output pipe
120
+ _ <- evaluate (force logText)
121
+ return logText
122
+ unless (exitcode == ExitSuccess ) $
123
+ debug verbosity $ cmd ++ " returned " ++ show exitcode
124
124
125
125
-- Generate final log file name
126
126
let finalLogName l = testLogDir
0 commit comments