@@ -29,6 +29,7 @@ module Test.Hls
29
29
-- * Running HLS for integration tests
30
30
runSessionWithServer ,
31
31
runSessionWithServerAndCaps ,
32
+ TestRunner ,
32
33
runSessionWithServerInTmpDir ,
33
34
runSessionWithServerAndCapsInTmpDir ,
34
35
runSessionWithServer' ,
@@ -368,6 +369,86 @@ initialiseTestRecorder envVars = do
368
369
-- ------------------------------------------------------------
369
370
-- Run an HLS server testing a specific plugin
370
371
-- ------------------------------------------------------------
372
+ class TestRunner cont res where
373
+ runSessionWithServerInTmpDir :: Pretty b => Config -> PluginTestDescriptor b -> VirtualFileTree -> cont -> IO res
374
+ runSessionWithServerInTmpDir config plugin tree act = do
375
+ recorder <- pluginTestRecorder
376
+ runSessionWithServerInTmpDir' (plugin recorder) config def fullCaps tree act
377
+ runSessionWithServerAndCapsInTmpDir :: Pretty b => Config -> PluginTestDescriptor b -> ClientCapabilities -> VirtualFileTree -> cont -> IO res
378
+ runSessionWithServerAndCapsInTmpDir config plugin caps tree act = do
379
+ recorder <- pluginTestRecorder
380
+ runSessionWithServerInTmpDir' (plugin recorder) config def caps tree act
381
+
382
+ -- | Host a server, and run a test session on it.
383
+ --
384
+ -- Creates a temporary directory, and materializes the VirtualFileTree
385
+ -- in the temporary directory.
386
+ --
387
+ -- To debug test cases and verify the file system is correctly set up,
388
+ -- you should set the environment variable 'HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP=1'.
389
+ -- Further, we log the temporary directory location on startup. To view
390
+ -- the logs, set the environment variable 'HLS_TEST_HARNESS_STDERR=1'.
391
+ --
392
+ -- Example invocation to debug test cases:
393
+ --
394
+ -- @
395
+ -- HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP=1 HLS_TEST_HARNESS_STDERR=1 cabal test <plugin-name>
396
+ -- @
397
+ --
398
+ -- Don't forget to use 'TASTY_PATTERN' to debug only a subset of tests.
399
+ --
400
+ -- For plugin test logs, look at the documentation of 'mkPluginTestDescriptor'.
401
+ --
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
+ cont -> IO res
416
+ runSessionWithServerInTmpDir' plugins conf sessConf caps tree act = withLock lockForTempDirs $ do
417
+ testRoot <- setupTestEnvironment
418
+ (recorder, _) <- initialiseTestRecorder
419
+ [" LSP_TEST_LOG_STDERR" , " HLS_TEST_HARNESS_STDERR" , " HLS_TEST_LOG_STDERR" ]
420
+
421
+ -- Do not clean up the temporary directory if this variable is set to anything but '0'.
422
+ -- Aids debugging.
423
+ cleanupTempDir <- lookupEnv " HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP"
424
+ let runTestInDir action = case cleanupTempDir of
425
+ Just val | val /= " 0" -> do
426
+ (tempDir, _) <- newTempDirWithin testRoot
427
+ a <- action tempDir
428
+ logWith recorder Debug LogNoCleanup
429
+ pure a
430
+
431
+ _ -> do
432
+ (tempDir, cleanup) <- newTempDirWithin testRoot
433
+ a <- action tempDir `finally` cleanup
434
+ logWith recorder Debug LogCleanup
435
+ pure a
436
+
437
+ runTestInDir $ \ tmpDir -> do
438
+ logWith recorder Info $ LogTestDir tmpDir
439
+ fs <- FS. materialiseVFT tmpDir tree
440
+ runSessionWithServer' plugins conf sessConf caps tmpDir (contToSessionRes fs act)
441
+ contToSessionRes :: FileSystem -> cont -> Session res
442
+
443
+
444
+ instance TestRunner (Session a ) a where
445
+ contToSessionRes _ act = act
446
+
447
+
448
+ instance TestRunner (FileSystem -> Session a ) a where
449
+ contToSessionRes fs act = act fs
450
+
451
+
371
452
372
453
runSessionWithServer :: Pretty b => Config -> PluginTestDescriptor b -> FilePath -> Session a -> IO a
373
454
runSessionWithServer config plugin fp act = do
@@ -379,77 +460,6 @@ runSessionWithServerAndCaps config plugin caps fp act = do
379
460
recorder <- pluginTestRecorder
380
461
runSessionWithServer' (plugin recorder) config def caps fp act
381
462
382
- runSessionWithServerInTmpDir :: Pretty b => Config -> PluginTestDescriptor b -> VirtualFileTree -> Session a -> IO a
383
- runSessionWithServerInTmpDir config plugin tree act = do
384
- recorder <- pluginTestRecorder
385
- runSessionWithServerInTmpDir' (plugin recorder) config def fullCaps tree act
386
-
387
- runSessionWithServerAndCapsInTmpDir :: Pretty b => Config -> PluginTestDescriptor b -> ClientCapabilities -> VirtualFileTree -> Session a -> IO a
388
- runSessionWithServerAndCapsInTmpDir config plugin caps tree act = do
389
- recorder <- pluginTestRecorder
390
- runSessionWithServerInTmpDir' (plugin recorder) config def caps tree act
391
-
392
- -- | Host a server, and run a test session on it.
393
- --
394
- -- Creates a temporary directory, and materializes the VirtualFileTree
395
- -- in the temporary directory.
396
- --
397
- -- To debug test cases and verify the file system is correctly set up,
398
- -- you should set the environment variable 'HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP=1'.
399
- -- Further, we log the temporary directory location on startup. To view
400
- -- the logs, set the environment variable 'HLS_TEST_HARNESS_STDERR=1'.
401
- --
402
- -- Example invocation to debug test cases:
403
- --
404
- -- @
405
- -- HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP=1 HLS_TEST_HARNESS_STDERR=1 cabal test <plugin-name>
406
- -- @
407
- --
408
- -- Don't forget to use 'TASTY_PATTERN' to debug only a subset of tests.
409
- --
410
- -- For plugin test logs, look at the documentation of 'mkPluginTestDescriptor'.
411
- --
412
- -- Note: cwd will be shifted into a temporary directory in @Session a@
413
- runSessionWithServerInTmpDir' ::
414
- -- | Plugins to load on the server.
415
- --
416
- -- For improved logging, make sure these plugins have been initalised with
417
- -- the recorder produced by @pluginTestRecorder@.
418
- IdePlugins IdeState ->
419
- -- | lsp config for the server
420
- Config ->
421
- -- | config for the test session
422
- SessionConfig ->
423
- ClientCapabilities ->
424
- VirtualFileTree ->
425
- Session a ->
426
- IO a
427
- runSessionWithServerInTmpDir' plugins conf sessConf caps tree act = withLock lockForTempDirs $ do
428
- testRoot <- setupTestEnvironment
429
- (recorder, _) <- initialiseTestRecorder
430
- [" LSP_TEST_LOG_STDERR" , " HLS_TEST_HARNESS_STDERR" , " HLS_TEST_LOG_STDERR" ]
431
-
432
- -- Do not clean up the temporary directory if this variable is set to anything but '0'.
433
- -- Aids debugging.
434
- cleanupTempDir <- lookupEnv " HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP"
435
- let runTestInDir action = case cleanupTempDir of
436
- Just val
437
- | val /= " 0" -> do
438
- (tempDir, _) <- newTempDirWithin testRoot
439
- a <- action tempDir
440
- logWith recorder Debug LogNoCleanup
441
- pure a
442
-
443
- _ -> do
444
- (tempDir, cleanup) <- newTempDirWithin testRoot
445
- a <- action tempDir `finally` cleanup
446
- logWith recorder Debug LogCleanup
447
- pure a
448
-
449
- runTestInDir $ \ tmpDir -> do
450
- logWith recorder Info $ LogTestDir tmpDir
451
- _fs <- FS. materialiseVFT tmpDir tree
452
- runSessionWithServer' plugins conf sessConf caps tmpDir act
453
463
454
464
-- | Setup the test environment for isolated tests.
455
465
--
0 commit comments