Skip to content

Commit 91364e1

Browse files
committed
Don't use withAsync
1 parent 09ad056 commit 91364e1

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Test.Hls
1919
where
2020

2121
import Control.Applicative.Combinators
22-
import Control.Concurrent.Async (withAsync)
22+
import Control.Concurrent.Async (async, wait)
2323
import Control.Exception.Base
2424
import Control.Monad.IO.Class
2525
import Data.ByteString.Lazy (ByteString)
@@ -53,7 +53,7 @@ import Test.Tasty.Runners
5353

5454
-- | Run 'defaultMainWithRerun' with -j1, and silence stderr
5555
defaultTestRunner :: TestTree -> IO ()
56-
defaultTestRunner = muteStderr . defaultMainWithRerun . adjustOption (const $ NumThreads 1)
56+
defaultTestRunner = silenceStderr . defaultMainWithRerun . adjustOption (const $ NumThreads 1)
5757

5858
gitDiff :: FilePath -> FilePath -> [String]
5959
gitDiff fRef fNew = ["git", "diff", "--no-index", "--text", "--exit-code", fRef, fNew]
@@ -72,13 +72,15 @@ runSessionWithServerFormatter plugin formatter =
7272
def
7373
fullCaps
7474

75-
-- | Silence stderr, running an action
76-
muteStderr :: IO () -> IO ()
77-
muteStderr action = withTempFile $ \tmp ->
78-
bracket (openFile tmp AppendMode) hClose $ \h -> do
75+
-- | Run an action, with stderr silenced
76+
silenceStderr :: IO () -> IO ()
77+
silenceStderr action =
78+
bracket (openFile nullFile AppendMode) hClose $ \h -> do
7979
old <- hDuplicate stderr
8080
h `hDuplicateTo'` stderr
8181
bracket_ action (hClose old) (old `hDuplicateTo'` stderr)
82+
where
83+
nullFile = if hostOS == Windows then "NUL" else "/dev/null"
8284

8385
-- | Host a server, and run a test session on it
8486
-- Note: cwd will be shifted into @root@ in @Session a@
@@ -98,19 +100,22 @@ runSessionWithServer' plugin conf sconf caps root s = do
98100
(outR, outW) <- createPipe
99101
-- restore cwd after running the session; otherwise the path to test data will be invalid
100102
cwd <- getCurrentDirectory
101-
let server =
102-
Ghcide.defaultMain
103-
def
104-
{ argsHandleIn = pure inR,
105-
argsHandleOut = pure outW,
106-
argsDefaultHlsConfig = conf,
107-
argsIdeOptions = \config sessionLoader ->
108-
let ideOptions = (argsIdeOptions def config sessionLoader) {optTesting = IdeTesting True}
109-
in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2}},
110-
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide.descriptors
111-
}
112-
x <- withAsync server $ \_ ->
103+
server <-
104+
async $
105+
Ghcide.defaultMain
106+
def
107+
{ argsHandleIn = pure inR,
108+
argsHandleOut = pure outW,
109+
argsDefaultHlsConfig = conf,
110+
argsIdeOptions = \config sessionLoader ->
111+
let ideOptions = (argsIdeOptions def config sessionLoader) {optTesting = IdeTesting True}
112+
in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2}},
113+
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide.descriptors
114+
}
115+
116+
x <-
113117
runSessionWithHandles inW outR sconf caps root s
114118
`finally` setCurrentDirectory cwd
119+
wait server
115120
sleep 0.5
116121
pure x

0 commit comments

Comments
 (0)