https://github.com/tek/polysemy-test
Utilities for testing Polysemy programs
https://github.com/tek/polysemy-test
Last synced: about 1 year ago
JSON representation
Utilities for testing Polysemy programs
- Host: GitHub
- URL: https://github.com/tek/polysemy-test
- Owner: tek
- Created: 2020-08-29T20:50:47.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-05-22T01:35:48.000Z (about 2 years ago)
- Last Synced: 2024-05-22T21:54:45.690Z (about 2 years ago)
- Language: Nix
- Size: 171 KB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# About
This package provides utilities for testing [Polysemy] programs:
* An effect, `Test`, that gives access to temporary files and fixtures
* An effect, `Hedgehog`, for lifted [Hedgehog] assertions
# Example
```haskell
import Path (relfile)
import Polysemy.Test
import Test.Tasty (defaultMain)
test_fixture :: UnitTest
test_fixture =
runTestAuto do
fixContent1 <- fixtureLines fixRel
fixPath <- Test.fixturePath fixRel
fixContent2 <- Text.lines <$> embed (Text.readFile (toFilePath fixPath))
fixContent1 === fixContent2
fixContent1 === ["file", "content"]
where
fixRel =
[relfile|files/file1|]
main :: IO ()
main =
defaultMain (unitTest test_fixture)
```
# Fixtures
Any file that is located below the subdirectory `fixtures` inside the test
directory can be accessed using the constructors `Test.fixturePath`,
`Test.fixture` and `Text.fixtureLines`.
You can override the path used to look for the `fixtures` directory by using
`runTest` instead of `runTestAuto`.
The latter analyzes the call stack to determine the test directory.
# Temp Files
The constructors `Test.tempDir`, `Test.tempFile`, `Test.tempFileContent` and
`Test.tempFileLines` allow you to create and read files in the `temp` directory
within the test directory.
# Paths
All paths are of type `Path` from the package [path].
You can construct them using the quasiquoters `reldir`, `absdir` etc. or the
functions `parseRelDir`, `parseAbsDir` etc.
[Polysemy]: https://hackage.haskell.org/package/polysemy
[Hedgehog]: https://hackage.haskell.org/package/hedgehog
[path]: https://hackage.haskell.org/package/path