Skip to content

Add UnitIO monad and thread-safe golden testing via MonadBaseControl #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 6, 2025

Conversation

newhoggy
Copy link
Collaborator

@newhoggy newhoggy commented Jun 4, 2025

This PR introduces two key features aimed at improving the expressiveness and safety of unit testing in the hedgehog-extras library:

New UnitIO Monad

A new UnitIO monad has been added under Hedgehog.Extras.Test.Unit. This is a wrapper around TestT (ResourceT IO) with support for:

MonadTest, MonadBaseControl IO, MonadIO, MonadResource, MonadCatch, and more.

Integration with Tasty via the Tasty type class.

Convenient usage in unit tests that require resource management and assertions.

A corresponding UnitSpec demonstrates example usage with bracket_ semantics.

Thread-Safe Golden File Support

Golden file operations (diffVsGoldenFile, diffFileVsGoldenFile) are now thread-safe:

A semaphore per canonicalised path is used to protect golden tests from concurrently writing to the same golden files. This allows multiple tests to share the same golden file.

New golden test function

New diffVsGoldenFileExcludeTrace function which excludes stack traces when comparing golden output, improving the stability of golden tests for error messages with non-deterministic trace content.

Miscellaneous

Re-exported the Golden module from Hedgehog.Extras.Test for easier access

This change lays the foundation for more robust and expressive unit testing, while resolving race conditions in golden file testing.

@newhoggy newhoggy force-pushed the newhoggy/new-UnitIO-monad branch from d5c1fad to baa108c Compare June 4, 2025 10:50
@newhoggy newhoggy force-pushed the newhoggy/new-UnitIO-monad branch from baa108c to 570fdb9 Compare June 4, 2025 12:26
@newhoggy newhoggy changed the title Add TestIO monad and thread-safe golden testing Add UnitIO monad and thread-safe golden testing Jun 4, 2025
@newhoggy newhoggy changed the title Add UnitIO monad and thread-safe golden testing Add UnitIO monad and thread-safe golden testing via MonadBaseControl Jun 4, 2025
Copy link
Contributor

@carbolymer carbolymer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress! I'm worried about copying code, which will be annoying to maintain in the future.

@newhoggy newhoggy force-pushed the newhoggy/new-UnitIO-monad branch from 728c07b to d15b4af Compare June 5, 2025 11:05
@newhoggy newhoggy requested a review from carbolymer June 5, 2025 11:10
@newhoggy newhoggy dismissed carbolymer’s stale review June 5, 2025 11:10

Comments addressed

@newhoggy newhoggy merged commit 332c768 into main Jun 6, 2025
10 checks passed
@newhoggy newhoggy deleted the newhoggy/new-UnitIO-monad branch June 6, 2025 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants