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

Safe Haskell | None
Language | GHC2021

Test.Hls.FileSystem

Contents

- init
- Interaction
- Test helpers
- Builders
- Cradle helpers
- Full project setups

Synopsis

- data FileSystem = FileSystem {
  - fsRoot :: FilePath
  - fsTree :: [FileTree]
  - fsOriginalRoot :: FilePath
  }
- data VirtualFileTree = VirtualFileTree {
  - vftTree :: [FileTree]
  - vftOriginalRoot :: FilePath
  }
- data FileTree
- data Content
- materialise :: FilePath -> [FileTree] -> FilePath -> IO FileSystem
- materialiseVFT :: FilePath -> VirtualFileTree -> IO FileSystem
- readFileFS :: FileSystem -> FilePath -> IO Text
- writeFileFS :: FileSystem -> FilePath -> Content -> IO ()
- mkVirtualFileTree :: FilePath -> [FileTree] -> VirtualFileTree
- toNfp :: FileSystem -> FilePath -> NormalizedFilePath
- toAbsFp :: FileSystem -> FilePath -> FilePath
- file :: FilePath -> Content -> FileTree
- copy :: FilePath -> FileTree
- directory :: FilePath -> [FileTree] -> FileTree
- text :: Text -> Content
- ref :: FilePath -> Content
- copyDir :: FilePath -> FileTree
- directCradle :: [Text] -> FileTree
- simpleCabalCradle :: FileTree
- directProject :: FilePath -> [FileTree]
- directProjectMulti :: [FilePath] -> [FileTree]
- simpleCabalProject :: [FilePath] -> [FileTree]
- simpleCabalProject' :: [FileTree] -> [FileTree]

# Documentation

data FileSystem #

Representation of a `VirtualFileTree` that has been `materialise`d to disk.

Constructors

FileSystem |
Fields fsRoot :: FilePath fsTree :: [FileTree] fsOriginalRoot :: FilePath

#### Instances

Instances details

Show FileSystem # |
Instance details Defined in Test.Hls.FileSystem Methods showsPrec :: Int -> FileSystem -> ShowS # show :: FileSystem -> String # showList :: [FileSystem] -> ShowS #
Eq FileSystem # |
Instance details Defined in Test.Hls.FileSystem Methods (==) :: FileSystem -> FileSystem -> Bool # (/=) :: FileSystem -> FileSystem -> Bool #
Ord FileSystem # |
Instance details Defined in Test.Hls.FileSystem Methods compare :: FileSystem -> FileSystem -> Ordering # (<) :: FileSystem -> FileSystem -> Bool # (<=) :: FileSystem -> FileSystem -> Bool # (>) :: FileSystem -> FileSystem -> Bool # (>=) :: FileSystem -> FileSystem -> Bool # max :: FileSystem -> FileSystem -> FileSystem # min :: FileSystem -> FileSystem -> FileSystem #

data VirtualFileTree #

Virtual representation of a filesystem tree.

Operations of `vftTree` are relative to `vftOriginalRoot`. In particular, any `copy` etc. operation looks for the sources in `vftOriginalRoot`.

To persist a `VirtualFileTree`, look at `materialise` and `materialiseVFT`.

Constructors

VirtualFileTree |
Fields vftTree :: [FileTree] vftOriginalRoot :: FilePath

#### Instances

Instances details

Show VirtualFileTree # |
Instance details Defined in Test.Hls.FileSystem Methods showsPrec :: Int -> VirtualFileTree -> ShowS # show :: VirtualFileTree -> String # showList :: [VirtualFileTree] -> ShowS #
Eq VirtualFileTree # |
Instance details Defined in Test.Hls.FileSystem Methods (==) :: VirtualFileTree -> VirtualFileTree -> Bool # (/=) :: VirtualFileTree -> VirtualFileTree -> Bool #
Ord VirtualFileTree # |
Instance details Defined in Test.Hls.FileSystem Methods compare :: VirtualFileTree -> VirtualFileTree -> Ordering # (<) :: VirtualFileTree -> VirtualFileTree -> Bool # (<=) :: VirtualFileTree -> VirtualFileTree -> Bool # (>) :: VirtualFileTree -> VirtualFileTree -> Bool # (>=) :: VirtualFileTree -> VirtualFileTree -> Bool # max :: VirtualFileTree -> VirtualFileTree -> VirtualFileTree # min :: VirtualFileTree -> VirtualFileTree -> VirtualFileTree #

