Skip to content

Commit 88f0931

Browse files
committed
Check for top existence.
1 parent a4f0744 commit 88f0931

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

rules_haskell_tests/tests/RunTests.hs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,25 @@ printMemoryHook action = do
194194
action
195195
_ -> action
196196

197+
topPath :: String
198+
topPath = "/usr/bin/top"
199+
197200
-- | Print information about the current memory state to debug intermittent failures
198201
-- Related to https://github.com/tweag/rules_haskell/issues/2089
199202
printMemory :: String -> IO ()
200203
printMemory msg = do
204+
-- Do not attempt to run top, if it does not exist.
205+
(exitCode, _, _) <- Process.readProcessWithExitCode "test" [topPath] ""
206+
case exitCode of
207+
ExitSuccess -> _doPrintMemory msg
208+
ExitFailure _ -> pure ()
209+
210+
-- | Print information about the current memory state to debug intermittent failures
211+
-- Related to https://github.com/tweag/rules_haskell/issues/2089
212+
_doPrintMemory :: String -> IO ()
213+
_doPrintMemory msg = do
201214
putStrLn msg
202-
(exitCode, stdOut, stdErr) <- Process.readProcessWithExitCode "/usr/bin/top" ["-l", "1", "-s", "0", "-o", "mem", "-n", "15"] ""
215+
(exitCode, stdOut, stdErr) <- Process.readProcessWithExitCode topPath ["-l", "1", "-s", "0", "-o", "mem", "-n", "15"] ""
203216
case exitCode of
204217
ExitSuccess -> putStrLn stdOut
205218
ExitFailure _ -> putStrLn ("=== printMemory failed ===\n" ++ stdErr)

0 commit comments

Comments
 (0)