hls-test-utils-2.9.0.0: Utilities used in the tests of Haskell Language Server

Safe Haskell | None
Language | GHC2021

Test.Hls.Util

Contents

- Test Capabilities
- Environment specifications
- Extract code actions
- Session Assertion Helpers
- Temporary directories
- Extract positions from input file.

Synopsis

- codeActionResolveCaps :: ClientCapabilities
- codeActionNoResolveCaps :: ClientCapabilities
- codeActionSupportCaps :: ClientCapabilities
- expectCodeAction :: [Command |? CodeAction] -> [Text] -> IO ()
- ghcVersion :: GhcVersion
- data GhcVersion
  - = GHC92
  - | GHC94
  - | GHC96
  - | GHC98
  - | GHC910
- hostOS :: OS
- data OS
  - = Windows
  - | MacOS
  - | Linux
- matchesCurrentEnv :: EnvSpec -> Bool
- data EnvSpec
  - = HostOS OS
  - | GhcVer GhcVersion
- ignoreForGhcVersions :: [GhcVersion] -> String -> TestTree -> TestTree
- ignoreInEnv :: [EnvSpec] -> String -> TestTree -> TestTree
- onlyRunForGhcVersions :: [GhcVersion] -> String -> TestTree -> TestTree
- knownBrokenOnWindows :: String -> TestTree -> TestTree
- knownBrokenForGhcVersions :: [GhcVersion] -> String -> TestTree -> TestTree
- knownBrokenInEnv :: [EnvSpec] -> String -> TestTree -> TestTree
- knownBrokenInSpecificEnv :: [EnvSpec] -> String -> TestTree -> TestTree
- onlyWorkForGhcVersions :: (GhcVersion -> Bool) -> String -> TestTree -> TestTree
- fromAction :: (Command |? CodeAction) -> CodeAction
- fromCommand :: (Command |? CodeAction) -> Command
- dontExpectCodeAction :: [Command |? CodeAction] -> [Text] -> IO ()
- expectDiagnostic :: [Diagnostic] -> [Text] -> IO ()
- expectNoMoreDiagnostics :: Seconds -> TextDocumentIdentifier -> String -> Session ()
- failIfSessionTimeout :: IO a -> IO a
- getCompletionByLabel :: MonadIO m => Text -> [CompletionItem] -> m CompletionItem
- noLiteralCaps :: ClientCapabilities
- inspectCodeAction :: [Command |? CodeAction] -> [Text] -> IO CodeAction
- inspectCommand :: [Command |? CodeAction] -> [Text] -> IO Command
- inspectDiagnostic :: [Diagnostic] -> [Text] -> IO Diagnostic
- waitForDiagnosticsFrom :: TextDocumentIdentifier -> Session [Diagnostic]
- waitForDiagnosticsFromSource :: TextDocumentIdentifier -> String -> Session [Diagnostic]
- waitForDiagnosticsFromSourceWithTimeout :: Seconds -> TextDocumentIdentifier -> String -> Session [Diagnostic]
- withCurrentDirectoryInTmp :: FilePath -> IO a -> IO a
- withCurrentDirectoryInTmp' :: [FilePath] -> FilePath -> IO a -> IO a
- withCanonicalTempDir :: (FilePath -> IO a) -> IO a
- extractCursorPositions :: Text -> (Text, [PosPrefixInfo])
- mkParameterisedLabel :: PosPrefixInfo -> String
- trimming :: QuasiQuoter

# Test Capabilities

codeActionResolveCaps :: ClientCapabilities #

codeActionNoResolveCaps :: ClientCapabilities #

codeActionSupportCaps :: ClientCapabilities #

expectCodeAction :: [Command |? CodeAction] -> [Text] -> IO () #

# Environment specifications

ghcVersion :: GhcVersion #

data GhcVersion #

Constructors

GHC92 |
GHC94 |
GHC96 |
GHC98 |
GHC910 |

#### Instances

Instances details

Enum GhcVersion |
Instance details Defined in Development.IDE.GHC.Compat Methods succ :: GhcVersion -> GhcVersion # pred :: GhcVersion -> GhcVersion # toEnum :: Int -> GhcVersion # fromEnum :: GhcVersion -> Int # enumFrom :: GhcVersion -> [GhcVersion] # enumFromThen :: GhcVersion -> GhcVersion -> [GhcVersion] # enumFromTo :: GhcVersion -> GhcVersion -> [GhcVersion] # enumFromThenTo :: GhcVersion -> GhcVersion -> GhcVersion -> [GhcVersion] #
Show GhcVersion |
Instance details Defined in Development.IDE.GHC.Compat Methods showsPrec :: Int -> GhcVersion -> ShowS # show :: GhcVersion -> String # showList :: [GhcVersion] -> ShowS #
Eq GhcVersion |
Instance details Defined in Development.IDE.GHC.Compat Methods (==) :: GhcVersion -> GhcVersion -> Bool # (/=) :: GhcVersion -> GhcVersion -> Bool #
Ord GhcVersion |
Instance details Defined in Development.IDE.GHC.Compat Methods compare :: GhcVersion -> GhcVersion -> Ordering # (<) :: GhcVersion -> GhcVersion -> Bool # (<=) :: GhcVersion -> GhcVersion -> Bool # (>) :: GhcVersion -> GhcVersion -> Bool # (>=) :: GhcVersion -> GhcVersion -> Bool # max :: GhcVersion -> GhcVersion -> GhcVersion # min :: GhcVersion -> GhcVersion -> GhcVersion #

