polysemy-test: Polysemy effects for testing

[ library, test ] [ Propose Tags ]
Versions [RSS],,,,,,,,,,,,,,,,,,,,,,, (info)
Change log changelog.md
Dependencies base (>= && <4.20), hedgehog (>=1.2 && <1.5), incipit-core (>= && <0.7), path (>=0.9.1 && <0.10), path-io (>=1.8.0 && <1.9), polysemy (>= && <1.10), tasty (>=1.4.3 && <1.5), tasty-hedgehog (>= && <1.5), transformers (>= && <0.7) [details]
License BSD-2-Clause-Patent
Copyright 2023 Torsten Schmits
Author Torsten Schmits
Maintainer hackage@tryp.io
Category Test
Home page https://github.com/tek/polysemy-test#readme
Bug tracker https://github.com/tek/polysemy-test/issues
Source repo head: git clone https://github.com/tek/polysemy-test
Uploaded by tek at 2024-05-25T16:00:59Z
Reverse Dependencies 5 direct, 15 indirect [details]
Downloads 3116 total (129 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for polysemy-test-

[back to package description]


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


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"]
    fixRel =

main :: IO ()
main =
  defaultMain (unitTest test_fixture)


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.


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.