diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 655b3f06..442d1b6a 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -1,4 +1,4 @@ -# Summary +# User Manual - [Introduction](./introduction.md) - [Installation](./install.md) @@ -8,3 +8,7 @@ - [Comment evaluation](./comment-evaluation.md) - [Only load modules you need](./no-load.md) - [FAQ](./faq.md) + +# Integration and tips + +- [Tasty](./integration/tasty.md) diff --git a/docs/integration/tasty.md b/docs/integration/tasty.md new file mode 100644 index 00000000..a6792f68 --- /dev/null +++ b/docs/integration/tasty.md @@ -0,0 +1,38 @@ +# 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