data FileTree #

#### Instances

Instances details

Show FileTree # |
Instance details Defined in Test.Hls.FileSystem Methods showsPrec :: Int -> FileTree -> ShowS # show :: FileTree -> String # showList :: [FileTree] -> ShowS #
Eq FileTree # |
Instance details Defined in Test.Hls.FileSystem Methods (==) :: FileTree -> FileTree -> Bool # (/=) :: FileTree -> FileTree -> Bool #
Ord FileTree # |
Instance details Defined in Test.Hls.FileSystem Methods compare :: FileTree -> FileTree -> Ordering # (<) :: FileTree -> FileTree -> Bool # (<=) :: FileTree -> FileTree -> Bool # (>) :: FileTree -> FileTree -> Bool # (>=) :: FileTree -> FileTree -> Bool # max :: FileTree -> FileTree -> FileTree # min :: FileTree -> FileTree -> FileTree #

data Content #

#### Instances

Instances details

Show Content # |
Instance details Defined in Test.Hls.FileSystem Methods showsPrec :: Int -> Content -> ShowS # show :: Content -> String # showList :: [Content] -> ShowS #
Eq Content # |
Instance details Defined in Test.Hls.FileSystem Methods (==) :: Content -> Content -> Bool # (/=) :: Content -> Content -> Bool #
Ord Content # |
Instance details Defined in Test.Hls.FileSystem Methods compare :: Content -> Content -> Ordering # (<) :: Content -> Content -> Bool # (<=) :: Content -> Content -> Bool # (>) :: Content -> Content -> Bool # (>=) :: Content -> Content -> Bool # max :: Content -> Content -> Content # min :: Content -> Content -> Content #

# init

materialise :: FilePath -> [FileTree] -> FilePath -> IO FileSystem #

Materialise a virtual file tree in the `rootDir` directory.

Synopsis: ``materialise` rootDir fileTree testDataDir`

File references in '[FileTree]' are resolved relative to the `testDataDir`.

materialiseVFT :: FilePath -> VirtualFileTree -> IO FileSystem #

Materialise a virtual file tree in the `rootDir` directory.

Synopsis: ``materialiseVFT` rootDir virtualFileTree`

File references in `virtualFileTree` are resolved relative to the `vftOriginalRoot`.

# Interaction

readFileFS :: FileSystem -> FilePath -> IO Text #

writeFileFS :: FileSystem -> FilePath -> Content -> IO () #

# Test helpers

mkVirtualFileTree :: FilePath -> [FileTree] -> VirtualFileTree #

toNfp :: FileSystem -> FilePath -> NormalizedFilePath #

toAbsFp :: FileSystem -> FilePath -> FilePath #

# Builders

file :: FilePath -> Content -> FileTree #

Create a file in the test project with some content.

Only the filename will be used, and any directory components are *not* reflected in the test project.

copy :: FilePath -> FileTree #

Copy a filepath into a test project. The name of the file is also used in the test project.

The filepath is always resolved to the root of the test data dir.

directory :: FilePath -> [FileTree] -> FileTree #

text :: Text -> Content #

Write the given test directly into a file.

ref :: FilePath -> Content #

Read the contents of the given file The filepath is always resolved to the root of the test data dir.

copyDir :: FilePath -> FileTree #

Copy a directory into a test project. The filepath is always resolved to the root of the test data dir.

# Cradle helpers

directCradle :: [Text] -> FileTree #

Set up a simple direct cradle.

All arguments are added to the direct cradle file. Arguments will not be escaped.

simpleCabalCradle :: FileTree #

Set up a simple cabal cradle.

Prefer simple cabal cradle, over custom multi cabal cradles if possible.

# Full project setups

directProject :: FilePath -> [FileTree] #

Set up a test project with a single haskell file.

directProjectMulti :: [FilePath] -> [FileTree] #

Set up a test project with multiple haskell files.

simpleCabalProject :: [FilePath] -> [FileTree] #

Set up a simple cabal cradle project and copy all the given filepaths into the test directory.

simpleCabalProject' :: [FileTree] -> [FileTree] #

Set up a simple cabal cradle project.