Skip to content
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

add tasty integration notes #321

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions docs/tasty-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Using ghciwatch with tasty

Tips and tricks for using ghciwatch with the [Tasty][tasty] test framework.

[tasty]: https://hackage.haskell.org/package/tasty

Ghciwatch will wait for GHCi to print output, and it can end up waiting forever
if the Tasty output is buffered. Something like this works:

```haskell
module TestMain where

import Control.Exception (bracket)
import System.IO (hGetBuffering, hSetBuffering, stdout)
import Test.Tasty (TestTree, defaultMain, testGroup)

-- | Run an `IO` action, restoring `stdout`\'s buffering mode after the action
-- completes or errors.
protectStdoutBuffering :: IO a -> IO a
protectStdoutBuffering action =
bracket
(hGetBuffering stdout)
(\bufferMode -> hSetBuffering stdout bufferMode)
(const action)

main :: IO ()
main = protectStdoutBuffering $ defaultMain $ mytestgroup
```

## `tasty-discover` issues

If you add a new test file, you may need to write the top level
[`tasty-discover`][tasty-discover] module to convince ghciwatch to reload it.
[`tasty-autocollect`][tasty-autocollect] relies on a compiler plugin and seems
to avoid this problem.

[tasty-discover]: https://hackage.haskell.org/package/tasty
[tasty-autocollect]: https://github.com/MercuryTechnologies/ghciwatch/pull/321/files?short_path=c86caa3#diff-c86caa33ad4639b624ef8db59e739295f362bf4c211bed24c8ba484c79af9bdb