@@ -19,7 +19,7 @@ module Test.Hls
19
19
where
20
20
21
21
import Control.Applicative.Combinators
22
- import Control.Concurrent.Async (withAsync )
22
+ import Control.Concurrent.Async (async , wait )
23
23
import Control.Exception.Base
24
24
import Control.Monad.IO.Class
25
25
import Data.ByteString.Lazy (ByteString )
@@ -53,7 +53,7 @@ import Test.Tasty.Runners
53
53
54
54
-- | Run 'defaultMainWithRerun' with -j1, and silence stderr
55
55
defaultTestRunner :: TestTree -> IO ()
56
- defaultTestRunner = muteStderr . defaultMainWithRerun . adjustOption (const $ NumThreads 1 )
56
+ defaultTestRunner = silenceStderr . defaultMainWithRerun . adjustOption (const $ NumThreads 1 )
57
57
58
58
gitDiff :: FilePath -> FilePath -> [String ]
59
59
gitDiff fRef fNew = [" git" , " diff" , " --no-index" , " --text" , " --exit-code" , fRef, fNew]
@@ -72,13 +72,15 @@ runSessionWithServerFormatter plugin formatter =
72
72
def
73
73
fullCaps
74
74
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
79
79
old <- hDuplicate stderr
80
80
h `hDuplicateTo'` stderr
81
81
bracket_ action (hClose old) (old `hDuplicateTo'` stderr)
82
+ where
83
+ nullFile = if hostOS == Windows then " NUL" else " /dev/null"
82
84
83
85
-- | Host a server, and run a test session on it
84
86
-- Note: cwd will be shifted into @root@ in @Session a@
@@ -98,19 +100,22 @@ runSessionWithServer' plugin conf sconf caps root s = do
98
100
(outR, outW) <- createPipe
99
101
-- restore cwd after running the session; otherwise the path to test data will be invalid
100
102
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 <-
113
117
runSessionWithHandles inW outR sconf caps root s
114
118
`finally` setCurrentDirectory cwd
119
+ wait server
115
120
sleep 0.5
116
121
pure x
0 commit comments