Skip to content

Commit 18e99cd

Browse files
committed
silenceStdErr to honor LSP_TEST_LOG_STDERR
1 parent c3ce8a4 commit 18e99cd

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

hls-test-utils/src/Test/Hls.hs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import Language.LSP.Types hiding
5959
import Language.LSP.Types.Capabilities (ClientCapabilities)
6060
import System.Directory (getCurrentDirectory,
6161
setCurrentDirectory)
62+
import System.Environment.Blank (getEnvDefault)
6263
import System.FilePath
6364
import System.IO.Extra
6465
import System.IO.Unsafe (unsafePerformIO)
@@ -133,15 +134,19 @@ runSessionWithServerFormatter plugin formatter =
133134

134135
-- | Run an action, with stderr silenced
135136
silenceStderr :: IO a -> IO a
136-
silenceStderr action = withTempFile $ \temp ->
137-
bracket (openFile temp ReadWriteMode) hClose $ \h -> do
138-
old <- hDuplicate stderr
139-
buf <- hGetBuffering stderr
140-
h `hDuplicateTo'` stderr
141-
action `finally` do
142-
old `hDuplicateTo'` stderr
143-
hSetBuffering stderr buf
144-
hClose old
137+
silenceStderr action = do
138+
showStderr <- getEnvDefault "LSP_TEST_LOG_STDERR" "0"
139+
case showStderr of
140+
"0" -> withTempFile $ \temp ->
141+
bracket (openFile temp ReadWriteMode) hClose $ \h -> do
142+
old <- hDuplicate stderr
143+
buf <- hGetBuffering stderr
144+
h `hDuplicateTo'` stderr
145+
action `finally` do
146+
old `hDuplicateTo'` stderr
147+
hSetBuffering stderr buf
148+
hClose old
149+
_ -> action
145150

146151
-- | Restore cwd after running an action
147152
keepCurrentDirectory :: IO a -> IO a

0 commit comments

Comments
 (0)