@@ -20,17 +20,26 @@ module Test.Hls
20
20
defaultTestRunner ,
21
21
goldenGitDiff ,
22
22
goldenWithHaskellDoc ,
23
+ goldenWithHaskellDocInTmpDir ,
23
24
goldenWithHaskellAndCaps ,
25
+ goldenWithHaskellAndCapsInTmpDir ,
24
26
goldenWithCabalDoc ,
25
27
goldenWithHaskellDocFormatter ,
28
+ goldenWithHaskellDocFormatterInTmpDir ,
26
29
goldenWithCabalDocFormatter ,
30
+ goldenWithCabalDocFormatterInTmpDir ,
27
31
def ,
28
32
-- * Running HLS for integration tests
29
33
runSessionWithServer ,
30
34
runSessionWithServerAndCaps ,
31
35
runSessionWithServerFormatter ,
32
36
runSessionWithCabalServerFormatter ,
37
+ runSessionWithServerInTmpDir ,
38
+ runSessionWithServerAndCapsInTmpDir ,
39
+ runSessionWithServerFormatterInTmpDir ,
40
+ runSessionWithCabalServerFormatterInTmpDir ,
33
41
runSessionWithServer' ,
42
+ runSessionWithServerInTmpDir' ,
34
43
-- * Helpful re-exports
35
44
PluginDescriptor ,
36
45
IdeState ,
@@ -105,9 +114,12 @@ import System.Directory (getCurrentDirectory,
105
114
setCurrentDirectory )
106
115
import System.Environment (lookupEnv )
107
116
import System.FilePath
117
+ import System.IO.Extra (withTempDir )
108
118
import System.IO.Unsafe (unsafePerformIO )
109
119
import System.Process.Extra (createPipe )
110
120
import System.Time.Extra
121
+ import qualified Test.Hls.FileSystem as FS
122
+ import Test.Hls.FileSystem
111
123
import Test.Hls.Util
112
124
import Test.Tasty hiding (Timeout )
113
125
import Test.Tasty.ExpectedFailure
@@ -144,6 +156,18 @@ goldenWithHaskellDoc
144
156
-> TestTree
145
157
goldenWithHaskellDoc = goldenWithDoc " haskell"
146
158
159
+ goldenWithHaskellDocInTmpDir
160
+ :: Pretty b
161
+ => PluginTestDescriptor b
162
+ -> TestName
163
+ -> VirtualFileTree
164
+ -> FilePath
165
+ -> FilePath
166
+ -> FilePath
167
+ -> (TextDocumentIdentifier -> Session () )
168
+ -> TestTree
169
+ goldenWithHaskellDocInTmpDir = goldenWithDocInTmpDir " haskell"
170
+
147
171
goldenWithHaskellAndCaps
148
172
:: Pretty b
149
173
=> ClientCapabilities
@@ -165,6 +189,27 @@ goldenWithHaskellAndCaps clientCaps plugin title testDataDir path desc ext act =
165
189
act doc
166
190
documentContents doc
167
191
192
+ goldenWithHaskellAndCapsInTmpDir
193
+ :: Pretty b
194
+ => ClientCapabilities
195
+ -> PluginTestDescriptor b
196
+ -> TestName
197
+ -> VirtualFileTree
198
+ -> FilePath
199
+ -> FilePath
200
+ -> FilePath
201
+ -> (TextDocumentIdentifier -> Session () )
202
+ -> TestTree
203
+ goldenWithHaskellAndCapsInTmpDir clientCaps plugin title tree path desc ext act =
204
+ goldenGitDiff title (vftTestDataRoot tree </> path <.> desc <.> ext)
205
+ $ runSessionWithServerAndCapsInTmpDir plugin clientCaps tree
206
+ $ TL. encodeUtf8 . TL. fromStrict
207
+ <$> do
208
+ doc <- openDoc (path <.> ext) " haskell"
209
+ void waitForBuildQueue
210
+ act doc
211
+ documentContents doc
212
+
168
213
goldenWithCabalDoc
169
214
:: Pretty b
170
215
=> PluginTestDescriptor b
@@ -198,6 +243,27 @@ goldenWithDoc fileType plugin title testDataDir path desc ext act =
198
243
act doc
199
244
documentContents doc
200
245
246
+ goldenWithDocInTmpDir
247
+ :: Pretty b
248
+ => T. Text
249
+ -> PluginTestDescriptor b
250
+ -> TestName
251
+ -> VirtualFileTree
252
+ -> FilePath
253
+ -> FilePath
254
+ -> FilePath
255
+ -> (TextDocumentIdentifier -> Session () )
256
+ -> TestTree
257
+ goldenWithDocInTmpDir fileType plugin title tree path desc ext act =
258
+ goldenGitDiff title (vftTestDataRoot tree </> path <.> desc <.> ext)
259
+ $ runSessionWithServerInTmpDir plugin tree
260
+ $ TL. encodeUtf8 . TL. fromStrict
261
+ <$> do
262
+ doc <- openDoc (path <.> ext) fileType
263
+ void waitForBuildQueue
264
+ act doc
265
+ documentContents doc
266
+
201
267
-- ------------------------------------------------------------
202
268
-- Helper function for initialising plugins under test
203
269
-- ------------------------------------------------------------
@@ -308,6 +374,51 @@ runSessionWithServerFormatter plugin formatter conf fp act = do
308
374
fp
309
375
act
310
376
377
+ runSessionWithServerInTmpDir :: Pretty b => PluginTestDescriptor b -> VirtualFileTree -> Session a -> IO a
378
+ runSessionWithServerInTmpDir plugin tree act = do
379
+ recorder <- pluginTestRecorder
380
+ runSessionWithServerInTmpDir' (plugin recorder) def def fullCaps tree act
381
+
382
+ runSessionWithServerAndCapsInTmpDir :: Pretty b => PluginTestDescriptor b -> ClientCapabilities -> VirtualFileTree -> Session a -> IO a
383
+ runSessionWithServerAndCapsInTmpDir plugin caps tree act = do
384
+ recorder <- pluginTestRecorder
385
+ runSessionWithServerInTmpDir' (plugin recorder) def def caps tree act
386
+
387
+ runSessionWithServerFormatterInTmpDir :: Pretty b => PluginTestDescriptor b -> String -> PluginConfig -> VirtualFileTree -> Session a -> IO a
388
+ runSessionWithServerFormatterInTmpDir plugin formatter conf tree act = do
389
+ recorder <- pluginTestRecorder
390
+ runSessionWithServerInTmpDir'
391
+ (plugin recorder)
392
+ def
393
+ { formattingProvider = T. pack formatter
394
+ , plugins = M. singleton (PluginId $ T. pack formatter) conf
395
+ }
396
+ def
397
+ fullCaps
398
+ tree
399
+ act
400
+
401
+ -- | Host a server, and run a test session on it
402
+ -- Note: cwd will be shifted into a temporary directory in @Session a@
403
+ runSessionWithServerInTmpDir' ::
404
+ -- | Plugins to load on the server.
405
+ --
406
+ -- For improved logging, make sure these plugins have been initalised with
407
+ -- the recorder produced by @pluginTestRecorder@.
408
+ IdePlugins IdeState ->
409
+ -- | lsp config for the server
410
+ Config ->
411
+ -- | config for the test session
412
+ SessionConfig ->
413
+ ClientCapabilities ->
414
+ VirtualFileTree ->
415
+ Session a ->
416
+ IO a
417
+ runSessionWithServerInTmpDir' plugins conf sessConf caps tree act = withLock lock2 $ do
418
+ withTempDir $ \ tmpDir -> do
419
+ _fs <- FS. materialiseVFT tmpDir tree
420
+ runSessionWithServer' plugins conf sessConf caps tmpDir act
421
+
311
422
goldenWithHaskellDocFormatter
312
423
:: Pretty b
313
424
=> PluginTestDescriptor b -- ^ Formatter plugin to be used
@@ -352,6 +463,50 @@ goldenWithCabalDocFormatter plugin formatter conf title testDataDir path desc ex
352
463
act doc
353
464
documentContents doc
354
465
466
+ goldenWithHaskellDocFormatterInTmpDir
467
+ :: Pretty b
468
+ => PluginTestDescriptor b -- ^ Formatter plugin to be used
469
+ -> String -- ^ Name of the formatter to be used
470
+ -> PluginConfig
471
+ -> TestName -- ^ Title of the test
472
+ -> VirtualFileTree -- ^ Virtual representation of the test project
473
+ -> FilePath -- ^ Path to the testdata to be used within the directory
474
+ -> FilePath -- ^ Additional suffix to be appended to the output file
475
+ -> FilePath -- ^ Extension of the output file
476
+ -> (TextDocumentIdentifier -> Session () )
477
+ -> TestTree
478
+ goldenWithHaskellDocFormatterInTmpDir plugin formatter conf title tree path desc ext act =
479
+ goldenGitDiff title (vftTestDataRoot tree </> path <.> desc <.> ext)
480
+ $ runSessionWithServerFormatterInTmpDir plugin formatter conf tree
481
+ $ TL. encodeUtf8 . TL. fromStrict
482
+ <$> do
483
+ doc <- openDoc (path <.> ext) " haskell"
484
+ void waitForBuildQueue
485
+ act doc
486
+ documentContents doc
487
+
488
+ goldenWithCabalDocFormatterInTmpDir
489
+ :: Pretty b
490
+ => PluginTestDescriptor b -- ^ Formatter plugin to be used
491
+ -> String -- ^ Name of the formatter to be used
492
+ -> PluginConfig
493
+ -> TestName -- ^ Title of the test
494
+ -> VirtualFileTree -- ^ Virtual representation of the test project
495
+ -> FilePath -- ^ Path to the testdata to be used within the directory
496
+ -> FilePath -- ^ Additional suffix to be appended to the output file
497
+ -> FilePath -- ^ Extension of the output file
498
+ -> (TextDocumentIdentifier -> Session () )
499
+ -> TestTree
500
+ goldenWithCabalDocFormatterInTmpDir plugin formatter conf title tree path desc ext act =
501
+ goldenGitDiff title (vftTestDataRoot tree </> path <.> desc <.> ext)
502
+ $ runSessionWithCabalServerFormatterInTmpDir plugin formatter conf tree
503
+ $ TL. encodeUtf8 . TL. fromStrict
504
+ <$> do
505
+ doc <- openDoc (path <.> ext) " cabal"
506
+ void waitForBuildQueue
507
+ act doc
508
+ documentContents doc
509
+
355
510
runSessionWithCabalServerFormatter :: Pretty b => PluginTestDescriptor b -> String -> PluginConfig -> FilePath -> Session a -> IO a
356
511
runSessionWithCabalServerFormatter plugin formatter conf fp act = do
357
512
recorder <- pluginTestRecorder
@@ -363,7 +518,22 @@ runSessionWithCabalServerFormatter plugin formatter conf fp act = do
363
518
}
364
519
def
365
520
fullCaps
366
- fp act
521
+ fp
522
+ act
523
+
524
+ runSessionWithCabalServerFormatterInTmpDir :: Pretty b => PluginTestDescriptor b -> String -> PluginConfig -> VirtualFileTree -> Session a -> IO a
525
+ runSessionWithCabalServerFormatterInTmpDir plugin formatter conf tree act = do
526
+ recorder <- pluginTestRecorder
527
+ runSessionWithServerInTmpDir'
528
+ (plugin recorder)
529
+ def
530
+ { cabalFormattingProvider = T. pack formatter
531
+ , plugins = M. singleton (PluginId $ T. pack formatter) conf
532
+ }
533
+ def
534
+ fullCaps
535
+ tree
536
+ act
367
537
368
538
-- | Restore cwd after running an action
369
539
keepCurrentDirectory :: IO a -> IO a
@@ -374,6 +544,12 @@ keepCurrentDirectory = bracket getCurrentDirectory setCurrentDirectory . const
374
544
lock :: Lock
375
545
lock = unsafePerformIO newLock
376
546
547
+
548
+ {-# NOINLINE lock2 #-}
549
+ -- | Never run in parallel
550
+ lock2 :: Lock
551
+ lock2 = unsafePerformIO newLock
552
+
377
553
-- | Host a server, and run a test session on it
378
554
-- Note: cwd will be shifted into @root@ in @Session a@
379
555
runSessionWithServer' ::
@@ -390,7 +566,7 @@ runSessionWithServer' ::
390
566
FilePath ->
391
567
Session a ->
392
568
IO a
393
- runSessionWithServer' plugins conf sconf caps root s = withLock lock $ keepCurrentDirectory $ do
569
+ runSessionWithServer' plugins conf sconf caps root s = withLock lock $ keepCurrentDirectory $ do
394
570
(inR, inW) <- createPipe
395
571
(outR, outW) <- createPipe
396
572
0 commit comments