| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Drasil.FileHandling
Synopsis
- localPath :: OsPath
- data FileLayout
- name :: FileLayout -> PathSegment
- file :: Writeable doc => PathSegment -> doc -> FileLayout
- exactFile :: Writeable doc => PathSegment -> doc -> FileLayout
- directory :: Foldable f => PathSegment -> f FileLayout -> FileLayout
- data OverwritePolicy
- writeFiles :: OverwritePolicy -> OsPath -> FileLayout -> IO ()
- data PathSegment
- ps :: QuasiQuoter
- (</>) :: OsPath -> PathSegment -> OsPath
- toPath :: PathSegment -> OsPath
- goldenTestingGroup :: OsPath -> OsPath -> TestName -> [GoldenTestCase] -> TestTree
- data GoldenTestCase
- goldenTest :: TestName -> FileLayout -> GoldenTestCase
Documentation
File Layout
data FileLayout Source #
Container for laying out files in a single container for writing to disk. Notes:
- Polymorphic over the representation of the file contents. For
rendering, writeFiles requires the file content representation
satisfy
Writeable. - Only permits writing files/directories relative to a base path
provided. Does not permit `..`,
., nor~as directory names. - System-local path separator is forbidden from use in directory names.
- Assumes host file system is case-sensitive (i.e., recognizes
txtand `a.txt` as different paths).
name :: FileLayout -> PathSegment Source #
Get the top-level name (a PathSegment) of a FileLayout.
Constructors
file :: Writeable doc => PathSegment -> doc -> FileLayout Source #
Create a file FileLayout. When written, this file will have a /trailing
newline always added/. Use exactFile for building raw files. This is
primarily for synthetic files/generated ones.
exactFile :: Writeable doc => PathSegment -> doc -> FileLayout Source #
Create a file FileLayout containing the exact file contents.
directory :: Foldable f => PathSegment -> f FileLayout -> FileLayout Source #
Create a directory FileLayout, optionally containing any number of nested
files.
Writing
data OverwritePolicy Source #
When writing files or creating directories, is overwriting allowed?
Constructors
| OverwriteAllowed | |
| NeverOverwrite |
writeFiles :: OverwritePolicy -> OsPath -> FileLayout -> IO () Source #
Write a FileLayout to disk about a base path.
If the given OverwritePolicy is NeverOverwrite, this will fail if the
top-level target path already exists. If it is OverwriteAllowed, it will
overwrite existing files.
Disclaimer: For case-insensitive file systems where different paths in the layout might reference the same on-disk path, this code will fail.
File Path Segments
data PathSegment Source #
Represents a single valid segment of a path (e.g., a file or directory
name, usually the terminal basename of a path). Does not allow path
segments to be any of: `..`, ., nor ~. Assumes case-sensitive equality.
Instances
| Eq PathSegment Source # | |
Defined in Drasil.FileHandling.FilePath | |
| Ord PathSegment Source # | |
Defined in Drasil.FileHandling.FilePath Methods compare :: PathSegment -> PathSegment -> Ordering # (<) :: PathSegment -> PathSegment -> Bool # (<=) :: PathSegment -> PathSegment -> Bool # (>) :: PathSegment -> PathSegment -> Bool # (>=) :: PathSegment -> PathSegment -> Bool # max :: PathSegment -> PathSegment -> PathSegment # min :: PathSegment -> PathSegment -> PathSegment # | |
Construction
ps :: QuasiQuoter Source #
QuasiQuoter for building PathSegments.
Syntax:
ps ::= comp+
comp ::= '{' hsVar '}'
| <any string excl. ., '..', ~, not
including the system-local path sep.>
hsVar ::= string
(</>) :: OsPath -> PathSegment -> OsPath Source #
Append a terminal PathSegment onto a OsPath to form a new OsPath.
Unpacking
toPath :: PathSegment -> OsPath Source #
Retrieve OsPath representation of a PathSegment.
Arguments
| :: OsPath | The relative directory where newly generated files should be written. |
| -> OsPath | The relative directory where the expected/golden files are stored. |
| -> TestName | The name of the test group (e.g., |
| -> [GoldenTestCase] | A list of golden test cases to run. |
| -> TestTree |
Create a golden testing group relative to a main build folder and golden artifacts folder.
data GoldenTestCase Source #
A golden test case.
goldenTest :: TestName -> FileLayout -> GoldenTestCase Source #
Create a golden test case for a given FileLayout. Within the context of a
goldenTestingGroup, will be dumped to the build folder and compared with
the golden artifacts folder.