@@ -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 )
@@ -49,11 +49,10 @@ import Test.Tasty.ExpectedFailure
49
49
import Test.Tasty.Golden
50
50
import Test.Tasty.HUnit
51
51
import Test.Tasty.Ingredients.Rerun
52
- import Test.Tasty.Runners
53
52
54
- -- | Run 'defaultMainWithRerun' with -j1 , and silence stderr
53
+ -- | Run 'defaultMainWithRerun', and silence stderr
55
54
defaultTestRunner :: TestTree -> IO ()
56
- defaultTestRunner = muteStderr . defaultMainWithRerun . adjustOption ( const $ NumThreads 1 )
55
+ defaultTestRunner = silenceStderr . defaultMainWithRerun
57
56
58
57
gitDiff :: FilePath -> FilePath -> [String ]
59
58
gitDiff fRef fNew = [" git" , " diff" , " --no-index" , " --text" , " --exit-code" , fRef, fNew]
@@ -72,13 +71,17 @@ runSessionWithServerFormatter plugin formatter =
72
71
def
73
72
fullCaps
74
73
75
- -- | Silence stderr, running an action
76
- muteStderr :: IO () -> IO ()
77
- muteStderr action = withTempFile $ \ tmp ->
78
- bracket (openFile tmp AppendMode ) hClose $ \ h -> do
74
+ -- | Run an action, with stderr silenced
75
+ silenceStderr :: IO () -> IO ()
76
+ silenceStderr action = withTempFile $ \ temp ->
77
+ bracket (openFile temp ReadWriteMode ) hClose $ \ h -> do
79
78
old <- hDuplicate stderr
79
+ buf <- hGetBuffering stderr
80
80
h `hDuplicateTo'` stderr
81
- bracket_ action (hClose old) (old `hDuplicateTo'` stderr)
81
+ bracket_
82
+ action
83
+ (hClose old)
84
+ (old `hDuplicateTo'` stderr >> hSetBuffering stderr buf)
82
85
83
86
-- | Host a server, and run a test session on it
84
87
-- Note: cwd will be shifted into @root@ in @Session a@
@@ -98,19 +101,22 @@ runSessionWithServer' plugin conf sconf caps root s = do
98
101
(outR, outW) <- createPipe
99
102
-- restore cwd after running the session; otherwise the path to test data will be invalid
100
103
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 $ \ _ ->
104
+ server <-
105
+ async $
106
+ Ghcide. defaultMain
107
+ def
108
+ { argsHandleIn = pure inR,
109
+ argsHandleOut = pure outW,
110
+ argsDefaultHlsConfig = conf,
111
+ argsIdeOptions = \ config sessionLoader ->
112
+ let ideOptions = (argsIdeOptions def config sessionLoader) {optTesting = IdeTesting True }
113
+ in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2 }},
114
+ argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide. descriptors
115
+ }
116
+
117
+ x <-
113
118
runSessionWithHandles inW outR sconf caps root s
114
119
`finally` setCurrentDirectory cwd
120
+ wait server
115
121
sleep 0.5
116
122
pure x
0 commit comments