hls-test-utils-2.13.0.0: Utilities used in the tests of Haskell Language Server
Safe HaskellNone
LanguageGHC2021

Test.Hls.Util

Synopsis

Test Capabilities

Environment specifications

data OS Source #

Constructors

Windows 
MacOS 
Linux 

Instances

Instances details
Show OS Source # 
Instance details

Defined in Test.Hls.Util

Methods

showsPrec :: Int -> OS -> ShowS #

show :: OS -> String #

showList :: [OS] -> ShowS #

Eq OS Source # 
Instance details

Defined in Test.Hls.Util

Methods

(==) :: OS -> OS -> Bool #

(/=) :: OS -> OS -> Bool #

data EnvSpec Source #

Constructors

HostOS OS 
GhcVer GhcVersion 

Instances

Instances details
Show EnvSpec Source # 
Instance details

Defined in Test.Hls.Util

Eq EnvSpec Source # 
Instance details

Defined in Test.Hls.Util

Methods

(==) :: EnvSpec -> EnvSpec -> Bool #

(/=) :: EnvSpec -> EnvSpec -> Bool #

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

IgnoreTest if any of environmental spec mathces the current environment.

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

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

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

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

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

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

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

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

Extract code actions

Session Assertion Helpers

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

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

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

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 Source #

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 Source #

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.

Extract positions from input file.

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

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 Source #

Pretty labelling for tests that use the parameterised test helpers.

__i :: QuasiQuoter #

An interpolator that handles indentation. Will interpolate anything you wrap in #{}, remove leading indentation, and remove any blank lines before and after the content.

If the contained interpolation uses both tabs and spaces for indentation, __i will assume the indentation type it finds in the first nonblank line, ignoring indentation of the other type. Please don't use mixed indentation.

Note that only indentation you actually write in source code will be stripped; __i does not touch any lines or whitespace inserted by interpolations themselves.

There is no extra performance penalty for using __i.