Copyright | © 2018-2020 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
Test.Hspec.Extra
Description
Helper functions for testing.
Synopsis
- aroundAll :: forall a. HasCallStack => (ActionWith a -> IO ()) -> SpecWith a -> Spec
- it :: HasCallStack => String -> ActionWith ctx -> SpecWith ctx
- itWithCustomTimeout :: HasCallStack => Int -> String -> ActionWith ctx -> SpecWith ctx
- flakyBecauseOf :: String -> Expectation
Documentation
aroundAll :: forall a. HasCallStack => (ActionWith a -> IO ()) -> SpecWith a -> Spec Source #
Run a bracket
resource acquisition function around all the specs. The
bracket opens before the first test case and closes after the last test case.
It works by actually spawning a new thread responsible for the resource acquisition, passing the resource along to the parent threads via a shared MVar. Then, there's a bit of logic to synchronize both threads and make sure that:
a) The 'Resource Owner' thread is terminated when the main thread is done with the resource.
b) The 'Main Thread' only exists when the resource owner has released the resource. Exiting the main thread before the 'Resource Owner' has released the resource could left a hanging resource open. This is particularly annoying when the resource is a running process!
Main Thread Resource Owner x | Spawn |----------------------->x | | | |-- Acquire resource | Send Resource | |<-----------------------| | | | | ... ... Await main thread signal | | | | | Send Signal | |----------------------->| | | | ... Release resource | Send Done | |<-----------------------| | Exit | Exit
it :: HasCallStack => String -> ActionWith ctx -> SpecWith ctx Source #
A drop-in replacement for it
that'll automatically retry a scenario once
if it fails, to cope with potentially flaky tests.
It also has a timeout of 10 minutes.
Arguments
:: HasCallStack | |
=> Int | Timeout in seconds. |
-> String | |
-> ActionWith ctx | |
-> SpecWith ctx |
Like it
but with a custom timeout, which makes it realistic to test.
flakyBecauseOf :: String -> Expectation Source #
Mark a test pending because of flakiness, with given reason. Unless the RUN_FLAKY_TESTS environment variable is set.