hostOS :: OS #

data OS #

Constructors

Windows |
MacOS |
Linux |

#### Instances

Instances details

Show OS # |
Instance details Defined in Test.Hls.Util Methods showsPrec :: Int -> OS -> ShowS # show :: OS -> String # showList :: [OS] -> ShowS #
Eq OS # |
Instance details Defined in Test.Hls.Util Methods (==) :: OS -> OS -> Bool # (/=) :: OS -> OS -> Bool #

matchesCurrentEnv :: EnvSpec -> Bool #

data EnvSpec #

Constructors

HostOS OS |
GhcVer GhcVersion |

#### Instances

Instances details

Show EnvSpec # |
Instance details Defined in Test.Hls.Util Methods showsPrec :: Int -> EnvSpec -> ShowS # show :: EnvSpec -> String # showList :: [EnvSpec] -> ShowS #
Eq EnvSpec # |
Instance details Defined in Test.Hls.Util Methods (==) :: EnvSpec -> EnvSpec -> Bool # (/=) :: EnvSpec -> EnvSpec -> Bool #

ignoreForGhcVersions :: [GhcVersion] -> String -> TestTree -> TestTree #

ignoreInEnv :: [EnvSpec] -> String -> TestTree -> TestTree #

IgnoreTest if any of environmental spec mathces the current environment.

onlyRunForGhcVersions :: [GhcVersion] -> String -> TestTree -> TestTree #

Ignore the test if GHC does not match only work versions.

knownBrokenOnWindows :: String -> TestTree -> TestTree #

knownBrokenForGhcVersions :: [GhcVersion] -> String -> TestTree -> TestTree #

knownBrokenInEnv :: [EnvSpec] -> String -> TestTree -> TestTree #

Mark as broken if any of the environmental specs matches the current environment.

knownBrokenInSpecificEnv :: [EnvSpec] -> String -> TestTree -> TestTree #

Mark as broken if all environmental specs match the current environment.

onlyWorkForGhcVersions :: (GhcVersion -> Bool) -> String -> TestTree -> TestTree #

Mark as broken if GHC does not match only work versions.

# Extract code actions

fromAction :: (Command |? CodeAction) -> CodeAction #

fromCommand :: (Command |? CodeAction) -> Command #

# Session Assertion Helpers

dontExpectCodeAction :: [Command |? CodeAction] -> [Text] -> IO () #

expectDiagnostic :: [Diagnostic] -> [Text] -> IO () #

expectNoMoreDiagnostics :: Seconds -> TextDocumentIdentifier -> String -> Session () #

wait for `timeout` seconds and report an assertion failure if any diagnostic messages arrive in that period

failIfSessionTimeout :: IO a -> IO a #

getCompletionByLabel :: MonadIO m => Text -> [CompletionItem] -> m CompletionItem #

noLiteralCaps :: ClientCapabilities #

inspectCodeAction :: [Command |? CodeAction] -> [Text] -> IO CodeAction #

inspectCommand :: [Command |? CodeAction] -> [Text] -> IO Command #

inspectDiagnostic :: [Diagnostic] -> [Text] -> IO Diagnostic #

waitForDiagnosticsFrom :: TextDocumentIdentifier -> Session [Diagnostic] #

waitForDiagnosticsFromSource :: TextDocumentIdentifier -> String -> Session [Diagnostic] #

waitForDiagnosticsFromSourceWithTimeout :: Seconds -> TextDocumentIdentifier -> String -> Session [Diagnostic] #

wait for `timeout` seconds and return diagnostics for the given `document and` source. If timeout is 0 it will wait until the session timeout

# Temporary directories

withCurrentDirectoryInTmp :: FilePath -> IO a -> IO a #

Like `withCurrentDirectory`, but will copy the directory over to the system temporary directory first to avoid haskell-language-server's source tree from interfering with the cradle.

Ignores directories containing build artefacts to avoid interference and provide reproducible test-behaviour.

withCurrentDirectoryInTmp' :: [FilePath] -> FilePath -> IO a -> IO a #

Like `withCurrentDirectory`, but will copy the directory over to the system temporary directory first to avoid haskell-language-server's source tree from interfering with the cradle.

You may specify directories to ignore, but should be careful to maintain reproducibility.

withCanonicalTempDir :: (FilePath -> IO a) -> IO a #

# Extract positions from input file.

extractCursorPositions :: Text -> (Text, [PosPrefixInfo]) #

Given a in-memory representation of a file, where a user can specify the current cursor position using a `^` in the next line.

This function allows to generate multiple tests for a single input file, without the hassle of calculating by hand where there cursor is supposed to be.

Example (line number has been added for readability):

      0: foo = 2
      1:  ^
      2: bar =
      3:      ^

This example input file contains two cursor positions (y, x), at

- (1, 1), and
- (3, 5).

`extractCursorPositions` will search for `^` characters, and determine there are two cursor positions in the text. First, it will normalise the text to:

      0: foo = 2
      1: bar =

stripping away the `^` characters. Then, the actual cursor positions are:

- (0, 1) and
- (2, 5).

mkParameterisedLabel :: PosPrefixInfo -> String #

Pretty labelling for tests that use the parameterised test helpers.

trimming :: QuasiQuoter #

Trimmed quasiquoter variation. Same as `untrimming`, but also removes the leading and trailing whitespace.